annotate data/fileio/CodedAudioFileReader.h @ 398:be49bf95d4a5

* Fix hang when using more than one consecutive coded audio file reader in decode-at-once mode
author Chris Cannam
date Wed, 26 Mar 2008 14:35:03 +0000
parents b92513201610
children 7a66b94ef1c0
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@357 30 Q_OBJECT
Chris@357 31
Chris@148 32 public:
Chris@148 33 virtual ~CodedAudioFileReader();
Chris@148 34
Chris@148 35 enum CacheMode {
Chris@148 36 CacheInTemporaryFile,
Chris@148 37 CacheInMemory
Chris@148 38 };
Chris@148 39
Chris@148 40 virtual void getInterleavedFrames(size_t start, size_t count,
Chris@148 41 SampleBlock &frames) const;
Chris@148 42
Chris@297 43 virtual size_t getNativeRate() const { return m_fileRate; }
Chris@297 44
Chris@357 45 signals:
Chris@357 46 void progress(int);
Chris@357 47
Chris@148 48 protected:
Chris@297 49 CodedAudioFileReader(CacheMode cacheMode, size_t targetRate);
Chris@148 50
Chris@148 51 void initialiseDecodeCache(); // samplerate, channels must have been set
Chris@297 52 void addSamplesToDecodeCache(float **samples, size_t nframes);
Chris@297 53 void addSamplesToDecodeCache(float *samplesInterleaved, size_t nframes);
Chris@297 54 void addSamplesToDecodeCache(const SampleBlock &interleaved);
Chris@148 55 void finishDecodeCache();
Chris@148 56 bool isDecodeCacheInitialised() const { return m_initialised; }
Chris@148 57
Chris@297 58 void startSerialised(QString id);
Chris@297 59 void endSerialised();
Chris@297 60
Chris@297 61 private:
Chris@297 62 void pushBuffer(float *interleaved, size_t sz, bool final);
Chris@297 63
Chris@297 64 protected:
Chris@263 65 QMutex m_cacheMutex;
Chris@148 66 CacheMode m_cacheMode;
Chris@148 67 SampleBlock m_data;
Chris@148 68 bool m_initialised;
Chris@297 69 Serialiser *m_serialiser;
Chris@297 70 size_t m_fileRate;
Chris@148 71
Chris@290 72 QString m_cacheFileName;
Chris@148 73 SNDFILE *m_cacheFileWritePtr;
Chris@148 74 WavFileReader *m_cacheFileReader;
Chris@148 75 float *m_cacheWriteBuffer;
Chris@148 76 size_t m_cacheWriteBufferIndex;
Chris@148 77 size_t m_cacheWriteBufferSize; // frames
Chris@297 78
Chris@297 79 Resampler *m_resampler;
Chris@297 80 float *m_resampleBuffer;
Chris@148 81 };
Chris@148 82
Chris@148 83 #endif