diff options
author | andrew@webrtc.org <andrew@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2013-05-02 00:30:36 +0000 |
---|---|---|
committer | andrew@webrtc.org <andrew@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> | 2013-05-02 00:30:36 +0000 |
commit | 4a68e95e2b6b6da1def731fa5f96559ee6f76c23 (patch) | |
tree | c172b28dd013fe937dc9f4a44753ef2523640fec /voice_engine/transmit_mixer.cc | |
parent | 166153edf3ca7372f62d86b050ea91a7ec494be9 (diff) | |
download | webrtc-4a68e95e2b6b6da1def731fa5f96559ee6f76c23.tar.gz |
Replace Resampler with PushResampler in transmit_mixer.
* VoE can now exchange 44.1 kHz audio with AudioDevice.
* Changes still required in AudioDevice to remove the 44 kHz workarounds and
enable native 44.1 kHz.
BUG=webrtc:1395
TESTED=voe_cmd_test loopback running through codecs using all combinations of {8, 16, 32} kHz and {1, 2} channels, and Opus (48 kHz, stereo)
R=bjornv@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/1373004
git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@3930 4adac7df-926f-26a2-2b94-8c16560cd09d
Diffstat (limited to 'voice_engine/transmit_mixer.cc')
-rw-r--r-- | voice_engine/transmit_mixer.cc | 123 |
1 files changed, 59 insertions, 64 deletions
diff --git a/voice_engine/transmit_mixer.cc b/voice_engine/transmit_mixer.cc index 4e6e6d67..ea35afb9 100644 --- a/voice_engine/transmit_mixer.cc +++ b/voice_engine/transmit_mixer.cc @@ -8,19 +8,19 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "transmit_mixer.h" - -#include "audio_frame_operations.h" -#include "channel.h" -#include "channel_manager.h" -#include "critical_section_wrapper.h" -#include "event_wrapper.h" -#include "statistics.h" -#include "trace.h" -#include "utility.h" -#include "voe_base_impl.h" -#include "voe_external_media.h" +#include "webrtc/voice_engine/transmit_mixer.h" + +#include "webrtc/modules/utility/interface/audio_frame_operations.h" +#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" +#include "webrtc/system_wrappers/interface/event_wrapper.h" #include "webrtc/system_wrappers/interface/logging.h" +#include "webrtc/system_wrappers/interface/trace.h" +#include "webrtc/voice_engine/channel.h" +#include "webrtc/voice_engine/channel_manager.h" +#include "webrtc/voice_engine/include/voe_external_media.h" +#include "webrtc/voice_engine/statistics.h" +#include "webrtc/voice_engine/utility.h" +#include "webrtc/voice_engine/voe_base_impl.h" #define WEBRTC_ABS(a) (((a) < 0) ? -(a) : (a)) @@ -1155,60 +1155,55 @@ bool TransmitMixer::IsRecordingMic() int TransmitMixer::GenerateAudioFrame(const int16_t audio[], int samples_per_channel, int num_channels, - int sample_rate_hz) -{ - int destination_rate; - int num_codec_channels; - GetSendCodecInfo(&destination_rate, &num_codec_channels); - - // Never upsample the capture signal here. This should be done at the - // end of the send chain. - destination_rate = std::min(destination_rate, sample_rate_hz); - stereo_codec_ = num_codec_channels == 2; - - const int16_t* audio_ptr = audio; - int16_t mono_audio[kMaxMonoDeviceDataSizeSamples]; - assert(samples_per_channel <= kMaxMonoDeviceDataSizeSamples); - // If no stereo codecs are in use, we downmix a stereo stream from the - // device early in the chain, before resampling. - if (num_channels == 2 && !stereo_codec_) { - AudioFrameOperations::StereoToMono(audio, samples_per_channel, - mono_audio); - audio_ptr = mono_audio; - num_channels = 1; - } - - ResamplerType resampler_type = (num_channels == 1) ? - kResamplerSynchronous : kResamplerSynchronousStereo; - - if (_audioResampler.ResetIfNeeded(sample_rate_hz, - destination_rate, - resampler_type) != 0) - { - WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, -1), - "TransmitMixer::GenerateAudioFrame() unable to resample"); - return -1; - } - if (_audioResampler.Push(audio_ptr, - samples_per_channel * num_channels, - _audioFrame.data_, - AudioFrame::kMaxDataSizeSamples, - _audioFrame.samples_per_channel_) == -1) - { - WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, -1), - "TransmitMixer::GenerateAudioFrame() resampling failed"); - return -1; - } + int sample_rate_hz) { + int destination_rate; + int num_codec_channels; + GetSendCodecInfo(&destination_rate, &num_codec_channels); + + // Never upsample the capture signal here. This should be done at the + // end of the send chain. + destination_rate = std::min(destination_rate, sample_rate_hz); + stereo_codec_ = num_codec_channels == 2; + + const int16_t* audio_ptr = audio; + int16_t mono_audio[kMaxMonoDeviceDataSizeSamples]; + assert(samples_per_channel <= kMaxMonoDeviceDataSizeSamples); + // If no stereo codecs are in use, we downmix a stereo stream from the + // device early in the chain, before resampling. + if (num_channels == 2 && !stereo_codec_) { + AudioFrameOperations::StereoToMono(audio, samples_per_channel, + mono_audio); + audio_ptr = mono_audio; + num_channels = 1; + } - _audioFrame.samples_per_channel_ /= num_channels; - _audioFrame.id_ = _instanceId; - _audioFrame.timestamp_ = -1; - _audioFrame.sample_rate_hz_ = destination_rate; - _audioFrame.speech_type_ = AudioFrame::kNormalSpeech; - _audioFrame.vad_activity_ = AudioFrame::kVadUnknown; - _audioFrame.num_channels_ = num_channels; + if (resampler_.InitializeIfNeeded(sample_rate_hz, + destination_rate, + num_channels) != 0) { + WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, -1), + "TransmitMixer::GenerateAudioFrame() unable to resample"); + return -1; + } - return 0; + int out_length = resampler_.Resample(audio_ptr, + samples_per_channel * num_channels, + _audioFrame.data_, + AudioFrame::kMaxDataSizeSamples); + if (out_length == -1) { + WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, -1), + "TransmitMixer::GenerateAudioFrame() resampling failed"); + return -1; + } + + _audioFrame.samples_per_channel_ = out_length / num_channels; + _audioFrame.id_ = _instanceId; + _audioFrame.timestamp_ = -1; + _audioFrame.sample_rate_hz_ = destination_rate; + _audioFrame.speech_type_ = AudioFrame::kNormalSpeech; + _audioFrame.vad_activity_ = AudioFrame::kVadUnknown; + _audioFrame.num_channels_ = num_channels; + + return 0; } int32_t TransmitMixer::RecordAudioToFile( |