Skip to content

Commit 070811a

Browse files
committed
* Ignore bext chunk
* formatting script Squashed commit of the following: commit 1c8e40a7a7d137718abff4dc292b9b0b8f2a3134 Author: Steven Atkinson <steven@atkinson.mn> Date: Sat Mar 25 18:52:42 2023 -0700 Format commit 2cf8cdffca3382c9a19e69e1a6af27f5ed1c5508 Author: Steven Atkinson <steven@atkinson.mn> Date: Sat Mar 25 18:52:14 2023 -0700 format.bash commit 198abd6a08683720829e53c8769e2d8e97bff5ad Author: Steven Atkinson <steven@atkinson.mn> Date: Sat Mar 25 18:51:39 2023 -0700 WAV: ignore bext chunk
1 parent 573065e commit 070811a

File tree

3 files changed

+60
-42
lines changed

3 files changed

+60
-42
lines changed

dsp/ImpulseResponse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void dsp::ImpulseResponse::_SetWeights(const double sampleRate) {
6666
// Gain reduction.
6767
// https://github.com/sdatkinson/NeuralAmpModelerPlugin/issues/100#issuecomment-1455273839
6868
// Add sample rate-dependence
69-
const float gain = pow(10, -18 * 0.05) * 48000/sampleRate;
69+
const float gain = pow(10, -18 * 0.05) * 48000 / sampleRate;
7070
for (size_t i = 0, j = irLength - 1; i < irLength; i++, j--)
7171
this->mWeight[j] = gain * this->mResampled[i];
7272
this->mHistoryRequired = irLength - 1;

dsp/wav.cpp

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
#include <fstream>
1010
#include <iostream>
1111
#include <string>
12-
#include <vector>
1312
#include <unordered_set>
13+
#include <vector>
1414

1515
#include "wav.h"
1616

1717
bool idIsJunk(char *id) {
18-
return strncmp(id, "junk", 4) == 0 || strncmp(id, "JUNK", 4) == 0 || strncmp(id, "smpl", 4) == 0 || strncmp(id, "LIST", 4) == 0;
18+
return strncmp(id, "junk", 4) == 0 || strncmp(id, "JUNK", 4) == 0 ||
19+
strncmp(id, "smpl", 4) == 0 || strncmp(id, "LIST", 4) == 0 ||
20+
strncmp(id, "bext", 4) == 0;
1921
}
2022

2123
bool ReadChunkAndSkipJunk(std::ifstream &file, char *chunkID) {
@@ -50,11 +52,10 @@ dsp::wav::LoadReturnCode dsp::wav::Load(const WDL_String &fileName,
5052
// Read the WAV file header
5153
char chunkId[4];
5254
if (!ReadChunkAndSkipJunk(wavFile, chunkId)) {
53-
std::cerr << "Error while reading for next chunk." << std::endl;
54-
return dsp::wav::LoadReturnCode::ERROR_INVALID_FILE;
55+
std::cerr << "Error while reading for next chunk." << std::endl;
56+
return dsp::wav::LoadReturnCode::ERROR_INVALID_FILE;
5557
}
56-
57-
58+
5859
if (strncmp(chunkId, "RIFF", 4) != 0) {
5960
std::cerr << "Error: File does not start with expected RIFF chunk. Got"
6061
<< chunkId << " instead." << std::endl;
@@ -75,8 +76,8 @@ dsp::wav::LoadReturnCode dsp::wav::Load(const WDL_String &fileName,
7576
// Read the format chunk
7677
char subchunk1Id[4];
7778
if (!ReadChunkAndSkipJunk(wavFile, subchunk1Id)) {
78-
std::cerr << "Error while reading for next chunk." << std::endl;
79-
return dsp::wav::LoadReturnCode::ERROR_INVALID_FILE;
79+
std::cerr << "Error while reading for next chunk." << std::endl;
80+
return dsp::wav::LoadReturnCode::ERROR_INVALID_FILE;
8081
}
8182
if (strncmp(subchunk1Id, "fmt ", 4) != 0) {
8283
std::cerr << "Error: Invalid WAV file missing expected fmt section; got "
@@ -87,15 +88,19 @@ dsp::wav::LoadReturnCode dsp::wav::Load(const WDL_String &fileName,
8788
int subchunk1Size;
8889
wavFile.read(reinterpret_cast<char *>(&subchunk1Size), 4);
8990
if (subchunk1Size < 16) {
90-
std::cerr << "WAV chunk 1 size is " << subchunk1Size << ", which is smaller than the requried 16 to fit the expected information." << std::endl;
91-
return dsp::wav::LoadReturnCode::ERROR_INVALID_FILE;
91+
std::cerr << "WAV chunk 1 size is " << subchunk1Size
92+
<< ", which is smaller than the requried 16 to fit the expected "
93+
"information."
94+
<< std::endl;
95+
return dsp::wav::LoadReturnCode::ERROR_INVALID_FILE;
9296
}
9397

9498
unsigned short audioFormat;
9599
wavFile.read(reinterpret_cast<char *>(&audioFormat), 2);
96100
const short AUDIO_FORMAT_PCM = 1;
97101
const short AUDIO_FORMAT_IEEE = 3;
98-
std::unordered_set<short> supportedFormats{ AUDIO_FORMAT_PCM, AUDIO_FORMAT_IEEE };
102+
std::unordered_set<short> supportedFormats{AUDIO_FORMAT_PCM,
103+
AUDIO_FORMAT_IEEE};
99104
if (supportedFormats.find(audioFormat) == supportedFormats.end()) {
100105
std::cerr << "Error: Unsupported WAV format detected. ";
101106
switch (audioFormat) {
@@ -136,22 +141,21 @@ dsp::wav::LoadReturnCode dsp::wav::Load(const WDL_String &fileName,
136141
short bitsPerSample;
137142
wavFile.read(reinterpret_cast<char *>(&bitsPerSample), 2);
138143

139-
// The default is for there to be 16 bytes in the fmt chunk, but sometimes it's different.
144+
// The default is for there to be 16 bytes in the fmt chunk, but sometimes
145+
// it's different.
140146
if (subchunk1Size > 16) {
141-
const int extraBytes = subchunk1Size - 16;
142-
const int skipChars = extraBytes / 4;
143-
wavFile.ignore(skipChars);
144-
const int remainder = extraBytes % 4;
145-
int junk;
146-
wavFile.read(reinterpret_cast<char*>(&byteRate), remainder);
147+
const int extraBytes = subchunk1Size - 16;
148+
const int skipChars = extraBytes / 4;
149+
wavFile.ignore(skipChars);
150+
const int remainder = extraBytes % 4;
151+
wavFile.read(reinterpret_cast<char *>(&byteRate), remainder);
147152
}
148153

149-
150154
// Read the data chunk
151155
char subchunk2Id[4];
152156
if (!ReadChunkAndSkipJunk(wavFile, subchunk2Id)) {
153-
std::cerr << "Error while reading for next chunk." << std::endl;
154-
return dsp::wav::LoadReturnCode::ERROR_INVALID_FILE;
157+
std::cerr << "Error while reading for next chunk." << std::endl;
158+
return dsp::wav::LoadReturnCode::ERROR_INVALID_FILE;
155159
}
156160
if (strncmp(subchunk2Id, "data", 4) != 0) {
157161
std::cerr << "Error: Invalid WAV file" << std::endl;
@@ -163,26 +167,25 @@ dsp::wav::LoadReturnCode dsp::wav::Load(const WDL_String &fileName,
163167
wavFile.read(reinterpret_cast<char *>(&subchunk2Size), 4);
164168

165169
if (audioFormat == AUDIO_FORMAT_IEEE) {
166-
if (bitsPerSample == 32)
167-
dsp::wav::_LoadSamples32(wavFile, subchunk2Size, audio);
168-
else {
169-
std::cerr << "Error: Unsupported bits per sample for IEEE files: " << bitsPerSample
170-
<< std::endl;
171-
return dsp::wav::LoadReturnCode::ERROR_UNSUPPORTED_BITS_PER_SAMPLE;
172-
}
173-
}
174-
else if (audioFormat == AUDIO_FORMAT_PCM) {
175-
if (bitsPerSample == 16)
176-
dsp::wav::_LoadSamples16(wavFile, subchunk2Size, audio);
177-
else if (bitsPerSample == 24)
178-
dsp::wav::_LoadSamples24(wavFile, subchunk2Size, audio);
179-
else if (bitsPerSample == 32)
180-
dsp::wav::_LoadSamples32(wavFile, subchunk2Size, audio);
181-
else {
182-
std::cerr << "Error: Unsupported bits per sample for PCM files: " << bitsPerSample
183-
<< std::endl;
184-
return dsp::wav::LoadReturnCode::ERROR_UNSUPPORTED_BITS_PER_SAMPLE;
185-
}
170+
if (bitsPerSample == 32)
171+
dsp::wav::_LoadSamples32(wavFile, subchunk2Size, audio);
172+
else {
173+
std::cerr << "Error: Unsupported bits per sample for IEEE files: "
174+
<< bitsPerSample << std::endl;
175+
return dsp::wav::LoadReturnCode::ERROR_UNSUPPORTED_BITS_PER_SAMPLE;
176+
}
177+
} else if (audioFormat == AUDIO_FORMAT_PCM) {
178+
if (bitsPerSample == 16)
179+
dsp::wav::_LoadSamples16(wavFile, subchunk2Size, audio);
180+
else if (bitsPerSample == 24)
181+
dsp::wav::_LoadSamples24(wavFile, subchunk2Size, audio);
182+
else if (bitsPerSample == 32)
183+
dsp::wav::_LoadSamples32(wavFile, subchunk2Size, audio);
184+
else {
185+
std::cerr << "Error: Unsupported bits per sample for PCM files: "
186+
<< bitsPerSample << std::endl;
187+
return dsp::wav::LoadReturnCode::ERROR_UNSUPPORTED_BITS_PER_SAMPLE;
188+
}
186189
}
187190

188191
// Close the WAV file

format.bash

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
# Apply project formatting (i.e. clang-format with LLVM style)
3+
#
4+
# Usage:
5+
# $ bash format.bash
6+
7+
echo "Formatting..."
8+
9+
git ls-files "*.h" "*.cpp" | xargs clang-format --style=llvm -i
10+
11+
echo "Formatting complete!"
12+
echo "You can stage all of the files using:"
13+
echo ""
14+
echo ' git ls-files "*.h" "*.cpp" | xargs git add'
15+
echo ""

0 commit comments

Comments
 (0)