audio buffer size patches
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6829 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -20,11 +20,15 @@
|
|||||||
#define DECODE_BUFFER_SIZE (32 * 1024)
|
#define DECODE_BUFFER_SIZE (32 * 1024)
|
||||||
|
|
||||||
|
|
||||||
inline size_t
|
inline void
|
||||||
AudioBufferSize(media_raw_audio_format * raf, bigtime_t buffer_duration = 50000 /* 50 ms */)
|
AdjustBufferSize(media_raw_audio_format * raf, bigtime_t buffer_duration = 50000 /* 50 ms */)
|
||||||
{
|
{
|
||||||
return (raf->format & 0xf) * (raf->channel_count)
|
size_t frame_size = (raf->format & 0xf) * raf->channel_count;
|
||||||
* (size_t)((raf->frame_rate * buffer_duration) / 1000000.0);
|
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.frame_rate = (float)fHeader->rate;
|
||||||
format.u.raw_audio.channel_count = fHeader->nb_channels;
|
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);
|
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)) {
|
if (!format_is_compatible(format,*ioDecodedFormat)) {
|
||||||
*ioDecodedFormat = format;
|
*ioDecodedFormat = format;
|
||||||
}
|
}
|
||||||
ioDecodedFormat->SpecializeTo(&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
|
// setup output variables
|
||||||
fFrameSize = (ioDecodedFormat->u.raw_audio.format & 0xf) *
|
fFrameSize = ioDecodedFormat->AudioFrameSize();
|
||||||
(ioDecodedFormat->u.raw_audio.channel_count);
|
|
||||||
fOutputBufferSize = ioDecodedFormat->u.raw_audio.buffer_size;
|
fOutputBufferSize = ioDecodedFormat->u.raw_audio.buffer_size;
|
||||||
fSpeexOutputLength = output_length;
|
fSpeexOutputLength = output_length;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|||||||
@@ -21,8 +21,8 @@
|
|||||||
inline void
|
inline void
|
||||||
AdjustBufferSize(media_raw_audio_format * raf, bigtime_t buffer_duration = 50000 /* 50 ms */)
|
AdjustBufferSize(media_raw_audio_format * raf, bigtime_t buffer_duration = 50000 /* 50 ms */)
|
||||||
{
|
{
|
||||||
int frame_size = (raf->format & 0xf) * raf->channel_count;
|
size_t frame_size = (raf->format & 0xf) * raf->channel_count;
|
||||||
if (raf->buffer_size == 0) {
|
if (raf->buffer_size <= frame_size) {
|
||||||
raf->buffer_size = frame_size * (size_t)((raf->frame_rate * buffer_duration) / 1000000.0);
|
raf->buffer_size = frame_size * (size_t)((raf->frame_rate * buffer_duration) / 1000000.0);
|
||||||
} else {
|
} else {
|
||||||
raf->buffer_size = (raf->buffer_size / frame_size) * frame_size;
|
raf->buffer_size = (raf->buffer_size / frame_size) * frame_size;
|
||||||
@@ -97,12 +97,12 @@ VorbisDecoder::Setup(media_format *inputFormat,
|
|||||||
}
|
}
|
||||||
// parse comment packet
|
// parse comment packet
|
||||||
if (vorbis_synthesis_headerin(&fInfo,&fComment,&(*packets)[1]) != 0) {
|
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;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
// parse codebook packet
|
// parse codebook packet
|
||||||
if (vorbis_synthesis_headerin(&fInfo,&fComment,&(*packets)[2]) != 0) {
|
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;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
// initialize decoder
|
// initialize decoder
|
||||||
|
|||||||
Reference in New Issue
Block a user