Mixxx
|
00001 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef SOUNDSOURCEFLAC_H 00019 #define SOUNDSOURCEFLAC_H 00020 00021 #include <QFile> 00022 #include <QString> 00023 #include <FLAC/stream_decoder.h> 00024 00025 #include "defs.h" 00026 #include "soundsource.h" 00027 00028 class SoundSourceFLAC : public Mixxx::SoundSource { 00029 public: 00030 SoundSourceFLAC(QString filename); 00031 ~SoundSourceFLAC(); 00032 int open(); 00033 long seek(long filepos); 00034 unsigned read(unsigned long size, const SAMPLE *buffer); 00035 inline long unsigned length(); 00036 int parseHeader(); 00037 static QList<QString> supportedFileExtensions(); 00038 // callback methods 00039 FLAC__StreamDecoderReadStatus flacRead(FLAC__byte buffer[], size_t *bytes); 00040 FLAC__StreamDecoderSeekStatus flacSeek(FLAC__uint64 offset); 00041 FLAC__StreamDecoderTellStatus flacTell(FLAC__uint64 *offset); 00042 FLAC__StreamDecoderLengthStatus flacLength(FLAC__uint64 *length); 00043 FLAC__bool flacEOF(); 00044 FLAC__StreamDecoderWriteStatus flacWrite(const FLAC__Frame *frame, const FLAC__int32 *const buffer[]); 00045 void flacMetadata(const FLAC__StreamMetadata *metadata); 00046 void flacError(FLAC__StreamDecoderErrorStatus status); 00047 private: 00048 // these next two are inline but are defined in the cpp file because 00049 // they should only be used there -- bkgood 00050 inline int getShift() const; 00051 inline FLAC__int16 shift(const FLAC__int32 sample) const; 00052 QFile m_file; 00053 FLAC__StreamDecoder *m_decoder; 00054 FLAC__StreamMetadata_StreamInfo *m_streamInfo; 00055 unsigned int m_samples; // total number of samples 00056 unsigned int m_bps; // bits per sample 00057 // misc bits about the flac format: 00058 // flac encodes from and decodes to LPCM in blocks, each block is made up of 00059 // subblocks (one for each chan) 00060 // flac stores in 'frames', each of which has a header and a certain number 00061 // of subframes (one for each channel) 00062 unsigned int m_minBlocksize; // in time samples (audio samples = time samples * chanCount) 00063 unsigned int m_maxBlocksize; 00064 unsigned int m_minFramesize; 00065 unsigned int m_maxFramesize; 00066 FLAC__int16 *m_flacBuffer; // buffer for the write callback to write a single frame's samples 00067 unsigned int m_flacBufferLength; 00068 FLAC__int16 *m_leftoverBuffer; // buffer to place any samples which haven't been used 00069 // at the end of a read call 00070 unsigned int m_leftoverBufferLength; 00071 }; 00072 00073 // callbacks for libFLAC 00074 FLAC__StreamDecoderReadStatus FLAC_read_cb(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data); 00075 FLAC__StreamDecoderSeekStatus FLAC_seek_cb(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data); 00076 FLAC__StreamDecoderTellStatus FLAC_tell_cb(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data); 00077 FLAC__StreamDecoderLengthStatus FLAC_length_cb(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data); 00078 FLAC__bool FLAC_eof_cb(const FLAC__StreamDecoder *decoder, void *client_data); 00079 FLAC__StreamDecoderWriteStatus FLAC_write_cb(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 *const buffer[], void *client_data); 00080 void FLAC_metadata_cb(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); 00081 void FLAC_error_cb(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); 00082 00083 #endif // ifndef SOUNDSOURCEFLAC_H