Source

gb_emulator / gb_emulator / include / gb_emulator / gb_sound_wasapi.h

/*  Copyright © 2011 Chris Spencer <spencercw@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#ifndef GB_SOUND_WASAPI_H_C83C9EC0_1828_11E1_989A_0002A5D5C51B
#define GB_SOUND_WASAPI_H_C83C9EC0_1828_11E1_989A_0002A5D5C51B

#include <atlbase.h>
#include <atlcom.h>

#include <gb_emulator/gb_sound.hpp>

class GbSoundWasapiRenderer;

//! WASAPI sound driver.
class GbSoundWasapi: public GbSound
{
public:
	//! Constructor.
	GbSoundWasapi(Gb &gb);

	//! Destructor.
	~GbSoundWasapi();

	//! Indicates whether WASAPI is available.
	/**
	 * This function does a runtime check to see whether WASAPI can be used on this system. If not
	 * then none of the other functions in this class may be used.
	 * \return Whether WASAPI is available.
	 */
	bool isAvailable();

	//! Opens the sound device and prepares for playback.
	void initialise();

	//! Generates a single sample.
	double poll();

	//! Checks for and handles any events then returns.
	void pollEvents();

	//! Sets the callback function to be called at the given frequency based on the audio clock.
	void setTimerCallback(double frequency, boost::function<void ()> callback);

private:
	// The audio renderer
	ATL::CComPtr<GbSoundWasapiRenderer> renderer_;

	// Saves the sample rate that the renderer is using
	void saveSampleRate(unsigned sampleRate);

	// Disabled operations
	GbSoundWasapi(const GbSoundWasapi &);
	GbSoundWasapi & operator=(const GbSoundWasapi &);
};

#endif