annotate data/fileio/CodedAudioFileReader.h @ 311:1c9143b2b658

...
author Chris Cannam
date Wed, 10 Oct 2007 15:32:16 +0000
parents c022976d18e8
children b92513201610
rev   line source
Chris@148 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@148 2
Chris@148 3 /*
Chris@148 4 Sonic Visualiser
Chris@148 5 An audio file viewer and annotation editor.
Chris@148 6 Centre for Digital Music, Queen Mary, University of London.
Chris@148 7 This file copyright 2006 Chris Cannam.
Chris@148 8
Chris@148 9 This program is free software; you can redistribute it and/or
Chris@148 10 modify it under the terms of the GNU General Public License as
Chris@148 11 published by the Free Software Foundation; either version 2 of the
Chris@148 12 License, or (at your option) any later version. See the file
Chris@148 13 COPYING included with this distribution for more information.
Chris@148 14 */
Chris@148 15
Chris@148 16 #ifndef _CODED_AUDIO_FILE_READER_H_
Chris@148 17 #define _CODED_AUDIO_FILE_READER_H_
Chris@148 18
Chris@148 19 #include "AudioFileReader.h"
Chris@148 20
Chris@148 21 #include <sndfile.h>
Chris@263 22 #include <QMutex>
Chris@148 23
Chris@148 24 class WavFileReader;
Chris@297 25 class Serialiser;
Chris@297 26 class Resampler;
Chris@148 27
Chris@148 28 class CodedAudioFileReader : public AudioFileReader
Chris@148 29 {
Chris@148 30 public:
Chris@148 31 virtual ~CodedAudioFileReader();
Chris@148 32
Chris@148 33 enum CacheMode {
Chris@148 34 CacheInTemporaryFile,
Chris@148 35 CacheInMemory
Chris@148 36 };
Chris@148 37
Chris@148 38 virtual void getInterleavedFrames(size_t start, size_t count,
Chris@148 39 SampleBlock &frames) const;
Chris@148 40
Chris@297 41 virtual size_t getNativeRate() const { return m_fileRate; }
Chris@297 42
Chris@148 43 protected:
Chris@297 44 CodedAudioFileReader(CacheMode cacheMode, size_t targetRate);
Chris@148 45
Chris@148 46 void initialiseDecodeCache(); // samplerate, channels must have been set
Chris@297 47 void addSamplesToDecodeCache(float **samples, size_t nframes);
Chris@297 48 void addSamplesToDecodeCache(float *samplesInterleaved, size_t nframes);
Chris@297 49 void addSamplesToDecodeCache(const SampleBlock &interleaved);
Chris@148 50 void finishDecodeCache();
Chris@148 51 bool isDecodeCacheInitialised() const { return m_initialised; }
Chris@148 52
Chris@297 53 void startSerialised(QString id);
Chris@297 54 void endSerialised();
Chris@297 55
Chris@297 56 private:
Chris@297 57 void pushBuffer(float *interleaved, size_t sz, bool final);
Chris@297 58
Chris@297 59 protected:
Chris@263 60 QMutex m_cacheMutex;
Chris@148 61 CacheMode m_cacheMode;
Chris@148 62 SampleBlock m_data;
Chris@148 63 bool m_initialised;
Chris@297 64 Serialiser *m_serialiser;
Chris@297 65 size_t m_fileRate;
Chris@148 66
Chris@290 67 QString m_cacheFileName;
Chris@148 68 SNDFILE *m_cacheFileWritePtr;
Chris@148 69 WavFileReader *m_cacheFileReader;
Chris@148 70 float *m_cacheWriteBuffer;
Chris@148 71 size_t m_cacheWriteBufferIndex;
Chris@148 72 size_t m_cacheWriteBufferSize; // frames
Chris@297 73
Chris@297 74 Resampler *m_resampler;
Chris@297 75 float *m_resampleBuffer;
Chris@148 76 };
Chris@148 77
Chris@148 78 #endif