svcore  1.9
CodedAudioFileReader.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef _CODED_AUDIO_FILE_READER_H_
17 #define _CODED_AUDIO_FILE_READER_H_
18 
19 #include "AudioFileReader.h"
20 
21 #include <sndfile.h>
22 #include <QMutex>
23 #include <QReadWriteLock>
24 
25 class WavFileReader;
26 class Serialiser;
27 class Resampler;
28 
30 {
31  Q_OBJECT
32 
33 public:
34  virtual ~CodedAudioFileReader();
35 
36  enum CacheMode {
39  };
40 
41  virtual void getInterleavedFrames(int start, int count,
42  SampleBlock &frames) const;
43 
44  virtual int getNativeRate() const { return m_fileRate; }
45 
47  virtual bool isQuicklySeekable() const { return true; }
48 
49 signals:
50  void progress(int);
51 
52 protected:
54  int targetRate,
55  bool normalised);
56 
57  void initialiseDecodeCache(); // samplerate, channels must have been set
58 
59  // may throw InsufficientDiscSpace:
60  void addSamplesToDecodeCache(float **samples, int nframes);
61  void addSamplesToDecodeCache(float *samplesInterleaved, int nframes);
62  void addSamplesToDecodeCache(const SampleBlock &interleaved);
63 
64  // may throw InsufficientDiscSpace:
65  void finishDecodeCache();
66 
67  bool isDecodeCacheInitialised() const { return m_initialised; }
68 
69  void startSerialised(QString id);
70  void endSerialised();
71 
72 private:
73  void pushBuffer(float *interleaved, int sz, bool final);
74  void pushBufferResampling(float *interleaved, int sz, float ratio, bool final);
75  void pushBufferNonResampling(float *interleaved, int sz);
76 
77 protected:
78  QMutex m_cacheMutex;
81  mutable QReadWriteLock m_dataLock;
85 
86  QString m_cacheFileName;
91  int m_cacheWriteBufferSize; // frames
92 
96 
98  float m_max;
99  float m_gain;
100 };
101 
102 #endif
std::vector< float > SampleBlock
Reader for audio files using libsndfile.
Definition: WavFileReader.h:36
void pushBufferResampling(float *interleaved, int sz, float ratio, bool final)
void addSamplesToDecodeCache(float **samples, int nframes)
CodedAudioFileReader(CacheMode cacheMode, int targetRate, bool normalised)
void pushBufferNonResampling(float *interleaved, int sz)
void pushBuffer(float *interleaved, int sz, bool final)
virtual void getInterleavedFrames(int start, int count, SampleBlock &frames) const
Return interleaved samples for count frames from index start.
WavFileReader * m_cacheFileReader
bool isDecodeCacheInitialised() const
virtual bool isQuicklySeekable() const
Intermediate cache means all CodedAudioFileReaders are quickly seekable.
virtual int getNativeRate() const
void startSerialised(QString id)