CodedAudioFileReader.h

Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Chris Cannam.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef _CODED_AUDIO_FILE_READER_H_
00017 #define _CODED_AUDIO_FILE_READER_H_
00018 
00019 #include "AudioFileReader.h"
00020 
00021 #include <sndfile.h>
00022 #include <QMutex>
00023 
00024 class WavFileReader;
00025 class Serialiser;
00026 class Resampler;
00027 
00028 class CodedAudioFileReader : public AudioFileReader
00029 {
00030     Q_OBJECT
00031 
00032 public:
00033     virtual ~CodedAudioFileReader();
00034 
00035     enum CacheMode {
00036         CacheInTemporaryFile,
00037         CacheInMemory
00038     };
00039 
00040     virtual void getInterleavedFrames(size_t start, size_t count,
00041                                       SampleBlock &frames) const;
00042 
00043     virtual size_t getNativeRate() const { return m_fileRate; }
00044 
00045 signals:
00046     void progress(int);
00047 
00048 protected:
00049     CodedAudioFileReader(CacheMode cacheMode, size_t targetRate);
00050 
00051     void initialiseDecodeCache(); // samplerate, channels must have been set
00052     void addSamplesToDecodeCache(float **samples, size_t nframes);
00053     void addSamplesToDecodeCache(float *samplesInterleaved, size_t nframes);
00054     void addSamplesToDecodeCache(const SampleBlock &interleaved);
00055     void finishDecodeCache();
00056     bool isDecodeCacheInitialised() const { return m_initialised; }
00057 
00058     void startSerialised(QString id);
00059     void endSerialised();
00060 
00061 private:
00062     void pushBuffer(float *interleaved, size_t sz, bool final);
00063 
00064 protected:
00065     QMutex m_cacheMutex;
00066     CacheMode m_cacheMode;
00067     SampleBlock m_data;
00068     bool m_initialised;
00069     Serialiser *m_serialiser;
00070     size_t m_fileRate;
00071 
00072     QString m_cacheFileName;
00073     SNDFILE *m_cacheFileWritePtr;
00074     WavFileReader *m_cacheFileReader;
00075     float *m_cacheWriteBuffer;
00076     size_t m_cacheWriteBufferIndex;
00077     size_t m_cacheWriteBufferSize; // frames
00078 
00079     Resampler *m_resampler;
00080     float *m_resampleBuffer;
00081 };
00082 
00083 #endif

Generated on Wed Feb 20 15:45:25 2008 for SonicVisualiser by  doxygen 1.5.1