annotate data/fileio/MP3FileReader.h @ 1288:5ef9b4d4bbdb 3.0-integration

Filter out Xing/LAME info frames, rather than letting them go to the mp3 decoder as if they were audio frames. Fixes the 1152-sample zero pad at start of some decoded mp3 files (distinct from decoder delay). The logic here is based on the madplay code.
author Chris Cannam
date Thu, 24 Nov 2016 13:32:04 +0000
parents 16a8e97179d7
children fa574c909c3d
rev   line source
Chris@148 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@148 2
Chris@148 3 /*
Chris@148 4 Sonic Visualiser
Chris@148 5 An audio file viewer and annotation editor.
Chris@148 6 Centre for Digital Music, Queen Mary, University of London.
Chris@148 7 This file copyright 2006 Chris Cannam.
Chris@148 8
Chris@148 9 This program is free software; you can redistribute it and/or
Chris@148 10 modify it under the terms of the GNU General Public License as
Chris@148 11 published by the Free Software Foundation; either version 2 of the
Chris@148 12 License, or (at your option) any later version. See the file
Chris@148 13 COPYING included with this distribution for more information.
Chris@148 14 */
Chris@148 15
Chris@148 16 #ifndef _MP3_FILE_READER_H_
Chris@148 17 #define _MP3_FILE_READER_H_
Chris@148 18
Chris@148 19 #ifdef HAVE_MAD
Chris@148 20
Chris@148 21 #include "CodedAudioFileReader.h"
Chris@148 22
Chris@263 23 #include "base/Thread.h"
Chris@148 24 #include <mad.h>
Chris@148 25
Chris@157 26 #include <set>
Chris@157 27
Chris@392 28 class ProgressReporter;
Chris@148 29
Chris@148 30 class MP3FileReader : public CodedAudioFileReader
Chris@148 31 {
Chris@392 32 Q_OBJECT
Chris@392 33
Chris@148 34 public:
Chris@317 35 MP3FileReader(FileSource source,
Chris@297 36 DecodeMode decodeMode,
Chris@297 37 CacheMode cacheMode,
Chris@1040 38 sv_samplerate_t targetRate = 0,
Chris@920 39 bool normalised = false,
Chris@392 40 ProgressReporter *reporter = 0);
Chris@148 41 virtual ~MP3FileReader();
Chris@148 42
Chris@290 43 virtual QString getError() const { return m_error; }
Chris@290 44
Chris@345 45 virtual QString getLocation() const { return m_source.getLocation(); }
Chris@290 46 virtual QString getTitle() const { return m_title; }
Chris@334 47 virtual QString getMaker() const { return m_maker; }
Chris@632 48 virtual TagMap getTags() const { return m_tags; }
Chris@271 49
Chris@290 50 static void getSupportedExtensions(std::set<QString> &extensions);
Chris@316 51 static bool supportsExtension(QString ext);
Chris@316 52 static bool supportsContentType(QString type);
Chris@317 53 static bool supports(FileSource &source);
Chris@316 54
Chris@265 55 virtual int getDecodeCompletion() const { return m_completion; }
Chris@265 56
Chris@263 57 virtual bool isUpdating() const {
Chris@263 58 return m_decodeThread && m_decodeThread->isRunning();
Chris@263 59 }
Chris@263 60
Chris@392 61 public slots:
Chris@392 62 void cancelled();
Chris@392 63
Chris@148 64 protected:
Chris@317 65 FileSource m_source;
Chris@290 66 QString m_path;
Chris@290 67 QString m_error;
Chris@290 68 QString m_title;
Chris@333 69 QString m_maker;
Chris@632 70 TagMap m_tags;
Chris@1038 71 sv_frame_t m_fileSize;
Chris@148 72 double m_bitrateNum;
Chris@929 73 int m_bitrateDenom;
Chris@1288 74 int m_mp3FrameCount;
Chris@265 75 int m_completion;
Chris@263 76 bool m_done;
Chris@263 77
Chris@263 78 unsigned char *m_filebuffer;
Chris@297 79 float **m_samplebuffer;
Chris@929 80 int m_samplebuffersize;
Chris@148 81
Chris@392 82 ProgressReporter *m_reporter;
Chris@148 83 bool m_cancelled;
Chris@148 84
Chris@1284 85 bool m_decodeErrorShown;
Chris@1284 86
Chris@148 87 struct DecoderData
Chris@148 88 {
Chris@148 89 unsigned char const *start;
Chris@1288 90 sv_frame_t length;
Chris@148 91 MP3FileReader *reader;
Chris@148 92 };
Chris@148 93
Chris@1038 94 bool decode(void *mm, sv_frame_t sz);
Chris@1288 95 enum mad_flow filter(struct mad_stream const *, struct mad_frame *);
Chris@148 96 enum mad_flow accept(struct mad_header const *, struct mad_pcm *);
Chris@148 97
Chris@1288 98 static enum mad_flow input_callback(void *, struct mad_stream *);
Chris@1288 99 static enum mad_flow output_callback(void *, struct mad_header const *,
Chris@1288 100 struct mad_pcm *);
Chris@1288 101 static enum mad_flow filter_callback(void *, struct mad_stream const *,
Chris@1288 102 struct mad_frame *);
Chris@1288 103 static enum mad_flow error_callback(void *, struct mad_stream *,
Chris@1288 104 struct mad_frame *);
Chris@263 105
Chris@263 106 class DecodeThread : public Thread
Chris@263 107 {
Chris@263 108 public:
Chris@263 109 DecodeThread(MP3FileReader *reader) : m_reader(reader) { }
Chris@263 110 virtual void run();
Chris@263 111
Chris@263 112 protected:
Chris@263 113 MP3FileReader *m_reader;
Chris@263 114 };
Chris@263 115
Chris@263 116 DecodeThread *m_decodeThread;
Chris@271 117
Chris@271 118 void loadTags();
Chris@333 119 QString loadTag(void *vtag, const char *name);
Chris@148 120 };
Chris@148 121
Chris@148 122 #endif
Chris@148 123
Chris@148 124 #endif