From fb6ee7844d0d31441c04674bf6501776868d8e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ximo=20Casta=C3=B1eda?= Date: Mon, 7 Dec 2020 17:15:08 +0100 Subject: [PATCH] GameSoundBuffer: avoid buffer copy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ibffe80ebe5e8205e853e09b6ebb9ba65b53d83e7 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3475 Reviewed-by: Jérôme Duval --- src/kits/game/GameSoundBuffer.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/kits/game/GameSoundBuffer.cpp b/src/kits/game/GameSoundBuffer.cpp index a3a56ea373..aff439b480 100644 --- a/src/kits/game/GameSoundBuffer.cpp +++ b/src/kits/game/GameSoundBuffer.cpp @@ -45,10 +45,10 @@ // Sound Buffer Utility functions ---------------------------------------- template static inline void -ApplyMod(T* data, T* buffer, int64 index, float * pan) +ApplyMod(T* data, int64 index, float* pan) { - data[index * 2] += T(float(buffer[index * 2] - middle) * pan[0] + middle); - data[index * 2 + 1] += T(float(buffer[index * 2 + 1] - middle) * pan[1] + data[index * 2] = T(float(data[index * 2] - middle) * pan[0] + middle); + data[index * 2 + 1] = T(float(data[index * 2 + 1] - middle) * pan[1] + middle); } @@ -256,15 +256,13 @@ GameSoundBuffer::Play(void * data, int64 frames) pan[0] = fPanRight * fGain; pan[1] = fPanLeft * fGain; - char * buffer = new char[fFrameSize * frames]; - - FillBuffer(buffer, frames); + FillBuffer(data, 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); + ApplyMod((uint8*)data, i, pan); UpdateMods(); } @@ -274,7 +272,7 @@ GameSoundBuffer::Play(void * data, int64 frames) case gs_audio_format::B_GS_S16: { for (int64 i = 0; i < frames; i++) { - ApplyMod((int16*)data, (int16*)buffer, i, pan); + ApplyMod((int16*)data, i, pan); UpdateMods(); } @@ -284,7 +282,7 @@ GameSoundBuffer::Play(void * data, int64 frames) case gs_audio_format::B_GS_S32: { for (int64 i = 0; i < frames; i++) { - ApplyMod((int32*)data, (int32*)buffer, i, pan); + ApplyMod((int32*)data, i, pan); UpdateMods(); } @@ -294,14 +292,13 @@ GameSoundBuffer::Play(void * data, int64 frames) case gs_audio_format::B_GS_F: { for (int64 i = 0; i < frames; i++) { - ApplyMod((float*)data, (float*)buffer, i, pan); + ApplyMod((float*)data, 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