snapshot
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
AudioInfo info(44100, 2, 16);
|
||||
SineWaveGenerator<int32_t> sineWave; // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int32_t> sound(sineWave); // Stream generated from sine wave
|
||||
auto invert = [](uint8_t* data, size_t bytes) {
|
||||
size_t sample_count = bytes / sizeof(int16_t);
|
||||
int16_t* data16 = (int16_t*)data;
|
||||
for (int j = 0; j < sample_count; j++) {
|
||||
data16[j] = -data16[j];
|
||||
}
|
||||
return bytes;
|
||||
};
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
CallbackStream cb(out, invert);
|
||||
StreamCopy copier(cb, sound); // copies sound into i2s
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(115200);
|
||||
//AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
// start input sound
|
||||
sineWave.begin(info, N_B4);
|
||||
cb.begin(info);
|
||||
|
||||
// start I2S in
|
||||
auto cfg = out.defaultConfig(TX_MODE);
|
||||
cfg.copyFrom(info);
|
||||
out.begin(cfg);
|
||||
// set AudioKit to full volume
|
||||
out.setVolume(0.3);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
copier.copy(); // Arduino loop - copy sound to out
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
I2SStream s1;
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
I2SStream s2;
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
I2SStream s3;
|
||||
|
||||
void setup(){
|
||||
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
/**
|
||||
* @brief Pin Tests for AudioKit
|
||||
*
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
for (int j=10;j<=36;j++){
|
||||
pinMode(j, INPUT_PULLUP);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (int j=10;j<=36;j++){
|
||||
int value = digitalRead(j);
|
||||
Serial.print(value ? "-":"+");
|
||||
}
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* @file test-ringbufferfile.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief genTest for the file backed ringbuffer
|
||||
* @version 0.1
|
||||
* @date 2023-04-30
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Test for the file backed ringbuffer
|
||||
*/
|
||||
#include <SdFat.h>
|
||||
|
||||
#include "AudioTools.h"
|
||||
// SD pins
|
||||
#define PIN_SD_CARD_CS 13
|
||||
#define PIN_SD_CARD_MISO 2
|
||||
#define PIN_SD_CARD_MOSI 15
|
||||
#define PIN_SD_CARD_CLK 14
|
||||
|
||||
const char* file_name = "/tmp.bin";
|
||||
SdFs SD;
|
||||
FsFile file;
|
||||
RingBufferFile<FsFile, int16_t> buffer(file);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// setup SD
|
||||
SPI.begin(PIN_SD_CARD_CLK, PIN_SD_CARD_MISO, PIN_SD_CARD_MOSI,
|
||||
PIN_SD_CARD_CS);
|
||||
while (!SD.begin(PIN_SD_CARD_CS, SPI_HALF_SPEED)) {
|
||||
Serial.println("Card Mount Failed");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// create file and setup buffer
|
||||
file = SD.open(file_name, O_RDWR | O_CREAT);
|
||||
if (!file) {
|
||||
Serial.println("Failed to open file for writing");
|
||||
return;
|
||||
}
|
||||
if (!buffer.begin(file)) {
|
||||
Serial.println("Failed to create buffer");
|
||||
return;
|
||||
}
|
||||
|
||||
// test write
|
||||
for (int j = 0; j < 10; j++) {
|
||||
buffer.write(j);
|
||||
}
|
||||
|
||||
// test write array
|
||||
int16_t tmp[10];
|
||||
for (int j = 0; j < 10; j++) {
|
||||
tmp[j] = j;
|
||||
}
|
||||
buffer.writeArray(tmp, 10);
|
||||
|
||||
// test read
|
||||
Serial.println("read");
|
||||
for (int j = 0; j < 10; j++) {
|
||||
int16_t result;
|
||||
if (buffer.read(result)) {
|
||||
Serial.print(result);
|
||||
Serial.print(" ");
|
||||
}
|
||||
assert(result == j);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
// test read array
|
||||
Serial.print("readArray");
|
||||
Serial.print(" ");
|
||||
Serial.println(buffer.available());
|
||||
memset(tmp, 0, 10 * sizeof(int16_t));
|
||||
|
||||
int max = buffer.readArray(tmp, buffer.available());
|
||||
for (int j = 0; j < max; j++) {
|
||||
Serial.print(tmp[j]);
|
||||
Serial.print(" ");
|
||||
assert(j == tmp[j]);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
file.close();
|
||||
Serial.println("Test success!");
|
||||
|
||||
// cleanup
|
||||
SD.remove(file_name);
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
@@ -0,0 +1,57 @@
|
||||
// TDM test using a RP2040 with a CS42448 DAC
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
|
||||
const AudioInfo info_in(44100, 1, 16);
|
||||
const AudioInfo info_out(44100, 8, 16);
|
||||
const MusicalNotes notes;
|
||||
Vector<SineWaveGenerator<int16_t>> sineWaves{info_out.channels};
|
||||
Vector<GeneratedSoundStream<int16_t>> sound{info_out.channels};
|
||||
InputMerge<int16_t> imerge; // merge to 8 channels
|
||||
DriverPins dac_pins;
|
||||
AudioBoard board(AudioDriverCS42448, dac_pins);
|
||||
AudioBoardStream tdm(board);
|
||||
StreamCopy copier(tdm, imerge);
|
||||
|
||||
// we use the AudioBoard API to set up the pins for the DAC
|
||||
void setupDACPins() {
|
||||
// add i2c codec pins: scl, sda, port
|
||||
dac_pins.addI2C(PinFunction::CODEC, 4, 5);
|
||||
// add i2s pins: mclk, bck, ws,data_out, data_in ,(port)
|
||||
dac_pins.addI2S(PinFunction::CODEC,-1, 3, 4, 5, -1);
|
||||
}
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// setup input sound and merge -> we get an merge with 8 channels
|
||||
for (int j = 0; j < info_out.channels; j++) {
|
||||
// use a different tone for each channel
|
||||
sineWaves[j].begin(info_in, notes.frequency(j * 2));
|
||||
// setup GeneratedSoundStream
|
||||
sound[j].setInput(sineWaves[j]);
|
||||
sound[j].begin(info_in);
|
||||
// setup merge input stream channels
|
||||
imerge.add(sound[j], 1);
|
||||
}
|
||||
|
||||
// setup DAC pins
|
||||
setupDACPins();
|
||||
|
||||
// setup DAC & I2S
|
||||
auto cfg = tdm.defaultConfig();
|
||||
cfg.copyFrom(info_out);
|
||||
cfg.input_device = ADC_INPUT_NONE;
|
||||
cfg.output_device = DAC_OUTPUT_ALL;
|
||||
cfg.signal_type = TDM;
|
||||
tdm.begin();
|
||||
|
||||
Serial.println("started...");
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() { copier.copy(); }
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
#define SAMPLE_COUNT 2048
|
||||
#define SAMPLE_BUFFER_SIZE sizeof(int32_t) * SAMPLE_COUNT
|
||||
unsigned char raw_data[SAMPLE_BUFFER_SIZE];
|
||||
AudioInfo info(8000, 1, 32);
|
||||
I2SStream i2sStream; // Access I2S as stream
|
||||
MemoryStream raw_samples(raw_data, SAMPLE_BUFFER_SIZE, true, RAM);
|
||||
StreamCopy copier(raw_samples, i2sStream, 1024); // copies sound
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
auto cfg = i2sStream.defaultConfig(RX_MODE);
|
||||
cfg.copyFrom(info);
|
||||
i2sStream.begin(cfg);
|
||||
|
||||
raw_samples.begin();
|
||||
|
||||
copier.copy();
|
||||
|
||||
assert(raw_samples.available()== 1024);
|
||||
assert(raw_samples.availableForWrite()== 7168);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
}
|
||||
Reference in New Issue
Block a user