Skip to content

Commit ccb64bd

Browse files
committed
Merge branch 'release/1.0.7'
2 parents 1c77de7 + 675df13 commit ccb64bd

30 files changed

+428
-66
lines changed

AudioFile.h

Lines changed: 189 additions & 19 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# AudioFile
22

33
<!-- Version and License Badges -->
4-
![Version](https://img.shields.io/badge/version-1.0.6-green.svg?style=flat-square)
4+
![Version](https://img.shields.io/badge/version-1.0.7-green.svg?style=flat-square)
55
![License](https://img.shields.io/badge/license-GPL-blue.svg?style=flat-square)
66
![Language](https://img.shields.io/badge/language-C++-yellow.svg?style=flat-square)
77

@@ -150,6 +150,12 @@ If you prefer not to see these messages, you can disable this error logging beha
150150
Versions
151151
-------
152152

153+
##### 1.0.7 - 3rd July 2020
154+
155+
- Support for 32-bit audio files
156+
- Support for multi-channel audio files
157+
- Reading/writing of [iXML data chunks](http://www.ixml.info/)
158+
153159
##### 1.0.6 - 29th February 2020
154160

155161
- Made error logging to the console optional
@@ -173,6 +179,14 @@ Versions
173179

174180
- Bug fixes
175181

182+
Contributions
183+
-------
184+
185+
* Multichannel (i.e. >2 channels) audio file support ([Sidelobe](https://github.com/Sidelobe))
186+
* Read/write of iXML data chunks ([mynameisjohn](https://github.com/mynameisjohn))
187+
* Remove warnings ([Abhinav1997](https://github.com/Abhinav1997))
188+
189+
176190
License
177191
-------
178192

tests/AudioFileTests/AiffLoadingTests.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
#include "test-headers/aiff_stereo_8bit_44100.h"
1313
#include "test-headers/aiff_stereo_16bit_44100.h"
1414
#include "test-headers/aiff_stereo_24bit_44100.h"
15+
#include "test-headers/aiff_stereo_32bit_44100.h"
1516

1617
// --------------------------------------------
1718
// Test audio files: 48kHz Stereo
1819
#include "test-headers/aiff_stereo_8bit_48000.h"
1920
#include "test-headers/aiff_stereo_16bit_48000.h"
2021
#include "test-headers/aiff_stereo_24bit_48000.h"
22+
#include "test-headers/aiff_stereo_32bit_48000.h"
2123

2224
//=============================================================
2325
BOOST_AUTO_TEST_SUITE (AiffLoadingTests)
@@ -85,6 +87,27 @@ BOOST_AUTO_TEST_CASE (AiffLoadingTests_Stereo_24bit_44100)
8587
}
8688
}
8789

90+
//=============================================================
91+
BOOST_AUTO_TEST_CASE (AiffLoadingTests_Stereo_32bit_44100)
92+
{
93+
AudioFile<double> audioFile;
94+
bool loadedOK = audioFile.load ("test-audio/aiff_stereo_32bit_44100.aif");
95+
96+
BOOST_CHECK (loadedOK);
97+
BOOST_CHECK_EQUAL (audioFile.getNumSamplesPerChannel(), aiff_stereo_32bit_44100::numSamplesPerChannel);
98+
BOOST_CHECK_EQUAL (audioFile.getBitDepth(), aiff_stereo_32bit_44100::bitDepth);
99+
BOOST_CHECK_EQUAL (audioFile.getSampleRate(), aiff_stereo_32bit_44100::sampleRate);
100+
BOOST_CHECK_EQUAL (audioFile.getNumChannels(), aiff_stereo_32bit_44100::numChannels);
101+
102+
for (size_t i = 0; i < aiff_stereo_32bit_44100::testBuffer.size(); i++)
103+
{
104+
for (int k = 0; k < audioFile.getNumChannels(); k++)
105+
{
106+
BOOST_CHECK_CLOSE (audioFile.samples[k][i], aiff_stereo_32bit_44100::testBuffer[k][i], 0.00001);
107+
}
108+
}
109+
}
110+
88111
//=============================================================
89112
BOOST_AUTO_TEST_CASE (AiffLoadingTests_Stereo_8bit_48000)
90113
{
@@ -148,6 +171,27 @@ BOOST_AUTO_TEST_CASE (AiffLoadingTests_Stereo_24bit_48000)
148171
}
149172
}
150173

174+
//=============================================================
175+
BOOST_AUTO_TEST_CASE (AiffLoadingTests_Stereo_32bit_48000)
176+
{
177+
AudioFile<double> audioFile;
178+
bool loadedOK = audioFile.load ("test-audio/aiff_stereo_32bit_48000.aif");
179+
180+
BOOST_CHECK (loadedOK);
181+
BOOST_CHECK_EQUAL (audioFile.getNumSamplesPerChannel(), aiff_stereo_32bit_48000::numSamplesPerChannel);
182+
BOOST_CHECK_EQUAL (audioFile.getBitDepth(), aiff_stereo_32bit_48000::bitDepth);
183+
BOOST_CHECK_EQUAL (audioFile.getSampleRate(), aiff_stereo_32bit_48000::sampleRate);
184+
BOOST_CHECK_EQUAL (audioFile.getNumChannels(), aiff_stereo_32bit_48000::numChannels);
185+
186+
for (size_t i = 0; i < aiff_stereo_32bit_48000::testBuffer.size(); i++)
187+
{
188+
for (int k = 0; k < audioFile.getNumChannels(); k++)
189+
{
190+
BOOST_CHECK_CLOSE (audioFile.samples[k][i], aiff_stereo_32bit_48000::testBuffer[k][i], 0.00001);
191+
}
192+
}
193+
}
194+
151195
BOOST_AUTO_TEST_SUITE_END()
152196

153197
#endif

tests/AudioFileTests/FileWritingTests.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ bool writeTestAudioFile (int numChannels, int sampleRate, int bitDepth, AudioFil
2929

3030
audioFile.setSampleRate (sampleRate);
3131
audioFile.setBitDepth (bitDepth);
32-
33-
std::string numChannelsAsString = numChannels == 1 ? "mono" : "stereo";
32+
33+
std::string numChannelsAsString;
34+
if (numChannels == 1) {
35+
numChannelsAsString = "mono";
36+
} else if (numChannels == 2) {
37+
numChannelsAsString = "stereo";
38+
} else {
39+
numChannelsAsString = std::to_string(numChannels) + " channels";
40+
}
41+
3442
std::string bitDepthAsString = std::to_string (bitDepth);
3543
std::string sampleRateAsString = std::to_string (sampleRate);
3644

@@ -55,8 +63,8 @@ BOOST_AUTO_TEST_SUITE (WritingTests)
5563
BOOST_AUTO_TEST_CASE (WritingTest_WriteSineToneToManyFormats)
5664
{
5765
std::vector<int> sampleRates = {22050, 44100, 48000, 96000};
58-
std::vector<int> bitDepths = {8, 16, 24};
59-
std::vector<int> numChannels = {1, 2};
66+
std::vector<int> bitDepths = {8, 16, 24, 32};
67+
std::vector<int> numChannels = {1, 2, 8};
6068
std::vector<AudioFileFormat> audioFormats = {AudioFileFormat::Wave, AudioFileFormat::Aiff};
6169

6270
for (auto& sampleRate : sampleRates)

tests/AudioFileTests/WavLoadingTests.cpp

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
#include "test-headers/wav_stereo_8bit_44100.h"
1313
#include "test-headers/wav_stereo_16bit_44100.h"
1414
#include "test-headers/wav_stereo_24bit_44100.h"
15+
#include "test-headers/wav_stereo_32bit_44100.h"
1516

1617
// --------------------------------------------
1718
// Test audio files: 48kHz Stereo
1819
#include "test-headers/wav_stereo_8bit_48000.h"
1920
#include "test-headers/wav_stereo_16bit_48000.h"
2021
#include "test-headers/wav_stereo_24bit_48000.h"
22+
#include "test-headers/wav_stereo_32bit_48000.h"
2123

2224
// --------------------------------------------
2325
// Test audio files: 44.1kHz Mono
@@ -29,6 +31,10 @@
2931
//#include "test-headers/wav_mono_8bit_48000.h"
3032
#include "test-headers/wav_mono_16bit_48000.h"
3133

34+
// --------------------------------------------
35+
// Test audio files: 48kHz 8-channel
36+
#include "test-headers/wav_8chan_24bit_48000.h"
37+
3238
//=============================================================
3339
BOOST_AUTO_TEST_SUITE (WavLoadingTests)
3440

@@ -96,9 +102,30 @@ BOOST_AUTO_TEST_CASE (WavLoadingTests_Stereo_24bit_44100)
96102
}
97103

98104
//=============================================================
99-
BOOST_AUTO_TEST_CASE (WavLoadingTests_Mono_8bit_44100)
105+
BOOST_AUTO_TEST_CASE (WavLoadingTests_Stereo_32bit_44100)
100106
{
107+
AudioFile<double> audioFile;
108+
bool loadedOK = audioFile.load ("test-audio/wav_stereo_32bit_44100.wav");
109+
110+
BOOST_CHECK (loadedOK);
111+
BOOST_CHECK_EQUAL (audioFile.getNumSamplesPerChannel(), wav_stereo_32bit_44100::numSamplesPerChannel);
112+
BOOST_CHECK_EQUAL (audioFile.getBitDepth(), wav_stereo_32bit_44100::bitDepth);
113+
BOOST_CHECK_EQUAL (audioFile.getSampleRate(), wav_stereo_32bit_44100::sampleRate);
114+
BOOST_CHECK_EQUAL (audioFile.getNumChannels(), static_cast<int> (wav_stereo_32bit_44100::testBuffer.size()));
115+
116+
for (size_t i = 0; i < wav_stereo_32bit_44100::testBuffer[0].size(); i++)
117+
{
118+
for (int k = 0; k < audioFile.getNumChannels(); k++)
119+
{
120+
BOOST_CHECK_CLOSE (audioFile.samples[k][i], wav_stereo_32bit_44100::testBuffer[k][i], 0.00001);
121+
}
122+
}
123+
}
101124

125+
//=============================================================
126+
BOOST_AUTO_TEST_CASE (WavLoadingTests_Mono_8bit_44100)
127+
{
128+
//TODO
102129
}
103130

104131
//=============================================================
@@ -125,7 +152,7 @@ BOOST_AUTO_TEST_CASE (WavLoadingTests_Mono_16bit_44100)
125152
//=============================================================
126153
BOOST_AUTO_TEST_CASE (WavLoadingTests_Mono_24bit_44100)
127154
{
128-
155+
//TODO
129156
}
130157

131158
//=============================================================
@@ -192,9 +219,30 @@ BOOST_AUTO_TEST_CASE (WavLoadingTests_Stereo_24bit_48000)
192219
}
193220

194221
//=============================================================
195-
BOOST_AUTO_TEST_CASE (WavLoadingTests_Mono_8bit_48000)
222+
BOOST_AUTO_TEST_CASE (WavLoadingTests_Stereo_32bit_48000)
196223
{
224+
AudioFile<double> audioFile;
225+
bool loadedOK = audioFile.load ("test-audio/wav_stereo_32bit_48000.wav");
197226

227+
BOOST_CHECK (loadedOK);
228+
BOOST_CHECK_EQUAL (audioFile.getNumSamplesPerChannel(), wav_stereo_32bit_48000::numSamplesPerChannel);
229+
BOOST_CHECK_EQUAL (audioFile.getBitDepth(), wav_stereo_32bit_48000::bitDepth);
230+
BOOST_CHECK_EQUAL (audioFile.getSampleRate(), wav_stereo_32bit_48000::sampleRate);
231+
BOOST_CHECK_EQUAL (audioFile.getNumChannels(), static_cast<int> (wav_stereo_32bit_48000::testBuffer.size()));
232+
233+
for (size_t i = 0; i < wav_stereo_32bit_48000::testBuffer[0].size(); i++)
234+
{
235+
for (int k = 0; k < audioFile.getNumChannels(); k++)
236+
{
237+
BOOST_CHECK_CLOSE (audioFile.samples[k][i], wav_stereo_32bit_48000::testBuffer[k][i], 0.00001);
238+
}
239+
}
240+
}
241+
242+
//=============================================================
243+
BOOST_AUTO_TEST_CASE (WavLoadingTests_Mono_8bit_48000)
244+
{
245+
//TODO
198246
}
199247

200248
//=============================================================
@@ -221,9 +269,29 @@ BOOST_AUTO_TEST_CASE (WavLoadingTests_Mono_16bit_48000)
221269
//=============================================================
222270
BOOST_AUTO_TEST_CASE (WavLoadingTests_Mono_24bit_48000)
223271
{
224-
272+
//TODO
273+
}
274+
275+
//=============================================================
276+
BOOST_AUTO_TEST_CASE (WavLoadingTests_8chan_24bit_48000)
277+
{
278+
AudioFile<double> audioFile;
279+
bool loadedOK = audioFile.load ("test-audio/wav_8chan_24bit_48000.wav");
280+
281+
BOOST_CHECK (loadedOK);
282+
BOOST_CHECK_EQUAL (audioFile.getNumSamplesPerChannel(), wav_8chan_24bit_48000::numSamplesPerChannel);
283+
BOOST_CHECK_EQUAL (audioFile.getBitDepth(), wav_8chan_24bit_48000::bitDepth);
284+
BOOST_CHECK_EQUAL (audioFile.getSampleRate(), wav_8chan_24bit_48000::sampleRate);
285+
BOOST_CHECK_EQUAL (audioFile.getNumChannels(), wav_8chan_24bit_48000::numChannels);
286+
287+
for (size_t i = 0; i < wav_8chan_24bit_48000::testBuffer.size(); i++)
288+
{
289+
for (int k = 0; k < audioFile.getNumChannels(); k++)
290+
BOOST_CHECK_CLOSE (audioFile.samples[k][i], wav_8chan_24bit_48000::testBuffer[k][i], 0.00001);
291+
}
225292
}
226293

294+
227295
BOOST_AUTO_TEST_SUITE_END()
228296

229297
#endif

tests/AudioFileTests/makeHeaders.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ def makeHeader (fileName, audioSignal, numChannels, bitRate, sampleRate, fileFor
2222

2323
header += "int numSamplesPerChannel = " + str (numSamples) + ";\n"
2424
header += "int bitDepth = " + str(bitRate) + ";\n"
25-
header += "int sampleRate = " + str(sampleRate) + ";\n"
25+
header += "uint32_t sampleRate = " + str(sampleRate) + ";\n"
2626
header += "int numChannels = " + str(numChannels) + ";\n"
2727
header += "\n"
2828
if numChannels == 1:
2929
header += "std::vector<double> testBuffer = "
30-
elif numChannels == 2:
30+
else:
3131
header += "std::vector<std::vector<double>> testBuffer = {"
3232

3333
numSamples = 500 # override to prevent enormous file sizes
@@ -40,16 +40,16 @@ def makeHeader (fileName, audioSignal, numChannels, bitRate, sampleRate, fileFor
4040

4141
if numChannels == 1:
4242
header += str (audioSignal[i])
43-
elif numChannels == 2:
43+
else:
4444
header += str (audioSignal.T[k][i])
45-
if i < (numSamples - 1):
45+
if i < (numSamples - 1):
4646
header += ", "
4747

4848
header += "}"
4949
if k < numChannels - 1:
5050
header += ", "
5151

52-
if numChannels == 2:
52+
if numChannels > 1:
5353
header += "}"
5454

5555
header += ";"
@@ -64,22 +64,22 @@ def makeHeader (fileName, audioSignal, numChannels, bitRate, sampleRate, fileFor
6464
# get all wav files
6565
for fileName in os.listdir("test-audio"):
6666
if fileName.endswith(".wav") or fileName.endswith(".aif"):
67-
67+
6868
if fileName.endswith(".wav"):
6969
audioSignal, fs, enc = wavread ("test-audio/" + fileName)
7070
fileFormat = "wav"
7171
elif fileName.endswith(".aif"):
7272
audioSignal, fs, enc = aiffread ("test-audio/" + fileName)
7373
fileFormat = "aif"
7474
else:
75-
assert (False)
75+
assert (False)
7676

7777
if len (audioSignal.shape) == 1:
7878
numChannels = 1
7979
elif len (audioSignal.shape) == 2:
80-
numChannels = 2
81-
else:
82-
assert (False)
80+
numChannels = audioSignal.shape[1]
81+
else:
82+
assert (False)
8383

8484
#print fileName, enc
8585

@@ -89,10 +89,8 @@ def makeHeader (fileName, audioSignal, numChannels, bitRate, sampleRate, fileFor
8989
makeHeader (fileName, audioSignal, numChannels, 16, fs, fileFormat)
9090
elif enc == "pcm24":
9191
makeHeader (fileName, audioSignal, numChannels, 24, fs, fileFormat)
92+
elif enc == "float32":
93+
makeHeader (fileName, audioSignal, numChannels, 32, fs, fileFormat)
9294
else:
9395
print "Unknown bit depth:", enc
9496
assert (False)
95-
96-
97-
98-
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

tests/AudioFileTests/test-headers/aiff_stereo_16bit_44100.h

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

tests/AudioFileTests/test-headers/aiff_stereo_16bit_48000.h

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

tests/AudioFileTests/test-headers/aiff_stereo_24bit_44100.h

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

tests/AudioFileTests/test-headers/aiff_stereo_24bit_48000.h

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

tests/AudioFileTests/test-headers/aiff_stereo_32bit_44100.h

Lines changed: 12 additions & 0 deletions
Large diffs are not rendered by default.

tests/AudioFileTests/test-headers/aiff_stereo_32bit_48000.h

Lines changed: 12 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)