From 4257b175f3260a36e02fdd7b076a438cf8890a05 Mon Sep 17 00:00:00 2001 From: "xians@google.com" Date: Mon, 8 Aug 2011 12:02:36 +0000 Subject: [PATCH] The Cl is to support mixing output file in a stereo stream. Previously, an assert will be triggered in case it is not a mono stream. With the CL, the mono file stream will be copied into a strereo stream and mixed with the channel stream. More detail about the fix please refer to http://code.google.com/p/webrtc/issues/detail?id=36 Review URL: http://webrtc-codereview.appspot.com/93020 git-svn-id: http://webrtc.googlecode.com/svn/trunk@322 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/voice_engine/main/source/channel.cc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/voice_engine/main/source/channel.cc b/src/voice_engine/main/source/channel.cc index 78d552e6a..447ab5e6e 100644 --- a/src/voice_engine/main/source/channel.cc +++ b/src/voice_engine/main/source/channel.cc @@ -879,7 +879,6 @@ WebRtc_Word32 Channel::GetAudioFrame(const WebRtc_Word32 id, // Mix decoded PCM output with file if file mixing is enabled if (_outputFilePlaying) { - assert(audioFrame._audioChannel == 1); MixAudioWithFile(audioFrame, audioFrame._frequencyInHz); } @@ -6282,7 +6281,7 @@ Channel::MixAudioWithFile(AudioFrame& audioFrame, { assert(mixingFrequency <= 32000); - WebRtc_Word16 fileBuffer[320]; + WebRtc_Word16 fileBuffer[640]; WebRtc_UWord32 fileSamples(0); { @@ -6310,6 +6309,25 @@ Channel::MixAudioWithFile(AudioFrame& audioFrame, if (audioFrame._payloadDataLengthInSamples == fileSamples) { + // In case the incoming stream is stereo and file stream is mono, + // turn the file stream into stereo. + // TODO(xians): remove the code when FilePlayer supports real stereo. + if (audioFrame._audioChannel == 2) + { + // The mono file stream is copied to be stereo. + WebRtc_Word16* FileBufferCopy = new WebRtc_Word16[fileSamples]; + memcpy(FileBufferCopy, fileBuffer, + sizeof(WebRtc_Word16) * fileSamples); + for (unsigned int i = 0; i < fileSamples; i++) + { + fileBuffer[2*i] = FileBufferCopy[i]; + fileBuffer[2*i+1] = FileBufferCopy[i]; + } + fileSamples = 2*fileSamples; + delete [] FileBufferCopy; + } + + // Mix the incoming stream and file stream. Utility::MixWithSat(audioFrame._payloadData, fileBuffer, (WebRtc_UWord16)fileSamples);