#include "SDLAudioDevice.h" #include "Util/logger.h" using namespace std; using namespace toolkit; SDLAudioDevice& SDLAudioDevice::Instance() { static SDLAudioDevice *instance(new SDLAudioDevice); return *instance; } SDLAudioDevice::SDLAudioDevice() { SDL_AudioSpec wanted_spec; wanted_spec.freq = DEFAULT_SAMPLERATE; wanted_spec.format = DEFAULT_SAMPLEBIT == 16 ? AUDIO_S16 : AUDIO_S8; wanted_spec.channels = DEFAULT_CHANNEL; wanted_spec.silence = 0; wanted_spec.samples = DEFAULT_PCMSIZE / (DEFAULT_CHANNEL * DEFAULT_SAMPLEBIT / 8) ; wanted_spec.size = DEFAULT_PCMSIZE; wanted_spec.callback = SDLAudioDevice::onReqPCM; wanted_spec.userdata = this; if (SDL_OpenAudio(&wanted_spec, &_audioConfig)<0) { // throw std::runtime_error("SDL_OpenAudio failed"); InfoL << "SDL_OpenAudio failed"; }else{ InfoL << "actual audioSpec: " << "freq=" << _audioConfig.freq << ",format=" << hex<<_audioConfig.format<getPCMData(_pcmBuf.get(),len); if(size){ //InfoL << len << " " << size; SDL_MixAudio((Uint8*)stream,(Uint8*)_pcmBuf.get(),size,SDL_MIX_MAXVOLUME); } } if(size){ channel++; } } if(!channel){ memset(stream,0,len); } }