annotate data/fileio/CodedAudioFileReader.h @ 776:cb587575bc0d tonioni

reset FlexiNote layer to have default piano (I couldn't get it to do organ anyway)
author matthiasm
date Tue, 26 Mar 2013 20:15:04 +0000
parents babed5be1ae7
children f0558e69a074
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@543 23 #include <QReadWriteLock>
Chris@148 24
Chris@148 25 class WavFileReader;
Chris@297 26 class Serialiser;
Chris@297 27 class Resampler;
Chris@148 28
Chris@148 29 class CodedAudioFileReader : public AudioFileReader
Chris@148 30 {
Chris@357 31 Q_OBJECT
Chris@357 32
Chris@148 33 public:
Chris@148 34 virtual ~CodedAudioFileReader();
Chris@148 35
Chris@148 36 enum CacheMode {
Chris@148 37 CacheInTemporaryFile,
Chris@148 38 CacheInMemory
Chris@148 39 };
Chris@148 40
Chris@148 41 virtual void getInterleavedFrames(size_t start, size_t count,
Chris@148 42 SampleBlock &frames) const;
Chris@148 43
Chris@297 44 virtual size_t getNativeRate() const { return m_fileRate; }
Chris@297 45
Chris@357 46 signals:
Chris@357 47 void progress(int);
Chris@357 48
Chris@148 49 protected:
Chris@297 50 CodedAudioFileReader(CacheMode cacheMode, size_t targetRate);
Chris@148 51
Chris@148 52 void initialiseDecodeCache(); // samplerate, channels must have been set
Chris@544 53
Chris@544 54 // may throw InsufficientDiscSpace:
Chris@297 55 void addSamplesToDecodeCache(float **samples, size_t nframes);
Chris@297 56 void addSamplesToDecodeCache(float *samplesInterleaved, size_t nframes);
Chris@297 57 void addSamplesToDecodeCache(const SampleBlock &interleaved);
Chris@544 58
Chris@544 59 // may throw InsufficientDiscSpace:
Chris@148 60 void finishDecodeCache();
Chris@544 61
Chris@148 62 bool isDecodeCacheInitialised() const { return m_initialised; }
Chris@148 63
Chris@297 64 void startSerialised(QString id);
Chris@297 65 void endSerialised();
Chris@297 66
Chris@297 67 private:
Chris@297 68 void pushBuffer(float *interleaved, size_t sz, bool final);
Chris@758 69 void pushBufferResampling(float *interleaved, size_t sz, float ratio, bool final);
Chris@758 70 void pushBufferNonResampling(float *interleaved, size_t sz);
Chris@297 71
Chris@297 72 protected:
Chris@263 73 QMutex m_cacheMutex;
Chris@148 74 CacheMode m_cacheMode;
Chris@148 75 SampleBlock m_data;
Chris@543 76 mutable QReadWriteLock m_dataLock;
Chris@148 77 bool m_initialised;
Chris@297 78 Serialiser *m_serialiser;
Chris@297 79 size_t m_fileRate;
Chris@148 80
Chris@290 81 QString m_cacheFileName;
Chris@148 82 SNDFILE *m_cacheFileWritePtr;
Chris@148 83 WavFileReader *m_cacheFileReader;
Chris@148 84 float *m_cacheWriteBuffer;
Chris@148 85 size_t m_cacheWriteBufferIndex;
Chris@148 86 size_t m_cacheWriteBufferSize; // frames
Chris@297 87
Chris@297 88 Resampler *m_resampler;
Chris@297 89 float *m_resampleBuffer;
Chris@757 90 size_t m_fileFrameCount;
Chris@148 91 };
Chris@148 92
Chris@148 93 #endif