snapshot
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @file streams-faust-i2s.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief Example how to use Faust as "Singal Processor"
|
||||
* @version 0.1
|
||||
* @date 2022-04-22
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioLibs/AudioBoardStream.h"
|
||||
#include "AudioTools/AudioLibs/AudioFaust.h"
|
||||
#include "volume.h"
|
||||
|
||||
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
|
||||
mydsp dsp;
|
||||
AudioBoardStream out(AudioKitEs8388V1);
|
||||
FaustStream<mydsp> faust(out);
|
||||
StreamCopy copier(faust, sound); // copy mic to tfl
|
||||
|
||||
// Arduino Setup
|
||||
void setup(void) {
|
||||
// Open Serial
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// Setup Faust volume control
|
||||
auto cfg = faust.defaultConfig();
|
||||
faust.begin(cfg);
|
||||
faust.setLabelValue("0x00", 0.5);
|
||||
|
||||
// Setup sine wave generator
|
||||
sineWave.begin(cfg.channels, cfg.sample_rate, N_B4);
|
||||
|
||||
// start I2S
|
||||
auto cfg_i2s = out.defaultConfig(TX_MODE);
|
||||
cfg_i2s.sample_rate = cfg.sample_rate;
|
||||
cfg_i2s.channels = cfg.channels;
|
||||
cfg_i2s.bits_per_sample = cfg.bits_per_sample;
|
||||
out.begin(cfg_i2s);
|
||||
|
||||
}
|
||||
|
||||
// Arduino loop - copy sound to out
|
||||
void loop() {
|
||||
copier.copy();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
declare compilation_options "-single -scal -inpl -fx -I /Users/pschatzmann/.FaustLive-CurrentSession-2.0/Libs -I /Users/pschatzmann/.FaustLive-CurrentSession-2.0/Examples";
|
||||
declare library_path "volume";
|
||||
declare library_path "/Users/pschatzmann/.FaustLive-CurrentSession-2.0/Libs/stdfaust.lib";
|
||||
declare library_path "/Users/pschatzmann/.FaustLive-CurrentSession-2.0/Libs/basics.lib";
|
||||
declare library_path "/Users/pschatzmann/.FaustLive-CurrentSession-2.0/Libs/signals.lib";
|
||||
declare author "Grame";
|
||||
declare basics_lib_name "Faust Basic Element Library";
|
||||
declare basics_lib_version "0.1";
|
||||
declare copyright "(c)GRAME 2006";
|
||||
declare filename "volume";
|
||||
declare license "BSD";
|
||||
declare name "volume";
|
||||
declare signals_lib_name "Faust Signal Routing Library";
|
||||
declare signals_lib_version "0.0";
|
||||
declare version "1.0";
|
||||
process = _,(vslider("[1]", 0.0f, -70.0f, 4.0f, 0.10000000000000001f) : \(x1).(10.0f,(x1,20.0f : /) : pow) : _,0.0010000000000000009f : * : +~(_,0.999f : *)) : *;
|
||||
@@ -0,0 +1,126 @@
|
||||
/* ------------------------------------------------------------
|
||||
author: "Grame"
|
||||
copyright: "(c)GRAME 2006"
|
||||
license: "BSD"
|
||||
name: "volume"
|
||||
version: "1.0"
|
||||
Code generated with Faust 2.38.16 (https://faust.grame.fr)
|
||||
Compilation options: -lang cpp -es 1 -mcd 16 -single -ftz 0
|
||||
------------------------------------------------------------ */
|
||||
|
||||
#ifndef __mydsp_H__
|
||||
#define __mydsp_H__
|
||||
|
||||
#ifndef FAUSTFLOAT
|
||||
#define FAUSTFLOAT float
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
|
||||
#ifndef FAUSTCLASS
|
||||
#define FAUSTCLASS mydsp
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define exp10f __exp10f
|
||||
#define exp10 __exp10
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define RESTRICT __restrict
|
||||
#else
|
||||
#define RESTRICT __restrict__
|
||||
#endif
|
||||
|
||||
|
||||
class mydsp : public dsp {
|
||||
|
||||
private:
|
||||
|
||||
FAUSTFLOAT fVslider0;
|
||||
float fRec0[2];
|
||||
int fSampleRate;
|
||||
|
||||
public:
|
||||
|
||||
void metadata(Meta* m) {
|
||||
m->declare("author", "Grame");
|
||||
m->declare("basics_lib_name", "Faust Basic Element Library");
|
||||
m->declare("basics_lib_version", "0.1");
|
||||
m->declare("compilation_options", "-single -scal -inpl -fx -I /Users/pschatzmann/.FaustLive-CurrentSession-2.0/Libs -I /Users/pschatzmann/.FaustLive-CurrentSession-2.0/Examples");
|
||||
m->declare("compile_options", "-lang cpp -es 1 -mcd 16 -single -ftz 0 ");
|
||||
m->declare("copyright", "(c)GRAME 2006");
|
||||
m->declare("filename", "volume.dsp");
|
||||
m->declare("library_path", "volume");
|
||||
m->declare("license", "BSD");
|
||||
m->declare("name", "volume");
|
||||
m->declare("signals_lib_name", "Faust Signal Routing Library");
|
||||
m->declare("signals_lib_version", "0.0");
|
||||
m->declare("version", "1.0");
|
||||
}
|
||||
|
||||
virtual int getNumInputs() {
|
||||
return 1;
|
||||
}
|
||||
virtual int getNumOutputs() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void classInit(int sample_rate) {
|
||||
}
|
||||
|
||||
virtual void instanceConstants(int sample_rate) {
|
||||
fSampleRate = sample_rate;
|
||||
}
|
||||
|
||||
virtual void instanceResetUserInterface() {
|
||||
fVslider0 = FAUSTFLOAT(0.0f);
|
||||
}
|
||||
|
||||
virtual void instanceClear() {
|
||||
for (int l0 = 0; (l0 < 2); l0 = (l0 + 1)) {
|
||||
fRec0[l0] = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void init(int sample_rate) {
|
||||
classInit(sample_rate);
|
||||
instanceInit(sample_rate);
|
||||
}
|
||||
virtual void instanceInit(int sample_rate) {
|
||||
instanceConstants(sample_rate);
|
||||
instanceResetUserInterface();
|
||||
instanceClear();
|
||||
}
|
||||
|
||||
virtual mydsp* clone() {
|
||||
return new mydsp();
|
||||
}
|
||||
|
||||
virtual int getSampleRate() {
|
||||
return fSampleRate;
|
||||
}
|
||||
|
||||
virtual void buildUserInterface(UI* ui_interface) {
|
||||
ui_interface->openVerticalBox("volume");
|
||||
ui_interface->declare(&fVslider0, "1", "");
|
||||
ui_interface->addVerticalSlider("0x00", &fVslider0, FAUSTFLOAT(0.0f), FAUSTFLOAT(-70.0f), FAUSTFLOAT(4.0f), FAUSTFLOAT(0.100000001f));
|
||||
ui_interface->closeBox();
|
||||
}
|
||||
|
||||
virtual void compute(int count, FAUSTFLOAT** RESTRICT inputs, FAUSTFLOAT** RESTRICT outputs) {
|
||||
FAUSTFLOAT* input0 = inputs[0];
|
||||
FAUSTFLOAT* output0 = outputs[0];
|
||||
float fSlow0 = (0.00100000005f * std::pow(10.0f, (0.0500000007f * float(fVslider0))));
|
||||
for (int i0 = 0; (i0 < count); i0 = (i0 + 1)) {
|
||||
fRec0[0] = (fSlow0 + (0.999000013f * fRec0[1]));
|
||||
output0[i0] = FAUSTFLOAT((float(input0[i0]) * fRec0[0]));
|
||||
fRec0[1] = fRec0[0];
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user