1. spencercw
  2. gb_emulator


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
    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.h>

class GbSoundWasapiRenderer;

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

	//! Destructor.

	//! 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);

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

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

	// Generates the given number of samples on-demand to avoid underflowing the audio buffer
	void extrapolate(unsigned samples);

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