-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioTest.cpp
More file actions
48 lines (40 loc) · 1.24 KB
/
Copy pathAudioTest.cpp
File metadata and controls
48 lines (40 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Testing code taken directly from ESP9266Audio library example "PlayWAVFromFunction.ino" with some mods
// Original source code here: https://github.com/earlephilhower/ESP8266Audio/blob/master/examples/PlayWAVFromFunction/PlayWAVFromFunction.ino
// Currently unused
#include <Arduino.h>
#include "AudioFileSourceFunction.h"
#include "AudioGeneratorWAV.h"
#include "AudioOutputI2S.h"
#include "Constants.h"
float hz = 440.f;
// pre-defined function can also be used to generate the wave
float sine_wave(const float time) {
float v = sin(TWO_PI * hz * time); // C
v *= fmod(time, 1.f); // change linear
v *= 0.5; // scale
return v;
};
AudioGeneratorWAV* wav;
AudioFileSourceFunction* file;
AudioOutputI2S* out;
void setup() {
Serial.begin(115200);
// ===== create instance with length of song in [sec] =====
file = new AudioFileSourceFunction(10.);
file->addAudioGenerators(sine_wave);
out = new AudioOutputI2S();
out->SetPinout(BCLK_PIN,LRCLK_PIN,DIN_PIN);
wav = new AudioGeneratorWAV();
wav->begin(file, out);
}
void loop() {
if (wav->isRunning()) {
Serial.println("Running");
if (!wav->loop())
{
wav->stop();
}
} else {
Serial.println("function done!");
}
}