Skip to content

Commit 11dbe2e

Browse files
committed
Make return codes consistent with other Arduino API's
1 parent 2a072a8 commit 11dbe2e

File tree

10 files changed

+37
-37
lines changed

10 files changed

+37
-37
lines changed

examples/AmplitudeSerialPlotter/AmplitudeSerialPlotter.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ void setup() {
3232
}
3333

3434
// setup the I2S audio input for 44.1 kHz with 32-bits per sample
35-
if (AudioInI2S.begin(44100, 32)) {
35+
if (!AudioInI2S.begin(44100, 32)) {
3636
Serial.println("Failed to initialize I2S input!");
3737
while (1); // do nothing
3838
}
3939

4040
// configure the I2S input as the input for the amplitude analyzer
41-
if (amplitudeAnalyzer.input(AudioInI2S)) {
41+
if (!amplitudeAnalyzer.input(AudioInI2S)) {
4242
Serial.println("Failed to set amplitude analyzer input!");
4343
while (1); // do nothing
4444
}

examples/ClapDetector/ClapDetector.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ void setup() {
3838
pinMode(ledPin, OUTPUT);
3939

4040
// setup the I2S audio input for 44.1 kHz with 32-bits per sample
41-
if (AudioInI2S.begin(44100, 32)) {
41+
if (!AudioInI2S.begin(44100, 32)) {
4242
Serial.println("Failed to initialize I2S input!");
4343
while (1); // do nothing
4444
}
4545

4646
// configure the I2S input as the input for the amplitude analyzer
47-
if (amplitudeAnalyzer.input(AudioInI2S)) {
47+
if (!amplitudeAnalyzer.input(AudioInI2S)) {
4848
Serial.println("Failed to set amplitude analyzer input!");
4949
while (1); // do nothing
5050
}

examples/SpectrumSerialPlotter/SpectrumSerialPlotter.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ void setup() {
4444
}
4545

4646
// setup the I2S audio input for the sample rate with 32-bits per sample
47-
if (AudioInI2S.begin(sampleRate, 32)) {
47+
if (!AudioInI2S.begin(sampleRate, 32)) {
4848
Serial.println("Failed to initialize I2S input!");
4949
while (1); // do nothing
5050
}
5151

5252
// configure the I2S input as the input for the FFT analyzer
53-
if (fftAnalyzer.input(AudioInI2S)) {
53+
if (!fftAnalyzer.input(AudioInI2S)) {
5454
Serial.println("Failed to set FFT analyzer input!");
5555
while (1); // do nothing
5656
}

examples/WhistleDetector/WhistleDetector.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ void setup() {
5151
pinMode(ledPin, OUTPUT);
5252

5353
// setup the I2S audio input for the sample rate with 32-bits per sample
54-
if (AudioInI2S.begin(sampleRate, 32)) {
54+
if (!AudioInI2S.begin(sampleRate, 32)) {
5555
Serial.println("Failed to initialize I2S input!");
5656
while (1); // do nothing
5757
}
5858

5959
// configure the I2S input as the input for the FFT analyzer
60-
if (fftAnalyzer.input(AudioInI2S)) {
60+
if (!fftAnalyzer.input(AudioInI2S)) {
6161
Serial.println("Failed to set FFT analyzer input!");
6262
while (1); // do nothing
6363
}

src/AmplitudeAnalyzer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ int AmplitudeAnalyzer::configure(AudioIn* input)
5151
int bitsPerSample = input->bitsPerSample();
5252

5353
if (bitsPerSample != 16 && bitsPerSample != 32) {
54-
return 1;
54+
return 0;
5555
}
5656

5757
_bitsPerSample = bitsPerSample;
5858

59-
return 0;
59+
return 1;
6060
}
6161

6262
void AmplitudeAnalyzer::update(const void* buffer, size_t size)

src/AudioIn.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ AudioIn::~AudioIn()
3232
int AudioIn::setAnalyzer(AudioAnalyzer* analyzer)
3333
{
3434
if (_analyzer) {
35-
return 1;
35+
return 0;
3636
}
3737

38-
if (analyzer->configure(this)) {
39-
return 1;
38+
if (!analyzer->configure(this)) {
39+
return 0;
4040
}
4141

4242
_analyzer = analyzer;
4343

44-
return 0;
44+
return 1;
4545
}
4646

4747
void AudioIn::samplesRead(void* buffer, size_t size)

src/AudioInI2S.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ AudioInI2SClass::~AudioInI2SClass()
3333

3434
int AudioInI2SClass::begin(long sampleRate, int bitsPerSample)
3535
{
36-
if (I2S.begin(I2S_PHILIPS_MODE, sampleRate, bitsPerSample)) {
37-
return 1;
36+
if (!I2S.begin(I2S_PHILIPS_MODE, sampleRate, bitsPerSample)) {
37+
return 0;
3838
}
3939

4040
_sampleRate = sampleRate;
@@ -46,7 +46,7 @@ int AudioInI2SClass::begin(long sampleRate, int bitsPerSample)
4646
// trigger a read to kick things off
4747
I2S.read();
4848

49-
return 0;
49+
return 1;
5050
}
5151

5252
void AudioInI2SClass::end()

src/AudioOutI2S.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ int AudioOutI2SClass::loop(AudioIn& input)
6161
int AudioOutI2SClass::pause()
6262
{
6363
if (!isPlaying()) {
64-
return 1;
64+
return 0;
6565
}
6666

6767
_paused = true;
6868

69-
return 0;
69+
return 1;
7070
}
7171

7272
int AudioOutI2SClass::resume()
7373
{
7474
if (!_paused) {
75-
return 1;
75+
return 0;
7676
}
7777

7878
_paused = false;
@@ -84,13 +84,13 @@ int AudioOutI2SClass::resume()
8484
I2S.write(silence, sizeof(silence));
8585
I2S.write(silence, sizeof(silence));
8686

87-
return 0;
87+
return 1;
8888
}
8989

9090
int AudioOutI2SClass::stop()
9191
{
9292
if (!_input) {
93-
return 1;
93+
return 0;
9494
}
9595

9696
endInput(_input);
@@ -119,13 +119,13 @@ int AudioOutI2SClass::startPlayback(AudioIn& input, bool loop)
119119

120120
I2S.onTransmit(AudioOutI2SClass::onI2STransmit);
121121

122-
if (I2S.begin(I2S_PHILIPS_MODE, input.sampleRate(), input.bitsPerSample())) {
123-
return 1;
122+
if (!I2S.begin(I2S_PHILIPS_MODE, input.sampleRate(), input.bitsPerSample())) {
123+
return 0;
124124
}
125125

126-
if (beginInput(&input)) {
126+
if (!beginInput(&input)) {
127127
I2S.end();
128-
return 1;
128+
return 0;
129129
}
130130

131131
_input = &input;
@@ -137,7 +137,7 @@ int AudioOutI2SClass::startPlayback(AudioIn& input, bool loop)
137137
I2S.write(silence, sizeof(silence));
138138
I2S.write(silence, sizeof(silence));
139139

140-
return 0;
140+
return 1;
141141
}
142142

143143
void AudioOutI2SClass::onTransmit()
@@ -158,7 +158,7 @@ void AudioOutI2SClass::onTransmit()
158158
}
159159

160160
// reset the input
161-
if (resetInput(_input)) {
161+
if (!resetInput(_input)) {
162162
I2S.end();
163163
return;
164164
}

src/FFTAnalyzer.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,20 @@ int FFTAnalyzer::configure(AudioIn* input)
7878
int channels = input->channels();
7979

8080
if (bitsPerSample != 16 && bitsPerSample != 32) {
81-
return 1;
81+
return 0;
8282
}
8383

8484
if (channels != 1 && channels != 2) {
85-
return 1;
85+
return 0;
8686
}
8787

8888
if (bitsPerSample == 16) {
8989
if (ARM_MATH_SUCCESS != arm_rfft_init_q15(&_S15, _length, 0, 1)) {
90-
return 1;
90+
return 0;
9191
}
9292
} else {
9393
if (ARM_MATH_SUCCESS != arm_rfft_init_q31(&_S31, _length, 0, 1)) {
94-
return 1;
94+
return 0;
9595
}
9696
}
9797

@@ -126,10 +126,10 @@ int FFTAnalyzer::configure(AudioIn* input)
126126
_spectrumBuffer = NULL;
127127
}
128128

129-
return 1;
129+
return 0;
130130
}
131131

132-
return 0;
132+
return 1;
133133
}
134134

135135
void FFTAnalyzer::update(const void* buffer, size_t size)

src/SDWaveFile.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ int SDWaveFile::cue(long time)
163163
int SDWaveFile::begin()
164164
{
165165
if (!(*this)) {
166-
return 1;
166+
return 0;
167167
}
168168

169169
_file = SD.open(_filename);
170170

171171
_isPlaying = true;
172172

173-
return 0;
173+
return 1;
174174
}
175175

176176
int SDWaveFile::read(void* buffer, size_t size)
@@ -194,7 +194,7 @@ int SDWaveFile::reset()
194194
{
195195
cue(0);
196196

197-
return 0;
197+
return 1;
198198
}
199199

200200
void SDWaveFile::end()

0 commit comments

Comments
 (0)