SYMBIAN: Fixes & improvements for SymbianSdlMixerManager (untested)

svn-id: r54519
This commit is contained in:
Max Horn 2010-11-28 14:57:04 +00:00
parent 7760077cf5
commit f1cdb318c6
4 changed files with 17 additions and 43 deletions

View File

@ -58,7 +58,7 @@ void SdlMixerManager::init() {
}
// Get the desired audio specs
SDL_AudioSpec desired = getAudioSpec();
SDL_AudioSpec desired = getAudioSpec(SAMPLES_PER_SEC);
// Start SDL audio with the desired specs
if (SDL_OpenAudio(&desired, &_obtainedRate) != 0) {
@ -78,7 +78,7 @@ void SdlMixerManager::init() {
}
}
SDL_AudioSpec SdlMixerManager::getAudioSpec() {
SDL_AudioSpec SdlMixerManager::getAudioSpec(uint32 outputRate) {
SDL_AudioSpec desired;
// Determine the desired output sampling frequency.
@ -86,7 +86,7 @@ SDL_AudioSpec SdlMixerManager::getAudioSpec() {
if (ConfMan.hasKey("output_rate"))
samplesPerSec = ConfMan.getInt("output_rate");
if (samplesPerSec <= 0)
samplesPerSec = SAMPLES_PER_SEC;
samplesPerSec = outputRate;
// Determine the sample buffer size. We want it to store enough data for
// at least 1/16th of a second (though at most 8192 samples). Note

View File

@ -83,7 +83,7 @@ protected:
/**
* Returns the desired audio specification
*/
virtual SDL_AudioSpec getAudioSpec();
virtual SDL_AudioSpec getAudioSpec(uint32 rate);
/**
* Starts SDL audio

View File

@ -36,56 +36,32 @@
SymbianSdlMixerManager::SymbianSdlMixerManager()
:
_stereo_mix_buffer(0) {
_stereoMixBuffer(0) {
}
SymbianSdlMixerManager::~SymbianSdlMixerManager() {
delete[] _stereo_mix_buffer;
delete[] _stereoMixBuffer;
}
void SymbianSdlMixerManager::init() {
// Start SDL Audio subsystem
if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1) {
error("Could not initialize SDL: %s", SDL_GetError());
void SymbianSdlMixerManager::startAudio() {
// Need to create mixbuffer for stereo mix to downmix
if (_obtainedRate.channels != 2) {
_stereoMixBuffer = new byte [_obtainedRate.size * 2]; // * 2 for stereo values
}
// Get the desired audio specs
SDL_AudioSpec desired = getAudioSpec();
// Start SDL audio with the desired specs
if (SDL_OpenAudio(&desired, &_obtainedRate) != 0) {
warning("Could not open audio device: %s", SDL_GetError());
_mixer = new Audio::MixerImpl(g_system, desired.freq);
assert(_mixer);
_mixer->setReady(false);
} else {
debug(1, "Output sample rate: %d Hz", _obtainedRate.freq);
_channels = _obtainedRate.channels;
// Need to create mixbuffer for stereo mix to downmix
if (_channels != 2) {
_stereo_mix_buffer = new byte [_obtainedRate.size * 2]; // * 2 for stereo values
}
_mixer = new Audio::MixerImpl(g_system, _obtainedRate.freq);
assert(_mixer);
_mixer->setReady(true);
startAudio();
}
SdlMixerManager::startAudio();
}
void SymbianSdlMixerManager::callbackHandler(byte *samples, int len) {
assert(_mixer);
#if defined (S60) && !defined(S60V3)
// If not stereo then we need to downmix
if (_mixer->_channels != 2) {
_mixer->mixCallback(_stereo_mix_buffer, len * 2);
if (_obtainedRate.channels != 2) {
_mixer->mixCallback(_stereoMixBuffer, len * 2);
int16 *bitmixDst = (int16 *)samples;
int16 *bitmixSrc = (int16 *)_stereo_mix_buffer;
int16 *bitmixSrc = (int16 *)_stereoMixBuffer;
for (int loop = len / 2; loop >= 0; loop --) {
*bitmixDst = (*bitmixSrc + *(bitmixSrc + 1)) >> 1;

View File

@ -36,12 +36,10 @@ public:
SymbianSdlMixerManager();
virtual ~SymbianSdlMixerManager();
virtual void init();
protected:
int _channels;
byte *_stereo_mix_buffer;
byte *_stereoMixBuffer;
virtual void startAudio();
virtual void callbackHandler(byte *samples, int len);
};