From a79b30c3b65a0035ccda843c6685accec08f833f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 31 Aug 2010 16:07:52 +0000 Subject: [PATCH] * In the MixerInput, also use the Linear resampler if requested by the settings. (There is a common "mixing frame rate" to which all inputs resample, before the MixerCore resamples to the frame rate of the output.) * Some more coding style fixes in MixerCore. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38479 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../media/media-add-ons/mixer/MixerCore.cpp | 38 ++++++++++--------- .../media/media-add-ons/mixer/MixerInput.cpp | 17 +++++++-- .../media/media-add-ons/mixer/MixerInput.h | 3 +- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp b/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp index 5615930901..3b5bdefd35 100644 --- a/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp +++ b/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp @@ -106,7 +106,7 @@ MixerCore::~MixerCore() if (fResampler) { for (int i = 0; i < fMixBufferChannelCount; i++) delete fResampler[i]; - delete [] fResampler; + delete[] fResampler; } delete fMixBufferChannelTypes; @@ -133,7 +133,7 @@ MixerCore::AddInput(const media_input& input) { ASSERT_LOCKED(); MixerInput* in = new MixerInput(this, input, fMixBufferFrameRate, - fMixBufferFrameCount); + fMixBufferFrameCount, Settings()->ResamplingAlgorithm()); fInputs->AddItem(in); return in; } @@ -286,16 +286,17 @@ MixerCore::ApplyOutputFormat() = ChannelMaskToChannelType(GetChannelMask(i, format.channel_mask)); } - fMixBuffer = (float *)rtm_alloc(NULL, sizeof(float) * fMixBufferFrameCount * fMixBufferChannelCount); - ASSERT(fMixBuffer); + fMixBuffer = (float*)rtm_alloc(NULL, sizeof(float) * fMixBufferFrameCount + * fMixBufferChannelCount); + ASSERT(fMixBuffer != NULL); - if (fResampler) { + if (fResampler != NULL) { for (int i = 0; i < fMixBufferChannelCount; i++) delete fResampler[i]; - delete [] fResampler; + delete[] fResampler; } - fResampler = new Resampler * [fMixBufferChannelCount]; + fResampler = new Resampler*[fMixBufferChannelCount]; for (int i = 0; i < fMixBufferChannelCount; i++) { switch (Settings()->ResamplingAlgorithm()) { case 2: @@ -491,8 +492,8 @@ MixerCore::MixThread() uint64 bufferIndex = 0; #endif - RtList InputChanInfos[MAX_CHANNEL_TYPES]; - RtList MixChanInfos[fMixBufferChannelCount]; + RtList inputChanInfos[MAX_CHANNEL_TYPES]; + RtList mixChanInfos[fMixBufferChannelCount]; // TODO: this does not support changing output channel count bigtime_t eventTime = timeBase; @@ -558,6 +559,7 @@ MixerCore::MixThread() PRINT(4, "create new buffer event at %Ld, reading input frames at " "%Ld\n", eventTime, currentFramePos); + // Init the channel information for each MixerInput. for (int i = 0; MixerInput* input = Input(i); i++) { int count = input->GetMixerChannelCount(); for (int channel = 0; channel < count; channel++) { @@ -571,7 +573,7 @@ MixerCore::MixThread() } if (type < 0 || type >= MAX_CHANNEL_TYPES) continue; - chan_info* info = InputChanInfos[type].Create(); + chan_info* info = inputChanInfos[type].Create(); info->base = (const char*)base; info->sample_offset = sampleOffset; info->gain = gain; @@ -587,10 +589,10 @@ MixerCore::MixThread() &gain); if (type < 0 || type >= MAX_CHANNEL_TYPES) continue; - int count = InputChanInfos[type].CountItems(); + int count = inputChanInfos[type].CountItems(); for (int j = 0; j < count; j++) { - chan_info* info = InputChanInfos[type].ItemAt(j); - chan_info* newInfo = MixChanInfos[channel].Create(); + chan_info* info = inputChanInfos[type].ItemAt(j); + chan_info* newInfo = mixChanInfos[channel].Create(); newInfo->base = info->base; newInfo->sample_offset = info->sample_offset; newInfo->gain = info->gain * gain; @@ -602,11 +604,11 @@ MixerCore::MixThread() fMixBufferChannelCount * fMixBufferFrameCount * sizeof(float)); for (int channel = 0; channel < fMixBufferChannelCount; channel++) { PRINT(5, "MixThread: channel %d has %d sources\n", channel, - MixChanInfos[channel].CountItems()); + mixChanInfos[channel].CountItems()); - int count = MixChanInfos[channel].CountItems(); + int count = mixChanInfos[channel].CountItems(); for (int i = 0; i < count; i++) { - chan_info* info = MixChanInfos[channel].ItemAt(i); + chan_info* info = mixChanInfos[channel].ItemAt(i); PRINT(5, "MixThread: base %p, sample-offset %2d, gain %.3f\n", info->base, info->sample_offset, info->gain); // This looks slightly ugly, but the current GCC will generate @@ -684,9 +686,9 @@ MixerCore::MixThread() // make all lists empty for (int i = 0; i < MAX_CHANNEL_TYPES; i++) - InputChanInfos[i].MakeEmpty(); + inputChanInfos[i].MakeEmpty(); for (int i = 0; i < fOutput->GetOutputChannelCount(); i++) - MixChanInfos[i].MakeEmpty(); + mixChanInfos[i].MakeEmpty(); schedule_next_event: // schedule next event diff --git a/src/add-ons/media/media-add-ons/mixer/MixerInput.cpp b/src/add-ons/media/media-add-ons/mixer/MixerInput.cpp index 8d5cb0e1fd..5f0ebc3fd8 100644 --- a/src/add-ons/media/media-add-ons/mixer/MixerInput.cpp +++ b/src/add-ons/media/media-add-ons/mixer/MixerInput.cpp @@ -14,13 +14,14 @@ #include // TODO: debug only #include "ByteSwap.h" +#include "Interpolate.h" #include "MixerInput.h" #include "MixerUtils.h" #include "Resampler.h" MixerInput::MixerInput(MixerCore *core, const media_input &input, - float mixFrameRate, int32 mixFrameCount) + float mixFrameRate, int32 mixFrameCount, int resamplingAlgorithm) : fCore(core), fInput(input), @@ -78,9 +79,17 @@ MixerInput::MixerInput(MixerCore *core, const media_input &input, // create resamplers fResampler = new Resampler * [fInputChannelCount]; for (int i = 0; i < fInputChannelCount; i++) { - // TODO create Interpolate instead of Resampler if the settings says so - fResampler[i] = new Resampler(fInput.format.u.raw_audio.format, - media_raw_audio_format::B_AUDIO_FLOAT); + switch (resamplingAlgorithm) { + case 2: + fResampler[i] = new Interpolate( + fInput.format.u.raw_audio.format, + media_raw_audio_format::B_AUDIO_FLOAT); + break; + default: + fResampler[i] = new Resampler( + fInput.format.u.raw_audio.format, + media_raw_audio_format::B_AUDIO_FLOAT); + } } // fMixerChannelInfo and fMixerChannelCount will be initialized by diff --git a/src/add-ons/media/media-add-ons/mixer/MixerInput.h b/src/add-ons/media/media-add-ons/mixer/MixerInput.h index ee051950c7..a6ade9b8fc 100644 --- a/src/add-ons/media/media-add-ons/mixer/MixerInput.h +++ b/src/add-ons/media/media-add-ons/mixer/MixerInput.h @@ -25,7 +25,8 @@ class MixerInput { public: MixerInput(MixerCore* core, const media_input& input, - float mixFrameRate, int32 mixFrameCount); + float mixFrameRate, int32 mixFrameCount, + int resamplingAlgorithm); ~MixerInput(); int32 ID();