File indexing completed on 2024-05-12 04:51:32

0001 /*
0002     SPDX-FileCopyrightText: 1998-2007 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef _K3B_MAD_H_
0007 #define _K3B_MAD_H_
0008 
0009 extern "C" {
0010 #include <mad.h>
0011 }
0012 
0013 #include <QFile>
0014 
0015 
0016 class K3bMad
0017 {
0018 public:
0019   K3bMad();
0020   ~K3bMad();
0021 
0022   bool open( const QString& filename );
0023 
0024   /**
0025    * @return true if the mad stream contains data
0026    *         false if there is no data left or an error occurred.
0027    *         In the latter case inputError() returns true.
0028    */
0029   bool fillStreamBuffer();
0030 
0031   /**
0032    * Skip id3 tags.
0033    *
0034    * This will reset the input file.
0035    */
0036   bool skipTag();
0037 
0038   /**
0039    * Find first frame and seek to the beginning of that frame.
0040    * This is used to skip the junk that many mp3 files start with.
0041    */
0042   bool seekFirstHeader();
0043 
0044   bool eof() const;
0045   bool inputError() const;
0046 
0047   /**
0048    * Current position in theinput file. This does NOT
0049    * care about the status of the mad stream. Use streamPos()
0050    * in that case.
0051    */
0052   qint64 inputPos() const;
0053 
0054   /**
0055    * Current absolute position of the decoder stream.
0056    */
0057   qint64 streamPos() const;
0058   bool inputSeek( qint64 pos );
0059 
0060   void initMad();
0061   void cleanup();
0062 
0063   bool decodeNextFrame();
0064   bool findNextHeader();
0065   bool checkFrameHeader( mad_header* header ) const;
0066 
0067   mad_stream*   madStream;
0068   mad_frame*    madFrame;
0069   mad_synth*    madSynth;
0070   mad_timer_t*  madTimer;
0071 
0072 private:
0073   QFile m_inputFile;
0074   bool m_madStructuresInitialized;
0075   unsigned char* m_inputBuffer;
0076   bool m_bInputError;
0077 
0078   int m_channels;
0079   int m_sampleRate;
0080 };
0081 
0082 #endif