-
-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65b5b20
commit 6a98cc1
Showing
32 changed files
with
774 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
examples/examples-communication/http-client/streams-url_mp3-pwm/streams-url_mp3-pwm.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* @file streams-url_mp3-out.ino | ||
* @author Phil Schatzmann | ||
* @brief decode MP3 stream from url and output it with the help of PWM | ||
* @version 0.1 | ||
* @date 2021-96-25 | ||
* | ||
* @copyright Copyright (c) 2021 | ||
*/ | ||
|
||
// install https://github.com/pschatzmann/arduino-libhelix.git | ||
|
||
#include "AudioTools.h" | ||
#include "AudioTools/AudioCodecs/CodecMP3Helix.h" | ||
|
||
|
||
URLStream url("ssid","password"); | ||
PWMAudioOutput out; // final output of decoded stream | ||
EncodedAudioStream dec(&out, new MP3DecoderHelix()); // Decoding stream | ||
StreamCopy copier(dec, url); // copy url to decoder | ||
|
||
|
||
void setup(){ | ||
Serial.begin(115200); | ||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info); | ||
|
||
// setup out | ||
auto config = out.defaultConfig(TX_MODE); | ||
//config.resolution = 8; // must be between 8 and 11 -> drives pwm frequency (8 is default) | ||
// alternative 1 | ||
//config.start_pin = 3; | ||
// alternative 2 | ||
int pins[] = {22, 23}; | ||
// alternative 3 | ||
//Pins pins = {3}; | ||
//config.setPins(pins); | ||
out.begin(config); | ||
|
||
// setup I2S based on sampling rate provided by decoder | ||
dec.begin(); | ||
|
||
// mp3 radio | ||
url.begin("http://stream.srg-ssr.ch/m/rsj/mp3_128","audio/mp3"); | ||
|
||
} | ||
|
||
void loop(){ | ||
copier.copy(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 0 additions & 67 deletions
67
examples/tests/concurrency/SynchronizedNBuffer/SynchronizedNBuffer.ino
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
#include "AudioTools.h" | ||
#include "AudioTools/Concurrency/RP2040.h" | ||
|
||
AudioInfo info(44100, 2, 16); | ||
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000 | ||
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave | ||
BufferRP2040 buffer(1024, 10); | ||
QueueStream queue(buffer); | ||
CsvOutput<int16_t> csv(Serial); | ||
StreamCopy copierFill(queue, sound); // copies sound into i2s | ||
StreamCopy copierConsume(csv, queue); // copies sound into i2s | ||
|
||
|
||
void setup(){ | ||
Serial.begin(115200); | ||
while(!Serial); | ||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info); | ||
|
||
queue.begin(); | ||
sineWave.begin(info, N_B4); | ||
csv.begin(info); | ||
} | ||
|
||
void loop(){ | ||
copierFill.copy(); | ||
} | ||
|
||
void loop1(){ | ||
copierConsume.copy(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "AudioTools.h" | ||
#include "AudioTools/Concurrency/RP2040.h" | ||
|
||
SpinLock mutex; | ||
NBuffer<int16_t> nbuffer(512, 10); | ||
SynchronizedBuffer<int16_t> buffer(nbuffer, mutex); | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
while (!Serial); | ||
Serial.println("starting..."); | ||
} | ||
|
||
void loop() { | ||
int16_t data[512]; | ||
for (int j = 0; j < 512; j++) { | ||
data[j] = j; | ||
} | ||
size_t result = buffer.writeArray(data, 512); | ||
if(result != 512){ | ||
// queue is full: give the reading queue some chance to empty | ||
delay(5); | ||
} | ||
} | ||
|
||
void loop1() { | ||
static uint64_t start = millis(); | ||
static size_t total_bytes = 0; | ||
static size_t errors = 0; | ||
static int16_t data[512]; | ||
|
||
// read data | ||
size_t result = buffer.readArray(data, 512); | ||
if(result == 0){ | ||
// reading queue is empty: give some time to fill | ||
delay(5); | ||
return; | ||
} | ||
|
||
// check data | ||
for (int j = 0; j < 512; j++) { | ||
if (data[j] != j) errors++; | ||
} | ||
// calculate bytes per second | ||
total_bytes += sizeof(int16_t) * 512; | ||
if (total_bytes >= 1024000) { | ||
uint64_t duration = millis() - start; | ||
float mbps = static_cast<float>(total_bytes) / duration / 1000.0; | ||
|
||
// print result | ||
Serial.print("Mbytes per second: "); | ||
Serial.print(mbps); | ||
Serial.print(" with "); | ||
Serial.print(errors); | ||
Serial.println(" errors"); | ||
|
||
start = millis(); | ||
errors = 0; | ||
total_bytes = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "AudioTools.h" | ||
#include "AudioTools/Concurrency/RP2040.h" | ||
|
||
MutexRP2040 mutex; | ||
NBuffer<int16_t> nbuffer(512, 10); | ||
SynchronizedBuffer<int16_t> buffer(nbuffer, mutex); | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
while (!Serial); | ||
Serial.println("starting..."); | ||
} | ||
|
||
void loop() { | ||
int16_t data[512]; | ||
for (int j = 0; j < 512; j++) { | ||
data[j] = j; | ||
} | ||
size_t result = buffer.writeArray(data, 512); | ||
if(result != 512){ | ||
Serial.print("write failed: "); | ||
Serial.println(result); | ||
} | ||
} | ||
|
||
void loop1() { | ||
static uint64_t start = millis(); | ||
static size_t total_bytes = 0; | ||
static size_t errors = 0; | ||
static int16_t data[512]; | ||
|
||
// read data | ||
size_t result = buffer.readArray(data, 512); | ||
if(result != 512){ | ||
Serial.print("read failed: "); | ||
Serial.println(result); | ||
} | ||
|
||
// check data | ||
for (int j = 0; j < 512; j++) { | ||
if (data[j] != j) errors++; | ||
} | ||
// calculate bytes per second | ||
total_bytes += sizeof(int16_t) * 512; | ||
if (total_bytes >= 1024000) { | ||
uint64_t duration = millis() - start; | ||
float mbps = static_cast<float>(total_bytes) / duration / 1000.0; | ||
|
||
// print result | ||
Serial.print("Mbytes per second: "); | ||
Serial.print(mbps); | ||
Serial.print(" with "); | ||
Serial.print(errors); | ||
Serial.println(" errors"); | ||
|
||
start = millis(); | ||
errors = 0; | ||
total_bytes = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
#include "AudioTools/Concurrency/Mutex.h" | ||
#include "AudioTools/Concurrency/SynchronizedBuffer.h" | ||
#include "AudioTools/Concurrency/SynchronizedQueue.h" | ||
#include "AudioTools/Concurrency/RP2040/BufferRP2040.h" | ||
#include "AudioTools/Concurrency/RP2040/MutexRP2040.h" |
Oops, something went wrong.