diff options
author | Gareth Stockwell <ext-gareth.stockwell@nokia.com> | 2010-10-26 16:15:29 (GMT) |
---|---|---|
committer | Gareth Stockwell <ext-gareth.stockwell@nokia.com> | 2010-10-29 12:46:34 (GMT) |
commit | 3cf35876400cb008fb25c8a3191c996af6059264 (patch) | |
tree | d7f38aa848daf1f70c2f3fd878f4eddee067661f /demos/spectrum/app/wavfile.h | |
parent | a53df3596e2061c202845f9f1c183177ca8a7eda (diff) | |
download | Qt-3cf35876400cb008fb25c8a3191c996af6059264.zip Qt-3cf35876400cb008fb25c8a3191c996af6059264.tar.gz Qt-3cf35876400cb008fb25c8a3191c996af6059264.tar.bz2 |
Play whole file in spectrum analyzer demo
This change required a significant refactoring of the application,
including:
* Re-write WavFile class so that it inherits from QFile rather
than taking a QIODevice as an argument to its method calls.
* Modified Engine class so that its internal QByteArray buffer
(m_buffer) need not correspond to the entire clip. This was done
by introducing the m_bufferPosition variable, which indicates the
offset from the start of the clip to the start of the region of
the clip which is currently held in memory. For tone generation
and record/playback modes, the buffer does still map directly to
the whole clip, so m_bufferPosition is always zero. For file
playback, the WavFile instance is the QIODevice which is passed
to QAudioOutput; m_buffer is just the part of the file which is
currently in memory for spectrum analysis, level calculation and
waveform rendering.
* For file playback, introduced a second WavFile instance as a
member of the Engine class. This is because QFile::seek() is
called in order to read the part of the file currently required
for analysis. If the QAudioOutput implementation passes its
QIODevice across a thread boundary, this seeking causes playback
to jump around within the file rather than progressing smoothly
forward.
* Modified the audioLength utility function so that its return
value is always a multiple of the sample size.
In the process of making the above changes, a few other minor
modifications were made:
* Modify all internal APIs concerned with buffer offsets and lengths
to deal in bytes. Previously, some calls passed values in
microseconds and others in bytes, which was confusing.
* Remove write functionality from WavFile class, since it is not
used in this application.
Task-number: QTBUG-12936
Diffstat (limited to 'demos/spectrum/app/wavfile.h')
-rw-r--r-- | demos/spectrum/app/wavfile.h | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/demos/spectrum/app/wavfile.h b/demos/spectrum/app/wavfile.h index fc14b08..935e935 100644 --- a/demos/spectrum/app/wavfile.h +++ b/demos/spectrum/app/wavfile.h @@ -46,38 +46,22 @@ #include <QtCore/qfile.h> #include <QtMultimedia/qaudioformat.h> -/** - * Helper class for reading WAV files - * - * See https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ - */ -class WavFile +class WavFile : public QFile { public: - WavFile(const QAudioFormat &format = QAudioFormat(), - qint64 dataLength = 0); + WavFile(QObject *parent = 0); - // Reads WAV header and seeks to start of data - bool readHeader(QIODevice &device); + bool open(const QString &fileName); + const QAudioFormat &fileFormat() const; + qint64 headerLength() const; - // Writes WAV header - bool writeHeader(QIODevice &device); - - // Read PCM data - qint64 readData(QIODevice &device, QByteArray &buffer, - QAudioFormat outputFormat = QAudioFormat()); - - const QAudioFormat& format() const; - qint64 dataLength() const; - - static qint64 headerLength(); - - static bool writeDataLength(QIODevice &device, qint64 dataLength); +private: + bool readHeader(); private: - QAudioFormat m_format; - qint64 m_dataLength; - qint64 m_dataPosition; + QAudioFormat m_fileFormat; + qint64 m_headerLength; + }; #endif |