diff options
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/ardour/mp3fileimportable.h | 2 | ||||
-rw-r--r-- | libs/ardour/mp3fileimportable.cc | 16 |
2 files changed, 14 insertions, 4 deletions
diff --git a/libs/ardour/ardour/mp3fileimportable.h b/libs/ardour/ardour/mp3fileimportable.h index e209b7bf7d..f4b37cf070 100644 --- a/libs/ardour/ardour/mp3fileimportable.h +++ b/libs/ardour/ardour/mp3fileimportable.h @@ -58,7 +58,7 @@ public: private: void unmap_mem (); - int decode_mp3 (); + int decode_mp3 (bool parse_only = false); mp3dec_t _mp3d; mp3dec_frame_info_t _info; 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; |