simplified vorbis format negotiation and fixed buffer_size negotiation

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6812 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper 2004-02-29 18:48:22 +00:00
parent e4e48cc279
commit 93df7353db
2 changed files with 21 additions and 37 deletions

View File

@ -21,14 +21,6 @@ vorbis_description()
}
static void
init_vorbis_media_raw_audio_format(media_raw_audio_format * output)
{
output->format = media_raw_audio_format::B_AUDIO_FLOAT;
output->byte_order = B_MEDIA_HOST_ENDIAN;
}
static media_format
vorbis_encoded_media_format()
{
@ -37,7 +29,8 @@ vorbis_encoded_media_format()
format.user_data_type = B_CODEC_TYPE_INFO;
strncpy((char*)format.user_data, "vorb", 4);
format.u.encoded_audio.frame_size = sizeof(ogg_packet);
init_vorbis_media_raw_audio_format(&format.u.encoded_audio.output);
format.u.encoded_audio.output.byte_order = B_MEDIA_HOST_ENDIAN;
format.u.encoded_audio.output.format = media_raw_audio_format::B_AUDIO_FLOAT;
return format;
}

View File

@ -18,20 +18,10 @@
#define DECODE_BUFFER_SIZE (32 * 1024)
inline size_t
AudioBufferSize(media_raw_audio_format * raf, bigtime_t buffer_duration = 50000 /* 50 ms */)
AudioBufferSize(const 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);
}
static media_format
vorbis_decoded_media_format()
{
media_format format;
format.type = B_MEDIA_RAW_AUDIO;
init_vorbis_media_raw_audio_format(&format.u.raw_audio);
return format;
return (raf.format & 0xf) * (raf.channel_count)
* (size_t)((raf.frame_rate * buffer_duration) / 1000000.0);
}
@ -103,10 +93,8 @@ VorbisDecoder::Setup(media_format *inputFormat,
// initialize decoder
vorbis_synthesis_init(&fDspState,&fInfo);
vorbis_block_init(&fDspState,&fBlock);
// setup default output
media_format requested_format = vorbis_decoded_media_format();
((media_raw_audio_format)requested_format.u.raw_audio) = inputFormat->u.encoded_audio.output;
return NegotiateOutputFormat(&requested_format);
return B_OK;
}
@ -127,21 +115,24 @@ VorbisDecoder::NegotiateOutputFormat(media_format *ioDecodedFormat)
//
// Be R5 behavior seems to be that we can never fail. If we
// don't support the requested format, just return one we do.
media_format format = vorbis_decoded_media_format();
format.u.raw_audio.frame_rate = (float)fInfo.rate;
format.u.raw_audio.channel_count = fInfo.channels;
format.u.raw_audio.channel_mask = B_CHANNEL_LEFT | (fInfo.channels != 1 ? B_CHANNEL_RIGHT : 0);
if (ioDecodedFormat->u.raw_audio.buffer_size < 512) {
format.u.raw_audio.buffer_size = AudioBufferSize(&format.u.raw_audio);
}
if (!format_is_compatible(format,*ioDecodedFormat)) {
*ioDecodedFormat = format;
}
ioDecodedFormat->SpecializeTo(&format);
ioDecodedFormat->type = B_MEDIA_RAW_AUDIO;
ioDecodedFormat->u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT;
ioDecodedFormat->u.raw_audio.byte_order = B_MEDIA_HOST_ENDIAN;
ioDecodedFormat->u.raw_audio.frame_rate = (float)fInfo.rate;
ioDecodedFormat->u.raw_audio.channel_count = fInfo.channels;
if (ioDecodedFormat->u.raw_audio.channel_mask == 0)
ioDecodedFormat->u.raw_audio.channel_mask = (fInfo.channels == 1) ? B_CHANNEL_LEFT : (B_CHANNEL_LEFT | B_CHANNEL_RIGHT);
int frame_size = (ioDecodedFormat->u.raw_audio.format & 0xf) * ioDecodedFormat->u.raw_audio.channel_count;
if (ioDecodedFormat->u.raw_audio.buffer_size == 0 || (ioDecodedFormat->u.raw_audio.buffer_size % frame_size) != 0)
ioDecodedFormat->u.raw_audio.buffer_size = AudioBufferSize(ioDecodedFormat->u.raw_audio);
// setup output variables
fFrameSize = (ioDecodedFormat->u.raw_audio.format & 0xf) *
(ioDecodedFormat->u.raw_audio.channel_count);
fOutputBufferSize = ioDecodedFormat->u.raw_audio.buffer_size;
return B_OK;
}