/thirdparty/liblastfm2/src/fingerprint/contrib/MadSource.h

http://github.com/tomahawk-player/tomahawk · C Header · 69 lines · 37 code · 13 blank · 19 comment · 0 complexity · b8068e4f1515e1d902640c45bb30c0d5 MD5 · raw file

  1. /*
  2. Copyright 2009 Last.fm Ltd.
  3. Copyright 2009 John Stamp <jstamp@users.sourceforge.net>
  4. This file is part of liblastfm.
  5. liblastfm is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. liblastfm is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with liblastfm. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __MP3_SOURCE_H__
  17. #define __MP3_SOURCE_H__
  18. #include <lastfm/FingerprintableSource>
  19. #include <QFile>
  20. #include <string>
  21. #include <vector>
  22. #include <fstream>
  23. #include <mad.h>
  24. class MadSource : public lastfm::FingerprintableSource
  25. {
  26. public:
  27. MadSource();
  28. ~MadSource();
  29. virtual void getInfo(int& lengthSecs, int& samplerate, int& bitrate, int& nchannels);
  30. virtual void init(const QString& fileName);
  31. virtual int updateBuffer(signed short* pBuffer, size_t bufferSize);
  32. virtual void skip(const int mSecs);
  33. virtual void skipSilence(double silenceThreshold = 0.0001);
  34. virtual bool eof() const { return m_inputFile.atEnd(); }
  35. private:
  36. static bool fetchData( QFile& mp3File,
  37. unsigned char* pMP3_Buffer,
  38. const int MP3_BufferSize,
  39. mad_stream& madStream );
  40. static bool isRecoverable(const mad_error& error, bool log = false);
  41. static std::string MadErrorString(const mad_error& error);
  42. struct mad_stream m_mad_stream;
  43. struct mad_frame m_mad_frame;
  44. mad_timer_t m_mad_timer;
  45. struct mad_synth m_mad_synth;
  46. QFile m_inputFile;
  47. unsigned char* m_pMP3_Buffer;
  48. static const int m_MP3_BufferSize = (5*8192);
  49. QString m_fileName;
  50. size_t m_pcmpos;
  51. };
  52. #endif