annotate data/fileio/MP3FileReader.h @ 297:c022976d18e8

* Merge from sv-match-alignment branch (excluding alignment-specific document). - add aggregate wave model (not yet complete enough to be added as a true model in a layer, but there's potential) - add play solo mode - add alignment model -- unused in plain SV - fix two plugin leaks - add m3u playlist support (opens all files at once, potentially hazardous) - fix retrieval of pre-encoded URLs - add ability to resample audio files on import, so as to match rates with other files previously loaded; add preference for same - add preliminary support in transform code for range and rate of transform input - reorganise preferences dialog, move dark-background option to preferences, add option for temporary directory location
author Chris Cannam
date Fri, 28 Sep 2007 13:56:38 +0000
parents 92e8dbde73cd
children 3a6725f285d6
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@148 28 class QProgressDialog;
Chris@148 29
Chris@148 30 class MP3FileReader : public CodedAudioFileReader
Chris@148 31 {
Chris@148 32 public:
Chris@263 33 enum DecodeMode {
Chris@263 34 DecodeAtOnce, // decode the file on construction, with progress dialog
Chris@263 35 DecodeThreaded // decode in a background thread after construction
Chris@263 36 };
Chris@263 37
Chris@297 38 MP3FileReader(QString path,
Chris@297 39 DecodeMode decodeMode,
Chris@297 40 CacheMode cacheMode,
Chris@297 41 size_t targetRate = 0);
Chris@148 42 virtual ~MP3FileReader();
Chris@148 43
Chris@290 44 virtual QString getError() const { return m_error; }
Chris@290 45
Chris@290 46 virtual QString getTitle() const { return m_title; }
Chris@271 47
Chris@290 48 static void getSupportedExtensions(std::set<QString> &extensions);
Chris@148 49
Chris@265 50 virtual int getDecodeCompletion() const { return m_completion; }
Chris@265 51
Chris@263 52 virtual bool isUpdating() const {
Chris@263 53 return m_decodeThread && m_decodeThread->isRunning();
Chris@263 54 }
Chris@263 55
Chris@148 56 protected:
Chris@290 57 QString m_path;
Chris@290 58 QString m_error;
Chris@290 59 QString m_title;
Chris@148 60 size_t m_fileSize;
Chris@148 61 double m_bitrateNum;
Chris@148 62 size_t m_bitrateDenom;
Chris@265 63 int m_completion;
Chris@263 64 bool m_done;
Chris@263 65
Chris@263 66 unsigned char *m_filebuffer;
Chris@297 67 float **m_samplebuffer;
Chris@297 68 size_t m_samplebuffersize;
Chris@148 69
Chris@148 70 QProgressDialog *m_progress;
Chris@148 71 bool m_cancelled;
Chris@148 72
Chris@148 73 struct DecoderData
Chris@148 74 {
Chris@148 75 unsigned char const *start;
Chris@148 76 unsigned long length;
Chris@148 77 MP3FileReader *reader;
Chris@148 78 };
Chris@148 79
Chris@148 80 bool decode(void *mm, size_t sz);
Chris@148 81 enum mad_flow accept(struct mad_header const *, struct mad_pcm *);
Chris@148 82
Chris@148 83 static enum mad_flow input(void *, struct mad_stream *);
Chris@148 84 static enum mad_flow output(void *, struct mad_header const *, struct mad_pcm *);
Chris@148 85 static enum mad_flow error(void *, struct mad_stream *, struct mad_frame *);
Chris@263 86
Chris@263 87 class DecodeThread : public Thread
Chris@263 88 {
Chris@263 89 public:
Chris@263 90 DecodeThread(MP3FileReader *reader) : m_reader(reader) { }
Chris@263 91 virtual void run();
Chris@263 92
Chris@263 93 protected:
Chris@263 94 MP3FileReader *m_reader;
Chris@263 95 };
Chris@263 96
Chris@263 97 DecodeThread *m_decodeThread;
Chris@271 98
Chris@271 99 void loadTags();
Chris@148 100 };
Chris@148 101
Chris@148 102 #endif
Chris@148 103
Chris@148 104 #endif