* 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
This commit is contained in:
Stephan Aßmus 2010-08-31 16:07:52 +00:00
parent 5911196b9c
commit a79b30c3b6
3 changed files with 35 additions and 23 deletions

View File

@ -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<chan_info> InputChanInfos[MAX_CHANNEL_TYPES];
RtList<chan_info> MixChanInfos[fMixBufferChannelCount];
RtList<chan_info> inputChanInfos[MAX_CHANNEL_TYPES];
RtList<chan_info> 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

View File

@ -14,13 +14,14 @@
#include <TimeSource.h> // 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

View File

@ -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();