snapshot
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
# Decoding a WAV file
|
||||
|
||||
In this example we decode a WAV file into RAW output and send it to a PWM pins (on a Raspberry Pico or ESP32)
|
||||
|
||||
The WAV file has been down sampled with the help of __Audacity__ and then converted into an array with __xxd__.
|
||||
|
||||
Please note that this example is still using the more confusing old api which uses the following processing chain:
|
||||
MemoryStream -> AudioOutputStream -> WAVDecoder -> AudioPWM
|
||||
|
||||
|
||||
The pins depend on the Processor:
|
||||
|
||||
| PIEZO | ESP32 | RPI Pico | MBED |
|
||||
| --------| -------------|---------------|--------------|
|
||||
| + | GPIO4 | GPIO2 | GPIO2 |
|
||||
| - | GND | | |
|
||||
|
||||
|
||||
Complie with Partition Scheme Huge APP!
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @file stream-memory_wav-pwm.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief decode WAV stream and output to PWM pins
|
||||
* @version 0.1
|
||||
* @date 2021-01-24
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*/
|
||||
|
||||
#include "AudioTools.h"
|
||||
//#include "knghtsng.h"
|
||||
#include "alice.h"
|
||||
|
||||
//Data Flow: MemoryStream -> EncodedAudioStream -> PWMAudioOutput
|
||||
//Use 8000 for alice_wav and 11025 for knghtsng_wav
|
||||
AudioInfo info(8000, 1, 16);
|
||||
//MemoryStream wav(knghtsng_wav, knghtsng_wav_len);
|
||||
MemoryStream wav(alice_wav, alice_wav_len);
|
||||
PWMAudioOutput pwm; // PWM output
|
||||
EncodedAudioStream out(&pwm, new WAVDecoder()); // Decoder stream
|
||||
StreamCopy copier(out, wav); // copy in to out
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
wav.begin();
|
||||
out.begin();
|
||||
|
||||
auto config = pwm.defaultConfig();
|
||||
config.copyFrom(info);
|
||||
pwm.begin(config);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
if (wav) {
|
||||
copier.copy();
|
||||
} else {
|
||||
// after we are done we just print some info form the wav file
|
||||
auto info = out.audioInfo();
|
||||
LOGI("The audio rate from the wav file is %d", info.sample_rate);
|
||||
LOGI("The channels from the wav file is %d", info.channels);
|
||||
|
||||
// restart from the beginning
|
||||
Serial.println("Restarting...");
|
||||
delay(5000);
|
||||
out.begin(); // indicate that we process the WAV header
|
||||
wav.begin(); // reset actual position to 0
|
||||
pwm.begin(); // reset counters
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user