comparison data/fileio/MP3FileReader.h @ 1365:3382d914e110

Merge from branch 3.0-integration
author Chris Cannam
date Fri, 13 Jan 2017 10:29:44 +0000
parents b3cb0edc25cd
children 48e9f538e6e9
comparison
equal deleted inserted replaced
1272:6a7ea3bd0e10 1365:3382d914e110
30 class MP3FileReader : public CodedAudioFileReader 30 class MP3FileReader : public CodedAudioFileReader
31 { 31 {
32 Q_OBJECT 32 Q_OBJECT
33 33
34 public: 34 public:
35 enum DecodeMode { 35 /**
36 DecodeAtOnce, // decode the file on construction, with progress 36 * How the MP3FileReader should handle leading and trailing gaps.
37 DecodeThreaded // decode in a background thread after construction 37 * See http://lame.sourceforge.net/tech-FAQ.txt for a technical
38 * explanation of the numbers here.
39 */
40 enum class GaplessMode {
41 /**
42 * Trim unwanted samples from the start and end of the decoded
43 * audio. From the start, trim a number of samples equal to
44 * the decoder delay (a fixed 529 samples) plus any encoder
45 * delay that may be specified in Xing/LAME metadata. From the
46 * end, trim any padding specified in Xing/LAME metadata, less
47 * the fixed decoder delay. This usually results in "gapless"
48 * audio, i.e. with no spurious zero padding at either end.
49 */
50 Gapless,
51
52 /**
53 * Do not trim any samples. Also do not suppress any frames
54 * from being passed to the mp3 decoder, even Xing/LAME
55 * metadata frames. This will result in the audio being padded
56 * with zeros at either end: at the start, typically
57 * 529+576+1152 = 2257 samples for LAME-encoded mp3s; at the
58 * end an unknown number depending on the fill ratio of the
59 * final coded frame, but typically less than 1152-529 = 623.
60 *
61 * This mode produces the same output as produced by older
62 * versions of this code before the gapless option was added,
63 * and is present mostly for backward compatibility.
64 */
65 Gappy
38 }; 66 };
39 67
40 MP3FileReader(FileSource source, 68 MP3FileReader(FileSource source,
41 DecodeMode decodeMode, 69 DecodeMode decodeMode,
42 CacheMode cacheMode, 70 CacheMode cacheMode,
71 GaplessMode gaplessMode,
43 sv_samplerate_t targetRate = 0, 72 sv_samplerate_t targetRate = 0,
44 bool normalised = false, 73 bool normalised = false,
45 ProgressReporter *reporter = 0); 74 ProgressReporter *reporter = 0);
46 virtual ~MP3FileReader(); 75 virtual ~MP3FileReader();
47 76
71 QString m_path; 100 QString m_path;
72 QString m_error; 101 QString m_error;
73 QString m_title; 102 QString m_title;
74 QString m_maker; 103 QString m_maker;
75 TagMap m_tags; 104 TagMap m_tags;
105 GaplessMode m_gaplessMode;
76 sv_frame_t m_fileSize; 106 sv_frame_t m_fileSize;
77 double m_bitrateNum; 107 double m_bitrateNum;
78 int m_bitrateDenom; 108 int m_bitrateDenom;
109 int m_mp3FrameCount;
79 int m_completion; 110 int m_completion;
80 bool m_done; 111 bool m_done;
81 112
82 unsigned char *m_filebuffer; 113 unsigned char *m_fileBuffer;
83 float **m_samplebuffer; 114 size_t m_fileBufferSize;
84 int m_samplebuffersize; 115
116 float **m_sampleBuffer;
117 size_t m_sampleBufferSize;
85 118
86 ProgressReporter *m_reporter; 119 ProgressReporter *m_reporter;
87 bool m_cancelled; 120 bool m_cancelled;
88 121
89 struct DecoderData 122 bool m_decodeErrorShown;
90 { 123
124 struct DecoderData {
91 unsigned char const *start; 125 unsigned char const *start;
92 unsigned long length; 126 sv_frame_t length;
127 bool finished;
93 MP3FileReader *reader; 128 MP3FileReader *reader;
94 }; 129 };
95 130
96 bool decode(void *mm, sv_frame_t sz); 131 bool decode(void *mm, sv_frame_t sz);
132 enum mad_flow filter(struct mad_stream const *, struct mad_frame *);
97 enum mad_flow accept(struct mad_header const *, struct mad_pcm *); 133 enum mad_flow accept(struct mad_header const *, struct mad_pcm *);
98 134
99 static enum mad_flow input(void *, struct mad_stream *); 135 static enum mad_flow input_callback(void *, struct mad_stream *);
100 static enum mad_flow output(void *, struct mad_header const *, struct mad_pcm *); 136 static enum mad_flow output_callback(void *, struct mad_header const *,
101 static enum mad_flow error(void *, struct mad_stream *, struct mad_frame *); 137 struct mad_pcm *);
138 static enum mad_flow filter_callback(void *, struct mad_stream const *,
139 struct mad_frame *);
140 static enum mad_flow error_callback(void *, struct mad_stream *,
141 struct mad_frame *);
102 142
103 class DecodeThread : public Thread 143 class DecodeThread : public Thread
104 { 144 {
105 public: 145 public:
106 DecodeThread(MP3FileReader *reader) : m_reader(reader) { } 146 DecodeThread(MP3FileReader *reader) : m_reader(reader) { }
110 MP3FileReader *m_reader; 150 MP3FileReader *m_reader;
111 }; 151 };
112 152
113 DecodeThread *m_decodeThread; 153 DecodeThread *m_decodeThread;
114 154
115 void loadTags(); 155 void loadTags(int fd);
116 QString loadTag(void *vtag, const char *name); 156 QString loadTag(void *vtag, const char *name);
117 }; 157 };
118 158
119 #endif 159 #endif
120 160