Added SDL audio path

This commit is contained in:
Robert Osfield 2009-03-03 20:59:16 +00:00
parent ac49ca81ca
commit 97e987a9d9

View File

@ -348,26 +348,26 @@ class SDLAudioSink : public osg::AudioSink
{ {
_playing = true; _playing = true;
osg::notify(osg::NOTICE)<<"SDLAudioSink()::startPlaying()"<<std::endl; osg::notify(osg::NOTICE)<<"SDLAudioSink()::startPlaying()"<<std::endl;
osg::notify(osg::NOTICE)<<" audioFrequency()="<<_audioStream->audioFrequency()<<std::endl; osg::notify(osg::NOTICE)<<" audioFrequency()="<<_audioStream->audioFrequency()<<std::endl;
osg::notify(osg::NOTICE)<<" audioNbChannels()="<<_audioStream->audioNbChannels()<<std::endl; osg::notify(osg::NOTICE)<<" audioNbChannels()="<<_audioStream->audioNbChannels()<<std::endl;
osg::notify(osg::NOTICE)<<" audioSampleFormat()="<<_audioStream->audioSampleFormat()<<std::endl; osg::notify(osg::NOTICE)<<" audioSampleFormat()="<<_audioStream->audioSampleFormat()<<std::endl;
SDL_AudioSpec specs = { 0 };
SDL_AudioSpec wanted_specs = { 0 };
wanted_specs.freq = _audioStream->audioFrequency(); SDL_AudioSpec specs = { 0 };
wanted_specs.format = AUDIO_S16SYS; SDL_AudioSpec wanted_specs = { 0 };
wanted_specs.channels = _audioStream->audioNbChannels();
wanted_specs.silence = 0;
wanted_specs.samples = 1024;
wanted_specs.callback = soundReadCallback;
wanted_specs.userdata = this;
if (SDL_OpenAudio(&wanted_specs, &specs) < 0) wanted_specs.freq = _audioStream->audioFrequency();
throw "SDL_OpenAudio() failed (" + std::string(SDL_GetError()) + ")"; wanted_specs.format = AUDIO_S16SYS;
wanted_specs.channels = _audioStream->audioNbChannels();
wanted_specs.silence = 0;
wanted_specs.samples = 1024;
wanted_specs.callback = soundReadCallback;
wanted_specs.userdata = this;
SDL_PauseAudio(0); if (SDL_OpenAudio(&wanted_specs, &specs) < 0)
throw "SDL_OpenAudio() failed (" + std::string(SDL_GetError()) + ")";
SDL_PauseAudio(0);
} }
virtual bool playing() const { return _playing; } virtual bool playing() const { return _playing; }
@ -381,14 +381,12 @@ class SDLAudioSink : public osg::AudioSink
void SDLAudioSink::soundReadCallback(void * const user_data, Uint8 * const data, const int datalen) void SDLAudioSink::soundReadCallback(void * const user_data, Uint8 * const data, const int datalen)
{ {
osg::notify(osg::NOTICE)<<"SDLAudioSink::soundReadCallback"<<std::endl; SDLAudioSink * sink = reinterpret_cast<SDLAudioSink*>(user_data);
osg::ref_ptr<osg::AudioStream> as = sink->_audioStream.get();
SDLAudioSink * sink = reinterpret_cast<SDLAudioSink*>(user_data); if (as.valid())
osg::ref_ptr<osg::AudioStream> as = sink->_audioStream.get(); {
if (as.valid()) as->consumeAudioBuffer(data, datalen);
{ }
as->consumeAudioBuffer(data, datalen);
}
} }
#endif #endif