|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the examples of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:BSD$ |
|
10 ** You may use this file under the terms of the BSD license as follows: |
|
11 ** |
|
12 ** Redistribution and use in source and binary forms, with or without |
|
13 ** modification, are permitted provided that the following conditions are met: |
|
14 ** - Redistributions of source code must retain the above copyright notice, |
|
15 ** this list of conditions and the following disclaimer. |
|
16 ** - Redistributions in binary form must reproduce the above copyright notice, |
|
17 ** this list of conditions and the following disclaimer in the documentation |
|
18 ** and/or other materials provided with the distribution. |
|
19 ** - Neither the name of Nokia Corporation and its Subsidiary(-ies) nor the |
|
20 ** names of its contributors may be used to endorse or promote products |
|
21 ** derived from this software without specific prior written permission. |
|
22 ** |
|
23 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
24 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
25 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
26 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
|
27 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
28 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
29 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
30 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
31 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
32 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
33 ** POSSIBILITY OF SUCH DAMAGE. |
|
34 ** $QT_END_LICENSE$ |
|
35 ** |
|
36 *****************************************************************************/ |
|
37 |
|
38 |
|
39 #ifndef WAVFILE_H |
|
40 #define WAVFILE_H |
|
41 |
|
42 #include <QtCore/qobject.h> |
|
43 #include <QtCore/qfile.h> |
|
44 #include <QtMultimedia/qaudioformat.h> |
|
45 |
|
46 /** |
|
47 * Helper class for reading WAV files |
|
48 * |
|
49 * See https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ |
|
50 */ |
|
51 class WavFile |
|
52 { |
|
53 public: |
|
54 WavFile(const QAudioFormat &format = QAudioFormat(), |
|
55 qint64 dataLength = 0); |
|
56 |
|
57 // Reads WAV header and seeks to start of data |
|
58 bool readHeader(QIODevice &device); |
|
59 |
|
60 // Writes WAV header |
|
61 bool writeHeader(QIODevice &device); |
|
62 |
|
63 // Read PCM data |
|
64 qint64 readData(QIODevice &device, QByteArray &buffer, |
|
65 QAudioFormat outputFormat = QAudioFormat()); |
|
66 |
|
67 const QAudioFormat& format() const; |
|
68 qint64 dataLength() const; |
|
69 |
|
70 static qint64 headerLength(); |
|
71 |
|
72 static bool writeDataLength(QIODevice &device, qint64 dataLength); |
|
73 |
|
74 private: |
|
75 QAudioFormat m_format; |
|
76 qint64 m_dataLength; |
|
77 }; |
|
78 |
|
79 #endif |
|
80 |