decoder/opus: Implement bitrate calculation

This commit is contained in:
Tim Sweet 2022-03-11 18:24:16 -06:00 committed by Max Kellermann
parent 407fa2720a
commit 3a3f605a56
2 changed files with 10 additions and 1 deletions

2
NEWS
View File

@ -4,6 +4,8 @@ ver 0.24 (not yet released)
- filter "prio" (for "playlistfind"/"playlistsearch")
* archive
- add option to disable archive plugins in mpd.conf
* decoder
- opus: implement bitrate calculation
* player
- add option "mixramp_analyzer" to scan MixRamp tags on-the-fly
* tags

View File

@ -327,6 +327,13 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet)
return;
}
/* Formula for calculation of bitrate of the current opus packet:
bits_sent_into_decoder = packet.bytes * 8
1/seconds_decoded = opus_sample_rate / nframes
kbits = bits_sent_into_decoder * 1/seconds_decoded / 1000
*/
uint16_t kbits = (unsigned int)packet.bytes*8 * opus_sample_rate / nframes / 1000;
/* apply the "skip" value */
if (skip >= (unsigned)nframes) {
skip -= nframes;
@ -361,7 +368,7 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet)
const size_t nbytes = nframes * frame_size;
auto cmd = client.SubmitData(input_stream,
data, nbytes,
0);
kbits);
if (cmd != DecoderCommand::NONE)
throw cmd;