debugging improvement, fixed locking, fixed sample copy bug in channel 1
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3730 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
#include "MixerUtils.h"
|
||||
#include "AudioMixer.h"
|
||||
#include "Resampler.h"
|
||||
#include "Debug.h"
|
||||
#include "debug.h"
|
||||
|
||||
#define DOUBLE_RATE_MIXING 1
|
||||
|
||||
@@ -340,15 +340,6 @@ MixerCore::StopMixThread()
|
||||
fRunning = false;
|
||||
}
|
||||
|
||||
/*
|
||||
bool
|
||||
MixerCore::IsStarted()
|
||||
{
|
||||
ASSERT_LOCKED();
|
||||
return fRunning;
|
||||
}
|
||||
*/
|
||||
|
||||
int32
|
||||
MixerCore::_mix_thread_(void *arg)
|
||||
{
|
||||
@@ -369,18 +360,21 @@ MixerCore::MixThread()
|
||||
// The broken BeOS R5 multiaudio node starts with time 0,
|
||||
// then publishes negative times for about 50ms, publishes 0
|
||||
// again until it finally reaches time values > 0
|
||||
Lock();
|
||||
if (!LockFromMixThread())
|
||||
return;
|
||||
start = fTimeSource->Now();
|
||||
Unlock();
|
||||
while (start <= 0) {
|
||||
printf("MixerCore: delaying MixThread start, timesource is at %Ld\n", start);
|
||||
snooze(1000);
|
||||
Lock();
|
||||
if (!LockFromMixThread())
|
||||
return;
|
||||
start = fTimeSource->Now();
|
||||
Unlock();
|
||||
}
|
||||
|
||||
Lock();
|
||||
if (!LockFromMixThread())
|
||||
return;
|
||||
latency = bigtime_t(0.4 * buffer_duration(fOutput->MediaOutput().format.u.raw_audio));
|
||||
|
||||
printf("MixerCore: starting MixThread at %Ld with latency %Ld and downstream latency %Ld\n", start, latency, fDownstreamLatency);
|
||||
@@ -397,9 +391,13 @@ MixerCore::MixThread()
|
||||
event_time = time_base;
|
||||
frame_pos = 0;
|
||||
for (;;) {
|
||||
bigtime_t wait_until;
|
||||
if (!LockFromMixThread())
|
||||
return;
|
||||
wait_until = fTimeSource->RealTimeFor(event_time, 0) - latency - fDownstreamLatency;
|
||||
Unlock();
|
||||
status_t rv;
|
||||
// rv = acquire_sem_etc(fMixThreadWaitSem, 1, B_ABSOLUTE_TIMEOUT, fTimeSource->RealTimeFor(event_time, latency + fDownstreamLatency));
|
||||
rv = acquire_sem_etc(fMixThreadWaitSem, 1, B_ABSOLUTE_TIMEOUT, fTimeSource->RealTimeFor(event_time, 0) - latency - fDownstreamLatency);
|
||||
rv = acquire_sem_etc(fMixThreadWaitSem, 1, B_ABSOLUTE_TIMEOUT, wait_until);
|
||||
if (rv == B_INTERRUPTED)
|
||||
continue;
|
||||
if (rv != B_TIMED_OUT && rv < B_OK)
|
||||
@@ -411,13 +409,10 @@ MixerCore::MixThread()
|
||||
// mix all data from all inputs into the mix buffer
|
||||
ASSERT((frame_base + frame_pos) % fMixBufferFrameCount == 0);
|
||||
|
||||
// printf("create new buffer event at %Ld, reading input frames at %Ld\n", event_time, frame_base + frame_pos);
|
||||
PRINT(4, "create new buffer event at %Ld, reading input frames at %Ld\n", event_time, frame_base + frame_pos);
|
||||
|
||||
// XXX this is a test, copy the the left and right channel from input 1 or 0
|
||||
|
||||
if (fMixBufferChannelCount > 2)
|
||||
memset(fMixBuffer, 0, fMixBufferChannelCount * fMixBufferFrameCount * sizeof(float));
|
||||
|
||||
MixerInput *input = Input(1);
|
||||
if (!input)
|
||||
input = Input(0);
|
||||
@@ -427,7 +422,7 @@ MixerCore::MixThread()
|
||||
|
||||
if (input) {
|
||||
|
||||
printf("at %10Ld, data reading for %10Ld to %10Ld, ", fTimeSource->Now(), event_time, event_time + duration_for_frames(fMixBufferFrameRate, fMixBufferFrameCount));
|
||||
PRINT(3, "at %10Ld, data reading for %10Ld to %10Ld, ", fTimeSource->Now(), event_time, event_time + duration_for_frames(fMixBufferFrameRate, fMixBufferFrameCount));
|
||||
|
||||
int64 cur_framepos = frame_base + frame_pos;
|
||||
|
||||
@@ -442,17 +437,7 @@ MixerCore::MixThread()
|
||||
input->GetMixerChannelInfo(chan, cur_framepos, &buffer, &src_sample_offset, &type, &gain);
|
||||
dst_sample_offset = fMixBufferChannelCount * sizeof(float);
|
||||
|
||||
char *src = (char *)buffer;
|
||||
char *dst = (char *)fMixBuffer;
|
||||
|
||||
src += chan * sizeof(float);
|
||||
dst += chan * sizeof(float);
|
||||
|
||||
for (int i = 0; i < fMixBufferFrameCount; i++) {
|
||||
*(float *)dst = *(float *)src;
|
||||
dst += dst_sample_offset;
|
||||
src += src_sample_offset;
|
||||
}
|
||||
CopySamples(&fMixBuffer[chan], dst_sample_offset, buffer, src_sample_offset, fMixBufferFrameCount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,7 +456,7 @@ MixerCore::MixThread()
|
||||
frames_per_buffer(fOutput->MediaOutput().format.u.raw_audio),
|
||||
1.0);
|
||||
}
|
||||
// printf("send buffer, inframes %ld, outframes %ld\n",fMixBufferFrameCount, frames_per_buffer(fOutput->MediaOutput().format.u.raw_audio));
|
||||
PRINT(4, "send buffer, inframes %ld, outframes %ld\n",fMixBufferFrameCount, frames_per_buffer(fOutput->MediaOutput().format.u.raw_audio));
|
||||
|
||||
// fill in the buffer header
|
||||
media_header* hdr = buf->Header();
|
||||
|
||||
@@ -27,6 +27,7 @@ public:
|
||||
|
||||
void Lock();
|
||||
bool LockWithTimeout(bigtime_t timeout);
|
||||
bool LockFromMixThread();
|
||||
void Unlock();
|
||||
|
||||
void BufferReceived(BBuffer *buffer, bigtime_t lateness);
|
||||
@@ -42,8 +43,6 @@ public:
|
||||
|
||||
void StartMixThread();
|
||||
void StopMixThread();
|
||||
|
||||
// bool IsStarted();
|
||||
|
||||
uint32 OutputChannelCount();
|
||||
|
||||
@@ -97,4 +96,15 @@ inline void MixerCore::Unlock()
|
||||
fLocker->Unlock();
|
||||
}
|
||||
|
||||
inline bool MixerCore::LockFromMixThread()
|
||||
{
|
||||
for (;;) {
|
||||
if (LockWithTimeout(10000))
|
||||
return true;
|
||||
// XXX accessing fMixThreadWaitSem is still a race condition :(
|
||||
if (B_WOULD_BLOCK != acquire_sem_etc(fMixThreadWaitSem, 1, B_RELATIVE_TIMEOUT, 0))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -120,9 +120,9 @@ MixerInput::BufferReceived(BBuffer *buffer)
|
||||
// if (offset < 0)
|
||||
// offset += fMixBufferFrameCount;
|
||||
|
||||
// printf("MixerInput::BufferReceived: mix buffer start %14Ld, buffer start %14Ld, offset %6d\n", fMixBufferStartTime, start, offset);
|
||||
PRINT(4, "MixerInput::BufferReceived: buffer start %10Ld, offset %6d\n", start, offset);
|
||||
|
||||
int in_frames = buffer->SizeUsed() / bytes_per_frame(fInput.format.u.raw_audio);
|
||||
int in_frames = size / bytes_per_frame(fInput.format.u.raw_audio);
|
||||
int out_frames = (int)((in_frames * fMixBufferFrameRate) / fInput.format.u.raw_audio.frame_rate); // XXX losing fractions
|
||||
|
||||
//printf("data arrived for %10Ld to %10Ld, storing at frames %ld to %ld\n", start, start + duration_for_frames(fInput.format.u.raw_audio.frame_rate, frames_per_buffer(fInput.format.u.raw_audio)), offset, offset + out_frames);
|
||||
@@ -134,10 +134,10 @@ MixerInput::BufferReceived(BBuffer *buffer)
|
||||
int in_frames1 = (out_frames1 * in_frames) / out_frames;
|
||||
int in_frames2 = in_frames - in_frames1;
|
||||
|
||||
printf("at %10Ld, data arrived for %10Ld to %10Ld, storing at frames %ld to %ld and %ld to %ld\n", fCore->fTimeSource->Now(), start, start + duration_for_frames(fInput.format.u.raw_audio.frame_rate, frames_per_buffer(fInput.format.u.raw_audio)), offset, offset + out_frames1, 0, out_frames2);
|
||||
PRINT(3, "at %10Ld, data arrived for %10Ld to %10Ld, storing at frames %ld to %ld and %ld to %ld\n", fCore->fTimeSource->Now(), start, start + duration_for_frames(fInput.format.u.raw_audio.frame_rate, frames_per_buffer(fInput.format.u.raw_audio)), offset, offset + out_frames1, 0, out_frames2);
|
||||
|
||||
//printf(" in_frames %5d, out_frames %5d, in_frames1 %5d, out_frames1 %5d, in_frames2 %5d, out_frames2 %5d\n",
|
||||
// in_frames, out_frames, in_frames1, out_frames1, in_frames2, out_frames2);
|
||||
PRINT(5, " in_frames %5d, out_frames %5d, in_frames1 %5d, out_frames1 %5d, in_frames2 %5d, out_frames2 %5d\n",
|
||||
in_frames, out_frames, in_frames1, out_frames1, in_frames2, out_frames2);
|
||||
|
||||
offset *= sizeof(float) * fInputChannelCount; // convert offset from frames into bytes
|
||||
|
||||
@@ -159,11 +159,12 @@ MixerInput::BufferReceived(BBuffer *buffer)
|
||||
fInputChannelCount * sizeof(float),
|
||||
out_frames2,
|
||||
fInputChannelInfo[i].gain);
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
printf("at %10Ld, data arrived for %10Ld to %10Ld, storing at frames %ld to %ld\n", fCore->fTimeSource->Now(), start, start + duration_for_frames(fInput.format.u.raw_audio.frame_rate, frames_per_buffer(fInput.format.u.raw_audio)), offset, offset + out_frames);
|
||||
//printf(" in_frames %5d, out_frames %5d\n", in_frames, out_frames);
|
||||
PRINT(3, "at %10Ld, data arrived for %10Ld to %10Ld, storing at frames %ld to %ld\n", fCore->fTimeSource->Now(), start, start + duration_for_frames(fInput.format.u.raw_audio.frame_rate, frames_per_buffer(fInput.format.u.raw_audio)), offset, offset + out_frames);
|
||||
PRINT(5, " in_frames %5d, out_frames %5d\n", in_frames, out_frames);
|
||||
|
||||
offset *= sizeof(float) * fInputChannelCount; // convert offset from frames into bytes
|
||||
|
||||
@@ -393,7 +394,7 @@ MixerInput::GetMixerChannelInfo(int channel, int64 framepos, const float **buffe
|
||||
ASSERT(fMixBuffer); // this function should not be called if we don't have a mix buffer!
|
||||
ASSERT(channel >= 0 && channel < fMixerChannelCount);
|
||||
int32 offset = framepos % fMixBufferFrameCount;
|
||||
if (channel == 0) printf("GetMixerChannelInfo: frames %ld to %ld\n", offset, offset + debugMixBufferFrames);
|
||||
if (channel == 0) PRINT(3, "GetMixerChannelInfo: frames %ld to %ld\n", offset, offset + debugMixBufferFrames);
|
||||
*buffer = reinterpret_cast<float *>(reinterpret_cast<char *>(fMixerChannelInfo[channel].buffer_base) + (offset * sizeof(float) * fInputChannelCount));
|
||||
*sample_offset = sizeof(float) * fInputChannelCount;
|
||||
*type = fMixerChannelInfo[channel].type;
|
||||
|
||||
Reference in New Issue
Block a user