Skip to content

Commit 6da1177

Browse files
committed
CsvStream example
1 parent e4b6eda commit 6da1177

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# I2S Analog Output Test
2+
3+
This is a simple basic test for any processor type
4+
5+
We just send a generated sine wave to the Serial Output
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @file streams-generator-csv.ino
3+
* @author Phil Schatzmann
4+
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-stream/streams-generator-csv/README.md
5+
* @copyright GPLv3
6+
**/
7+
8+
#include "AudioTools.h"
9+
10+
11+
uint16_t sample_rate=44100;
12+
uint8_t channels = 2; // The stream will have 2 channels
13+
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
14+
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
15+
CsvStream<int16_t> out(Serial);
16+
StreamCopy copier(out, sound); // copies sound into i2s
17+
18+
// Arduino Setup
19+
void setup(void) {
20+
// Open Serial
21+
Serial.begin(115200);
22+
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
23+
24+
// start the bluetooth
25+
auto config = out.defaultConfig();
26+
config.sample_rate = sample_rate;
27+
out.begin(config);
28+
29+
// Setup sine wave
30+
sineWave.begin(channels, sample_rate, N_B4);
31+
Serial.println("started...");
32+
}
33+
34+
// Arduino loop - copy sound to out
35+
void loop() {
36+
copier.copy();
37+
}

src/AudioTools/AudioOutput.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,27 @@ class CsvStream : public AudioPrint, public AudioBaseInfoDependent {
6969
this->active = active;
7070
}
7171

72-
// Starts the processing with 2 channels
72+
/// Starts the processing with 2 channels
7373
void begin(){
7474
LOGD(LOG_METHOD);
7575
this->active = true;
7676
this->channels = 2;
7777
}
7878

79-
// Starts the processing with the number of channels defined in AudioBaseInfo
79+
/// Provides the default configuration
80+
AudioBaseInfo defaultConfig(){
81+
AudioBaseInfo info;
82+
return info;
83+
}
84+
85+
/// Starts the processing with the number of channels defined in AudioBaseInfo
8086
void begin(AudioBaseInfo info){
8187
LOGD(LOG_METHOD);
8288
this->active = true;
8389
this->channels = info.channels;
8490
}
8591

86-
// Starts the processing with the defined number of channels
92+
/// Starts the processing with the defined number of channels
8793
void begin(int channels, Print &out=Serial){
8894
LOGD(LOG_METHOD);
8995
this->channels = channels;
@@ -104,6 +110,7 @@ class CsvStream : public AudioPrint, public AudioBaseInfoDependent {
104110
this->channels = info.channels;
105111
};
106112

113+
/// Writes the data - formatted as CSV - to the output stream
107114
virtual size_t write(const uint8_t* data, size_t len) {
108115
if (!active) return 0;
109116
LOGD(LOG_METHOD);

0 commit comments

Comments
 (0)