svcore  1.9
MP3FileReader.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef _MP3_FILE_READER_H_
17 #define _MP3_FILE_READER_H_
18 
19 #ifdef HAVE_MAD
20 
21 #include "CodedAudioFileReader.h"
22 
23 #include "base/Thread.h"
24 #include <mad.h>
25 
26 #include <set>
27 
28 class ProgressReporter;
29 
31 {
32  Q_OBJECT
33 
34 public:
35  enum DecodeMode {
36  DecodeAtOnce, // decode the file on construction, with progress
37  DecodeThreaded // decode in a background thread after construction
38  };
39 
41  DecodeMode decodeMode,
42  CacheMode cacheMode,
43  int targetRate = 0,
44  bool normalised = false,
45  ProgressReporter *reporter = 0);
46  virtual ~MP3FileReader();
47 
48  virtual QString getError() const { return m_error; }
49 
50  virtual QString getLocation() const { return m_source.getLocation(); }
51  virtual QString getTitle() const { return m_title; }
52  virtual QString getMaker() const { return m_maker; }
53  virtual TagMap getTags() const { return m_tags; }
54 
55  static void getSupportedExtensions(std::set<QString> &extensions);
56  static bool supportsExtension(QString ext);
57  static bool supportsContentType(QString type);
58  static bool supports(FileSource &source);
59 
60  virtual int getDecodeCompletion() const { return m_completion; }
61 
62  virtual bool isUpdating() const {
63  return m_decodeThread && m_decodeThread->isRunning();
64  }
65 
66 public slots:
67  void cancelled();
68 
69 protected:
71  QString m_path;
72  QString m_error;
73  QString m_title;
74  QString m_maker;
77  double m_bitrateNum;
80  bool m_done;
81 
82  unsigned char *m_filebuffer;
83  float **m_samplebuffer;
85 
88 
89  struct DecoderData
90  {
91  unsigned char const *start;
92  unsigned long length;
94  };
95 
96  bool decode(void *mm, int sz);
97  enum mad_flow accept(struct mad_header const *, struct mad_pcm *);
98 
99  static enum mad_flow input(void *, struct mad_stream *);
100  static enum mad_flow output(void *, struct mad_header const *, struct mad_pcm *);
101  static enum mad_flow error(void *, struct mad_stream *, struct mad_frame *);
102 
103  class DecodeThread : public Thread
104  {
105  public:
106  DecodeThread(MP3FileReader *reader) : m_reader(reader) { }
107  virtual void run();
108 
109  protected:
111  };
112 
114 
115  void loadTags();
116  QString loadTag(void *vtag, const char *name);
117 };
118 
119 #endif
120 
121 #endif
unsigned char const * start
Definition: MP3FileReader.h:91
virtual bool isUpdating() const
Definition: MP3FileReader.h:62
QString loadTag(void *vtag, const char *name)
static void getSupportedExtensions(std::set< QString > &extensions)
QString getLocation() const
Return the location filename or URL as passed to the constructor.
Definition: FileSource.cpp:595
static enum mad_flow input(void *, struct mad_stream *)
DecodeThread * m_decodeThread
enum mad_flow accept(struct mad_header const *, struct mad_pcm *)
static enum mad_flow output(void *, struct mad_header const *, struct mad_pcm *)
FileSource m_source
Definition: MP3FileReader.h:70
virtual QString getMaker() const
Return the "maker" of the work in the audio file, if known.
Definition: MP3FileReader.h:52
QString m_error
Definition: MP3FileReader.h:72
QString m_maker
Definition: MP3FileReader.h:74
virtual TagMap getTags() const
Definition: MP3FileReader.h:53
unsigned char * m_filebuffer
Definition: MP3FileReader.h:82
float ** m_samplebuffer
Definition: MP3FileReader.h:83
MP3FileReader(FileSource source, DecodeMode decodeMode, CacheMode cacheMode, int targetRate=0, bool normalised=false, ProgressReporter *reporter=0)
std::map< QString, QString > TagMap
int m_samplebuffersize
Definition: MP3FileReader.h:84
QString m_path
Definition: MP3FileReader.h:71
FileSource is a class used to refer to the contents of a file that may be either local or at a remote...
Definition: FileSource.h:59
virtual QString getError() const
Definition: MP3FileReader.h:48
double m_bitrateNum
Definition: MP3FileReader.h:77
bool decode(void *mm, int sz)
virtual QString getTitle() const
Return the title of the work in the audio file, if known.
Definition: MP3FileReader.h:51
static bool supports(FileSource &source)
virtual int getDecodeCompletion() const
Definition: MP3FileReader.h:60
Definition: Thread.h:24
virtual QString getLocation() const
Return the location of the audio data in the reader (as passed in to the FileSource constructor,...
Definition: MP3FileReader.h:50
ProgressReporter * m_reporter
Definition: MP3FileReader.h:86
static enum mad_flow error(void *, struct mad_stream *, struct mad_frame *)
QString m_title
Definition: MP3FileReader.h:73
DecodeThread(MP3FileReader *reader)
static bool supportsExtension(QString ext)
virtual ~MP3FileReader()
static bool supportsContentType(QString type)