snapshot
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#include "AudioTools.h"
|
||||
|
||||
uint32_t sampling_rate = 44100;
|
||||
uint32_t delay_us = AudioTime::toTimeUs(sampling_rate);
|
||||
uint32_t count;
|
||||
TimerAlarmRepeating timer;
|
||||
|
||||
void callback(void*ptr){
|
||||
count++;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
Serial.print("Delay us: ");
|
||||
Serial.println(delay_us);
|
||||
// select timer function
|
||||
timer.setTimerFunction(DirectTimerCallback); //DirectTimerCallback,TimerCallbackInThread, SimpleThreadLoop
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
count = 0;
|
||||
timer.begin(callback, delay_us, US);
|
||||
delay(10000);
|
||||
timer.end();
|
||||
char msg[80];
|
||||
sprintf(msg, "Sampling Rate %d vs eff: %d", sampling_rate, count / 10);
|
||||
Serial.println(msg);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
#include "AudioTools.h"
|
||||
|
||||
TimerCallbackAudioStream timerStream;
|
||||
|
||||
uint16_t IRAM_ATTR callback(uint8_t *data, uint16_t len){
|
||||
uint16_t result = len > 256 ? 256 : len;
|
||||
|
||||
for (uint16_t j=0;j<result;j++){
|
||||
data[j]=1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioLogger::instance().begin(Serial,AudioLogger::Info);
|
||||
|
||||
auto cfg = timerStream.defaultConfig();
|
||||
cfg.rx_tx_mode = RX_MODE;
|
||||
cfg.channels = 1;
|
||||
cfg.sample_rate = 5000;
|
||||
cfg.bits_per_sample = 16;
|
||||
cfg.callback = callback;
|
||||
timerStream.begin(cfg);
|
||||
|
||||
}
|
||||
|
||||
/// read from the TimerCallbackAudioStream
|
||||
void loop(){
|
||||
uint8_t buffer[512];
|
||||
while (true){
|
||||
int len = timerStream.readBytes(buffer, 512);
|
||||
for (int j=0;j<len;j++){
|
||||
assert(buffer[j]==1);
|
||||
}
|
||||
Serial.println(len);
|
||||
yield();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
#include "AudioTools.h"
|
||||
|
||||
TimerCallbackAudioStream timerStream;
|
||||
|
||||
// Reads the data in the callback driven by a timer
|
||||
uint16_t IRAM_ATTR callback(uint8_t *data, uint16_t len){
|
||||
for (int j=0;j<len;j++){
|
||||
assert(data[j]==1);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioLogger::instance().begin(Serial,AudioLogger::Info);
|
||||
|
||||
auto cfg = timerStream.defaultConfig();
|
||||
cfg.rx_tx_mode = TX_MODE;
|
||||
cfg.channels = 1;
|
||||
cfg.sample_rate = 5000;
|
||||
cfg.bits_per_sample = 16;
|
||||
cfg.callback = callback;
|
||||
timerStream.begin(cfg);
|
||||
}
|
||||
|
||||
|
||||
// write to the TimerCallbackAudioStream
|
||||
void loop(){
|
||||
uint8_t buffer[512];
|
||||
memset(buffer,1,512);
|
||||
while (true){
|
||||
int len = timerStream.write(buffer, 512);
|
||||
Serial.println(len);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
#include "AudioTools.h"
|
||||
|
||||
TimerCallbackAudioStream timerStream;
|
||||
|
||||
uint16_t IRAM_ATTR callback(uint8_t *data, uint16_t len){
|
||||
uint16_t result = len > 256 ? 256 : len;
|
||||
|
||||
for (uint16_t j=0;j<result;j++){
|
||||
data[j]=1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioLogger::instance().begin(Serial,AudioLogger::Info);
|
||||
|
||||
auto cfg = timerStream.defaultConfig();
|
||||
cfg.rx_tx_mode = RX_MODE;
|
||||
cfg.channels = 1;
|
||||
cfg.sample_rate = 5000;
|
||||
cfg.bits_per_sample = 16;
|
||||
cfg.timer_function = TimerCallbackInThread; // Use separate Task
|
||||
cfg.callback = callback;
|
||||
timerStream.begin(cfg);
|
||||
|
||||
}
|
||||
|
||||
/// read from the TimerCallbackAudioStream
|
||||
void loop(){
|
||||
uint8_t buffer[512];
|
||||
while (true){
|
||||
int len = timerStream.readBytes(buffer, 512);
|
||||
for (int j=0;j<len;j++){
|
||||
assert(buffer[j]==1);
|
||||
}
|
||||
Serial.println(len);
|
||||
yield();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
|
||||
#include "AudioTools.h"
|
||||
|
||||
TimerCallbackAudioStream timerStream;
|
||||
|
||||
// Reads the data in the callback driven by a timer
|
||||
uint16_t IRAM_ATTR callback(uint8_t *data, uint16_t len){
|
||||
for (int j=0;j<len;j++){
|
||||
assert(data[j]==1);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
AudioLogger::instance().begin(Serial,AudioLogger::Info);
|
||||
|
||||
auto cfg = timerStream.defaultConfig();
|
||||
cfg.rx_tx_mode = TX_MODE;
|
||||
cfg.channels = 1;
|
||||
cfg.sample_rate = 5000;
|
||||
cfg.bits_per_sample = 16;
|
||||
cfg.timer_function = TimerCallbackInThread; // Use separate Task
|
||||
cfg.callback = callback;
|
||||
timerStream.begin(cfg);
|
||||
}
|
||||
|
||||
|
||||
// write to the TimerCallbackAudioStream
|
||||
void loop(){
|
||||
uint8_t buffer[512];
|
||||
memset(buffer,1,512);
|
||||
while (true){
|
||||
int len = timerStream.write(buffer, 512);
|
||||
Serial.println(len);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user