void GameSoundBuffer::Play(void * data, int64 frames) { float pan[2]; pan[0] = fPanRight; pan[1] = fPanLeft; char * buffer = new char[fFrameSize * frames]; FillBuffer(buffer, frames); switch (fFormat.format) { case gs_audio_format::B_GS_U8: { for (int64 i = 0; i < frames; i++) { ApplyMod((uint8*)data, (uint8*)buffer, i, fGain, pan); UpdateMods(); } break; } case gs_audio_format::B_GS_S16: { for (int64 i = 0; i < frames; i++) { ApplyMod((int16*)data, (int16*)buffer, i, fGain, pan); UpdateMods(); } break; } case gs_audio_format::B_GS_S32: { for (int64 i = 0; i < frames; i++) { ApplyMod((int32*)data, (int32*)buffer, i, fGain, pan); UpdateMods(); } break; } case gs_audio_format::B_GS_F: { for (int64 i = 0; i < frames; i++) { ApplyMod((float*)data, (float*)buffer, i, fGain, pan); UpdateMods(); } break; } } delete[] buffer; }
void GameSoundBuffer::Play(void * data, int64 frames) { // Mh... should we add some locking? if (!fIsPlaying) return; if (fFormat.channel_count == 2) { float pan[2]; pan[0] = fPanRight * fGain; pan[1] = fPanLeft * fGain; char * buffer = new char[fFrameSize * frames]; FillBuffer(buffer, frames); switch (fFormat.format) { case gs_audio_format::B_GS_U8: { for (int64 i = 0; i < frames; i++) { ApplyMod((uint8*)data, (uint8*)buffer, i, pan); UpdateMods(); } break; } case gs_audio_format::B_GS_S16: { for (int64 i = 0; i < frames; i++) { ApplyMod((int16*)data, (int16*)buffer, i, pan); UpdateMods(); } break; } case gs_audio_format::B_GS_S32: { for (int64 i = 0; i < frames; i++) { ApplyMod((int32*)data, (int32*)buffer, i, pan); UpdateMods(); } break; } case gs_audio_format::B_GS_F: { for (int64 i = 0; i < frames; i++) { ApplyMod((float*)data, (float*)buffer, i, pan); UpdateMods(); } break; } } delete[] buffer; } else if (fFormat.channel_count == 1) { // FIXME the output should be stereo, and we could pan mono sounds // here. But currently the output has the same number of channels as // the sound and we can't do this. // FIXME also, we don't handle the gain here. FillBuffer(data, frames); } else debugger("Invalid number of channels."); }