Skip to content

Commit d40c82e

Browse files
committed
Comments CatStream
1 parent cb9a16e commit d40c82e

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include "AudioTools.h"
2+
#include "AudioTools/AudioLibs/AudioRealFFT.h" // using RealFFT
3+
4+
AudioInfo info(44100, 1, 16);
5+
AudioRealFFT fft; // or AudioKissFFT
6+
Hann hann;
7+
BufferedWindow buffered(&hann);
8+
SineWaveGenerator<int16_t> sineWave(32000);
9+
GeneratedSoundStream<int16_t> in(sineWave);
10+
StreamCopy copier(fft, in);
11+
CsvStream<int16_t> out(Serial);
12+
StreamCopy copierOut(out, fft);
13+
float value = 0;
14+
15+
// display fft result
16+
void fftResult(AudioFFTBase &fft) {
17+
float diff;
18+
auto result = fft.result();
19+
if (result.magnitude > 100) {
20+
Serial.print(result.frequency);
21+
Serial.print(" ");
22+
Serial.print(result.magnitude);
23+
Serial.print(" => ");
24+
Serial.print(result.frequencyAsNote(diff));
25+
Serial.print(" diff: ");
26+
Serial.print(diff);
27+
Serial.print(" - time ms ");
28+
Serial.print(fft.resultTime() - fft.resultTimeBegin());
29+
Serial.println();
30+
}
31+
// execute ifft
32+
copierOut.copyAll();
33+
}
34+
35+
void setup() {
36+
Serial.begin(115200);
37+
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
38+
39+
// set the frequency
40+
sineWave.setFrequency(N_B4);
41+
42+
// Setup sine wave
43+
auto cfg = in.defaultConfig();
44+
cfg.copyFrom(info);
45+
in.begin(cfg);
46+
47+
// Setup FFT
48+
auto tcfg = fft.defaultConfig(RXTX_MODE);
49+
tcfg.window_function = &buffered;
50+
fft.begin(tcfg);
51+
52+
// setup output
53+
out.begin(info);
54+
}
55+
56+
void loop() { copier.copy(); }

src/AudioTools/CoreAudio/BaseStream.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ class AudioStream : public BaseStream, public AudioInfoSupport, public AudioInfo
176176
/**
177177
* @brief Provides data from a concatenation of Streams. Please note that the
178178
* provided Streams can be played only once! You will need to reset them (e.g.
179-
* moving the file pointer to the beginning) and readd them back if you want to
179+
* moving the file pointer to the beginning) and read them back if you want to
180180
* process them a second time. The default timeout on the available() method is
181-
* set to 0. This might be not good if you use e.g. a URLStream.
181+
* set to 0. This might be too small if you use e.g. a URLStream.
182182
* @ingroup io
183183
* @author Phil Schatzmann
184184
* @copyright GPLv3
@@ -222,6 +222,8 @@ class CatStream : public BaseStream {
222222
void setOnEndCallback(void (*callback)(Stream *stream)) {
223223
end_callback = callback;
224224
}
225+
226+
/// Defines the timout the system waits for data when moving to the next stream
225227
void setTimeout(uint32_t t) { _timeout = t; }
226228

227229
/// not supported

0 commit comments

Comments
 (0)