mirror of
https://github.com/pschatzmann/arduino-audio-tools.git
synced 2024-09-21 10:27:27 +00:00
STK support
This commit is contained in:
parent
3c82386385
commit
2ddf12a24b
@ -135,6 +135,7 @@ Dependent on the example you might need to install some of the following librari
|
||||
- [SAM](https://github.com/pschatzmann/arduino-SAM) A Text to Speach Engine
|
||||
- [TTS](https://github.com/pschatzmann/TTS) A Text to Speach Engine
|
||||
- [flite](https://github.com/pschatzmann/arduino-flite) A Text to Speach Engine
|
||||
- [arduino-stk](https://github.com/pschatzmann/Arduino-STK) Synthesis ToolKit in C++ (STK)
|
||||
- [Mozzi](https://github.com/pschatzmann/Mozzi) A sound synthesis library for Arduino
|
||||
- [ESP8266Audio](https://github.com/earlephilhower/ESP8266Audio) to play different audio Formats
|
||||
|
||||
|
71
src/AudioSTK.h
Normal file
71
src/AudioSTK.h
Normal file
@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
#include "Arduino.h"
|
||||
#include <Voicer.h>
|
||||
|
||||
|
||||
namespace audio_tools {
|
||||
|
||||
/**
|
||||
* @brief Stream Source which provides the audio data using the STK framework: https://github.com/pschatzmann/Arduino-STK
|
||||
* @author Phil Schatzmann
|
||||
* @copyright GPLv3
|
||||
*/
|
||||
class AudioSTK : public BufferedStream<int16_t> {
|
||||
|
||||
public:
|
||||
/// provides the audio from a Voicer
|
||||
void begin(stk::Voicer &voicer) {
|
||||
p_voicer = &voicer;
|
||||
p_instrument = nullptr;
|
||||
active = true;
|
||||
}
|
||||
|
||||
/// provides the audio from an Instrument
|
||||
void begin(stk::Instrument &instrument) {
|
||||
p_instrument = &instrument;
|
||||
p_voicer = nullptr;
|
||||
active = true;
|
||||
}
|
||||
|
||||
/// stops the generation of sound
|
||||
void end() {
|
||||
active = false;
|
||||
}
|
||||
|
||||
protected:
|
||||
stk::Voicer *p_voicer;
|
||||
stk::Instrument *p_instrument;
|
||||
bool active = false;
|
||||
|
||||
// not supported
|
||||
virtual size_t writeExt(const uint8_t* data, size_t len) {
|
||||
LOGE("not supported");
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual size_t readExt( uint8_t *data, size_t len) {
|
||||
// generate samples
|
||||
size_t result = 0;
|
||||
if (active){
|
||||
result = len;
|
||||
size_t sample_count = len / sizeof(int16_t);
|
||||
int16_t* samples = (int16_t*)data;
|
||||
|
||||
if (p_voicer!=nullptr){
|
||||
for (int j=0;j<sample_count;j++){
|
||||
// scale ticks to int16 values
|
||||
samples[j] = p_voicer->tick() * 32768;
|
||||
}
|
||||
} else if (p_instrument!=nullptr){
|
||||
for (int j=0;j<sample_count;j++){
|
||||
// scale ticks to int16 values
|
||||
samples[j] = p_instrument->tick() * 32768;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
@ -13,6 +13,8 @@ namespace audio_tools {
|
||||
* @brief Typed Stream Copy which supports the conversion from channel to 2 channels. We make sure that we
|
||||
* allways copy full samples
|
||||
* @tparam T
|
||||
* @author Phil Schatzmann
|
||||
* @copyright GPLv3
|
||||
*/
|
||||
template <class T>
|
||||
class StreamCopyT {
|
||||
@ -205,7 +207,8 @@ class StreamCopyT {
|
||||
|
||||
/**
|
||||
* @brief We provide the typeless StreamCopy as a subclass of StreamCopyT
|
||||
*
|
||||
* @author Phil Schatzmann
|
||||
* @copyright GPLv3
|
||||
*/
|
||||
class StreamCopy : public StreamCopyT<uint8_t> {
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user