diff options
author | Robin Gareus <robin@gareus.org> | 2019-12-06 21:53:03 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2019-12-06 21:53:03 +0100 |
commit | 9aa887fa65590d235273cc3e8e440f091b9f0d07 (patch) | |
tree | 928b93528474c4d6c67f6ca57027c5ca60dc75fc /libs/ardour/mp3fileimportable.cc | |
parent | 0700cb81656cc7b0cc0f39e81eb1f5456e3c146c (diff) |
Fix issues with VBR mp3s, detect duration by decoding
Diffstat (limited to 'libs/ardour/mp3fileimportable.cc')
-rw-r--r-- | libs/ardour/mp3fileimportable.cc | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/libs/ardour/mp3fileimportable.cc b/libs/ardour/mp3fileimportable.cc index 200f5f622a..202ad8493c 100644 --- a/libs/ardour/mp3fileimportable.cc +++ b/libs/ardour/mp3fileimportable.cc @@ -93,7 +93,17 @@ Mp3FileImportableSource::Mp3FileImportableSource (const string& path) throw failed_constructor (); } + /* estimate length, fixed bitrate */ _length = _n_frames * _map_length / _info.frame_bytes; + +#if 1 /* detect accurate length by parsing frame headers */ + _length = _n_frames; + while (decode_mp3 (true)) { + _length += _n_frames; + } + _read_position = _length; + seek (0); +#endif } Mp3FileImportableSource::~Mp3FileImportableSource () @@ -116,11 +126,11 @@ Mp3FileImportableSource::unmap_mem () } int -Mp3FileImportableSource::decode_mp3 () +Mp3FileImportableSource::decode_mp3 (bool parse_only) { _pcm_off = 0; do { - _n_frames = mp3dec_decode_frame (&_mp3d, _buffer, _remain, _pcm, &_info); + _n_frames = mp3dec_decode_frame (&_mp3d, _buffer, _remain, parse_only ? NULL :_pcm, &_info); _buffer += _info.frame_bytes; _remain -= _info.frame_bytes; if (_n_frames) { @@ -154,7 +164,7 @@ Mp3FileImportableSource::seek (samplepos_t pos) _read_position += _n_frames; } - if (_n_frames >= 0) { + if (_n_frames > 0) { _pcm_off = _info.channels * (pos - _read_position); _n_frames -= pos - _read_position; _read_position = pos; |