annotate data/fileio/CodedAudioFileReader.h @ 1018:4a2c150ecd67

Avoid crash when setting alignment to 0
author Chris Cannam
date Thu, 20 Nov 2014 16:18:31 +0000
parents 36f79bc5c3d7
children cc27f35aa75c
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@929 41 virtual void getInterleavedFrames(int start, int count,
Chris@148 42 SampleBlock &frames) const;
Chris@148 43
Chris@929 44 virtual int getNativeRate() const { return m_fileRate; }
Chris@297 45
Chris@1010 46 virtual QString getLocalFilename() const { return m_cacheFileName; }
Chris@1010 47
Chris@823 48 /// Intermediate cache means all CodedAudioFileReaders are quickly seekable
Chris@823 49 virtual bool isQuicklySeekable() const { return true; }
Chris@823 50
Chris@357 51 signals:
Chris@357 52 void progress(int);
Chris@357 53
Chris@148 54 protected:
Chris@933 55 CodedAudioFileReader(CacheMode cacheMode,
Chris@933 56 int targetRate,
Chris@920 57 bool normalised);
Chris@148 58
Chris@148 59 void initialiseDecodeCache(); // samplerate, channels must have been set
Chris@544 60
Chris@544 61 // may throw InsufficientDiscSpace:
Chris@929 62 void addSamplesToDecodeCache(float **samples, int nframes);
Chris@929 63 void addSamplesToDecodeCache(float *samplesInterleaved, int nframes);
Chris@297 64 void addSamplesToDecodeCache(const SampleBlock &interleaved);
Chris@544 65
Chris@544 66 // may throw InsufficientDiscSpace:
Chris@148 67 void finishDecodeCache();
Chris@544 68
Chris@148 69 bool isDecodeCacheInitialised() const { return m_initialised; }
Chris@148 70
Chris@297 71 void startSerialised(QString id);
Chris@297 72 void endSerialised();
Chris@297 73
Chris@297 74 private:
Chris@929 75 void pushBuffer(float *interleaved, int sz, bool final);
Chris@929 76 void pushBufferResampling(float *interleaved, int sz, float ratio, bool final);
Chris@929 77 void pushBufferNonResampling(float *interleaved, int sz);
Chris@297 78
Chris@297 79 protected:
Chris@263 80 QMutex m_cacheMutex;
Chris@148 81 CacheMode m_cacheMode;
Chris@148 82 SampleBlock m_data;
Chris@543 83 mutable QReadWriteLock m_dataLock;
Chris@148 84 bool m_initialised;
Chris@297 85 Serialiser *m_serialiser;
Chris@929 86 int m_fileRate;
Chris@148 87
Chris@290 88 QString m_cacheFileName;
Chris@148 89 SNDFILE *m_cacheFileWritePtr;
Chris@148 90 WavFileReader *m_cacheFileReader;
Chris@148 91 float *m_cacheWriteBuffer;
Chris@929 92 int m_cacheWriteBufferIndex;
Chris@929 93 int m_cacheWriteBufferSize; // frames
Chris@297 94
Chris@297 95 Resampler *m_resampler;
Chris@297 96 float *m_resampleBuffer;
Chris@929 97 int m_fileFrameCount;
Chris@920 98
Chris@920 99 bool m_normalised;
Chris@920 100 float m_max;
Chris@920 101 float m_gain;
Chris@148 102 };
Chris@148 103
Chris@148 104 #endif