* _FillNextBuffer(): performanceTime and startTime were duplicated variables.

* Small coding style improvements.
 * Improved generating of debug .wav file.
 * Incorporate the channel count in the audio buffer size! This was important
   since the duration could then lead to rounding errors. 6 channel playback
   is much improved, but still far from perfect.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38469 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2010-08-30 22:26:11 +00:00
parent 0f7fb31be2
commit cfe3295bcf

View File

@ -65,21 +65,22 @@ init_media_file(media_format format, BMediaTrack** _track)
media_file_format fileFormat;
int32 cookie = 0;
while (get_next_file_format(&cookie, &fileFormat) == B_OK) {
if (strcmp(fileFormat.short_name, "wav") == 0) {
if (strcmp(fileFormat.short_name, "wav") == 0)
break;
}
}
file = new BMediaFile(&ref, &fileFormat);
media_codec_info info;
cookie = 0;
while (get_next_encoder(&cookie, &info) == B_OK) {
if (strcmp(info.short_name, "raw-audio") == 0)
if (strcmp(info.short_name, "raw-audio") == 0
|| strcmp(info.short_name, "pcm") == 0) {
break;
}
}
track = file->CreateTrack(&format, &info);
if (!track)
if (track == NULL)
printf("failed to create track\n");
file->CommitHeader();
@ -755,6 +756,7 @@ AudioProducer::_SpecializeFormat(media_format* format)
// 25, which it usually is.)
format->u.raw_audio.buffer_size
= uint32(format->u.raw_audio.frame_rate / 25.0)
* format->u.raw_audio.channel_count
* (format->u.raw_audio.format
& media_raw_audio_format::B_AUDIO_SIZE_MASK);
@ -830,16 +832,14 @@ AudioProducer::_FillNextBuffer(bigtime_t eventTime)
header->time_source = TimeSource()->ID();
buffer->SetSizeUsed(fOutput.format.u.raw_audio.buffer_size);
bigtime_t performanceTime = bigtime_t(double(fFramesSent)
* 1000000.0 / double(fOutput.format.u.raw_audio.frame_rate));
// fill in data from audio supplier
int64 frameCount = numSamples / fOutput.format.u.raw_audio.channel_count;
bigtime_t startTime = performanceTime;
bigtime_t startTime = bigtime_t(double(fFramesSent)
* 1000000.0 / fOutput.format.u.raw_audio.frame_rate);
bigtime_t endTime = bigtime_t(double(fFramesSent + frameCount)
* 1000000.0 / fOutput.format.u.raw_audio.frame_rate);
if (!fSupplier || fSupplier->InitCheck() != B_OK
if (fSupplier == NULL || fSupplier->InitCheck() != B_OK
|| fSupplier->GetFrames(buffer->Data(), frameCount, startTime,
endTime) != B_OK) {
ERROR("AudioProducer::_FillNextBuffer() - supplier error -> silence\n");
@ -847,17 +847,15 @@ AudioProducer::_FillNextBuffer(bigtime_t eventTime)
}
// stamp buffer
if (RunMode() == B_RECORDING) {
if (RunMode() == B_RECORDING)
header->start_time = eventTime;
} else {
header->start_time = fStartTime + performanceTime;
}
else
header->start_time = fStartTime + startTime;
#if DEBUG_TO_FILE
BMediaTrack* track;
if (BMediaFile* file = init_media_file(fOutput.format, &track)) {
if (init_media_file(fOutput.format, &track) != NULL)
track->WriteFrames(buffer->Data(), frameCount);
}
#endif // DEBUG_TO_FILE
if (fPeakListener
@ -887,7 +885,7 @@ AudioProducer::_FillNextBuffer(bigtime_t eventTime)
message.AddFloat("max", maxAbs);
}
bigtime_t realTime = TimeSource()->RealTimeFor(
fStartTime + performanceTime, 0);
fStartTime + startTime, 0);
MessageEvent* event = new (std::nothrow) MessageEvent(realTime,
fPeakListener, message);
if (event != NULL)