From 6f524d0869bac94bb61a8009ebcf2ca5e0fdd6c0 Mon Sep 17 00:00:00 2001 From: shatty Date: Sun, 29 Feb 2004 23:31:22 +0000 Subject: [PATCH] audio buffer size patches git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6829 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../media/plugins/speex/speexCodecPlugin.cpp | 27 +++++++++---------- .../plugins/vorbis/vorbisCodecPlugin.cpp | 8 +++--- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/add-ons/media/plugins/speex/speexCodecPlugin.cpp b/src/add-ons/media/plugins/speex/speexCodecPlugin.cpp index d86ca50770..2da5573d94 100644 --- a/src/add-ons/media/plugins/speex/speexCodecPlugin.cpp +++ b/src/add-ons/media/plugins/speex/speexCodecPlugin.cpp @@ -20,11 +20,15 @@ #define DECODE_BUFFER_SIZE (32 * 1024) -inline size_t -AudioBufferSize(media_raw_audio_format * raf, bigtime_t buffer_duration = 50000 /* 50 ms */) +inline void +AdjustBufferSize(media_raw_audio_format * raf, bigtime_t buffer_duration = 50000 /* 50 ms */) { - return (raf->format & 0xf) * (raf->channel_count) - * (size_t)((raf->frame_rate * buffer_duration) / 1000000.0); + size_t frame_size = (raf->format & 0xf) * raf->channel_count; + if (raf->buffer_size <= frame_size) { + raf->buffer_size = frame_size * (size_t)((raf->frame_rate * buffer_duration) / 1000000.0); + } else { + raf->buffer_size = (raf->buffer_size / frame_size) * frame_size; + } } @@ -209,21 +213,16 @@ SpeexDecoder::NegotiateOutputFormat(media_format *ioDecodedFormat) format.u.raw_audio.frame_rate = (float)fHeader->rate; format.u.raw_audio.channel_count = fHeader->nb_channels; format.u.raw_audio.channel_mask = B_CHANNEL_LEFT | (fHeader->nb_channels != 1 ? B_CHANNEL_RIGHT : 0); - int buffer_size = ioDecodedFormat->u.raw_audio.buffer_size; - if (buffer_size < 512) { - buffer_size = AudioBufferSize(&format.u.raw_audio); - } - int output_length = fHeader->frame_size * fHeader->nb_channels - * (format.u.raw_audio.format & 0xf); - buffer_size = ((buffer_size - 1) / output_length + 1) * output_length; - format.u.raw_audio.buffer_size = buffer_size; if (!format_is_compatible(format,*ioDecodedFormat)) { *ioDecodedFormat = format; } ioDecodedFormat->SpecializeTo(&format); + AdjustBufferSize(&ioDecodedFormat->u.raw_audio); + int output_length = fHeader->frame_size * format.AudioFrameSize(); + ioDecodedFormat->u.raw_audio.buffer_size + = ((ioDecodedFormat->u.raw_audio.buffer_size - 1) / output_length + 1) * output_length; // setup output variables - fFrameSize = (ioDecodedFormat->u.raw_audio.format & 0xf) * - (ioDecodedFormat->u.raw_audio.channel_count); + fFrameSize = ioDecodedFormat->AudioFrameSize(); fOutputBufferSize = ioDecodedFormat->u.raw_audio.buffer_size; fSpeexOutputLength = output_length; return B_OK; diff --git a/src/add-ons/media/plugins/vorbis/vorbisCodecPlugin.cpp b/src/add-ons/media/plugins/vorbis/vorbisCodecPlugin.cpp index e88d793cf6..f1e239007d 100644 --- a/src/add-ons/media/plugins/vorbis/vorbisCodecPlugin.cpp +++ b/src/add-ons/media/plugins/vorbis/vorbisCodecPlugin.cpp @@ -21,8 +21,8 @@ inline void AdjustBufferSize(media_raw_audio_format * raf, bigtime_t buffer_duration = 50000 /* 50 ms */) { - int frame_size = (raf->format & 0xf) * raf->channel_count; - if (raf->buffer_size == 0) { + size_t frame_size = (raf->format & 0xf) * raf->channel_count; + if (raf->buffer_size <= frame_size) { raf->buffer_size = frame_size * (size_t)((raf->frame_rate * buffer_duration) / 1000000.0); } else { raf->buffer_size = (raf->buffer_size / frame_size) * frame_size; @@ -97,12 +97,12 @@ VorbisDecoder::Setup(media_format *inputFormat, } // parse comment packet if (vorbis_synthesis_headerin(&fInfo,&fComment,&(*packets)[1]) != 0) { - TRACE("vorbiseDecoder::Setup: vorbis_synthesis_headerin failed: not vorbis comment\n"); + TRACE("VorbisDecoder::Setup: vorbis_synthesis_headerin failed: not vorbis comment\n"); return B_ERROR; } // parse codebook packet if (vorbis_synthesis_headerin(&fInfo,&fComment,&(*packets)[2]) != 0) { - TRACE("vorbiseDecoder::Setup: vorbis_synthesis_headerin failed: not vorbis codebook\n"); + TRACE("VorbisDecoder::Setup: vorbis_synthesis_headerin failed: not vorbis codebook\n"); return B_ERROR; } // initialize decoder