From b3266bce747ca16d4d65cbdeb7797673348cc099 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 28 Sep 2023 08:10:52 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20doxygen=20from=20@=20pschatzma?= =?UTF-8?q?nn/arduino-audio-tools@b15cbd9fb3fa93cf4b763421a7e05011ee62f780?= =?UTF-8?q?=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _audio_faust_8h_source.html | 486 ++++++++++++++++++------------------ 1 file changed, 244 insertions(+), 242 deletions(-) diff --git a/_audio_faust_8h_source.html b/_audio_faust_8h_source.html index 822a1c8e91..c23a9beddc 100644 --- a/_audio_faust_8h_source.html +++ b/_audio_faust_8h_source.html @@ -115,7 +115,7 @@
55  TRACED();
56  bool result = true;
57  this->cfg = cfg;
-
58  this->bytes_per_sample = cfg.bits_per_sample/8;
+
58  this->bytes_per_sample = cfg.bits_per_sample / 8;
59  this->bytes_per_frame = bytes_per_sample * cfg.channels;
60  this->float_to_int_factor = NumberConverter::maxValue(cfg.bits_per_sample);
61 
@@ -201,242 +201,244 @@
143  }
144 
146  size_t write(const uint8_t *write_data, size_t len) override {
-
147  switch(cfg.bits_per_sample){
-
148  case 8:
-
149  return writeT<int8_t>(write_data, len);
-
150  case 16:
-
151  return writeT<int16_t>(write_data, len);
-
152  case 24:
-
153  return writeT<int24_t>(write_data, len);
-
154  case 32:
-
155  return writeT<int32_t>(write_data, len);
-
156  default:
-
157  TRACEE();
-
158  }
-
159  return 0;
-
160  }
-
161 
-
162  int available() override {
-
163  return DEFAULT_BUFFER_SIZE;
-
164  }
-
165 
-
166  int availableForWrite() override {
-
167  return DEFAULT_BUFFER_SIZE / bytes_per_frame; // we limit the write size
-
168  }
-
169 
-
171  virtual FAUSTFLOAT labelValue(const char*label) {
-
172  return ui.getValue(label);
-
173  }
-
174 
-
176  virtual bool setLabelValue(const char*label, FAUSTFLOAT value){
-
177  if (!is_read && !is_write) LOGE("setLabelValue must be called after begin");
-
178  bool result = ui.setValue(label, value);
-
179  LOGI("setLabelValue('%s',%f) -> %s", label, value, result?"true":"false");
-
180  return result;
-
181  }
-
182 
-
183  virtual bool setMidiNote(int note){
-
184  FAUSTFLOAT frq = noteToFrequency(note);
-
185  return setFrequency(frq);
-
186  }
-
187 
-
188  virtual bool setFrequency(FAUSTFLOAT freq){
-
189  return setLabelValue("freq", freq);
-
190  }
-
191 
-
192  virtual FAUSTFLOAT frequency() {
-
193  return labelValue("freq");
-
194  }
-
195 
-
196  virtual bool setBend(FAUSTFLOAT bend){
-
197  return setLabelValue("bend", bend);
-
198  }
-
199 
-
200  virtual FAUSTFLOAT bend() {
-
201  return labelValue("bend");
-
202  }
-
203 
-
204  virtual bool setGain(FAUSTFLOAT gain){
-
205  return setLabelValue("gain", gain);
-
206  }
-
207 
-
208  virtual FAUSTFLOAT gain() {
-
209  return labelValue("gain");
-
210  }
-
211 
-
212  virtual bool midiOn(int note, FAUSTFLOAT gain){
-
213  if (gate_exists) setLabelValue("gate",1.0);
-
214  return setMidiNote(note) && setGain(gain);
-
215  }
-
216 
-
217  virtual bool midiOff(int note){
-
218  if (gate_exists) setLabelValue("gate",0.0);
-
219  return setMidiNote(note) && setGain(0.0);
-
220  }
-
221 
-
222  protected:
-
223  bool is_init = false;
-
224  bool is_read = false;
-
225  bool is_write = false;
-
226  bool gate_exists = false;
-
227  bool with_output_buffer;
-
228  int bytes_per_sample;
-
229  int bytes_per_frame;
-
230  int buffer_allocated;
-
231  float float_to_int_factor = 32767;
-
232  DSP *p_dsp = nullptr;
-
233  AudioInfo cfg;
-
234  Print *p_out=nullptr;
-
235  FAUSTFLOAT** p_buffer=nullptr;
-
236  FAUSTFLOAT** p_buffer_out=nullptr;
-
237  UI ui;
-
238 
-
240  bool checkChannels() {
-
241  bool result = true;
-
242 
-
243  // update channels
-
244  int num_outputs = p_dsp->getNumOutputs();
-
245  if (cfg.channels!=num_outputs){
-
246  cfg.channels = num_outputs;
-
247  LOGW("Updating channels to %d", num_outputs);
-
248  }
-
249 
-
250  if (num_outputs>0){
-
251  if (num_outputs==cfg.channels){
-
252  is_read = true;
-
253  } else {
-
254  LOGE("NumOutputs %d is not matching with number of channels %d", num_outputs, cfg.channels);
-
255  result = false;
-
256  }
-
257  if (p_dsp->getNumInputs()!=0 && p_dsp->getNumInputs()!=cfg.channels){
-
258  LOGE("NumInputs is not matching with number of channels");
-
259  result = false;
-
260  }
-
261  if (p_dsp->getNumInputs()>0){
-
262  if (p_out!=nullptr){
-
263  is_write = true;
-
264  } else {
-
265  LOGE("Faust expects input - you need to provide and AudioStream in the constructor");
-
266  result = false;
-
267  }
-
268  }
-
269  }
-
270  return result;
-
271  }
-
272 
-
274  template <class T>
-
275  void convertFloatBufferToInt(int samples, FAUSTFLOAT**p_float_in, void *data_out){
-
276  T *dataT = (T*) data_out;
-
277  int frameCount = samples/cfg.channels;
-
278  for (int j=0; j<frameCount; j++){
-
279  for (int i=0;i<cfg.channels;i++){
-
280  float sample = p_float_in[i][j];
-
281  // clip input
-
282  if(sample > 1.0f){
-
283  sample = 1.0f;
-
284  }
-
285  if(sample < -1.0f){
-
286  sample = -1.0f;
-
287  }
-
288  dataT[(j*cfg.channels)+i] = sample * float_to_int_factor;
-
289  }
-
290  }
-
291  }
-
292 
-
294  template <class T>
-
295  void convertIntBufferToFloat(int samples, void *data_in, FAUSTFLOAT**p_float_out ){
-
296  T *dataT = (T*) data_in;
-
297  int frameCount = samples/cfg.channels;
-
298  for(int j=0;j<frameCount;j++){
-
299  for(int i=0;i<cfg.channels;i++){
-
300  p_float_out[i][j] = static_cast<FAUSTFLOAT>(dataT[(j*cfg.channels)+i]) / float_to_int_factor;
-
301  }
-
302  }
-
303  }
-
304 
-
306  template <class T>
-
307  size_t writeT(const uint8_t *write_data, size_t len) {
-
308  size_t result = 0;
-
309  if (is_write){
-
310  TRACED();
-
311  int samples = len / bytes_per_sample;
-
312  // prepare float input for faust
-
313  allocateFloatBuffer(samples, with_output_buffer);
-
314  convertIntBufferToFloat<T>(samples, (void*) write_data, p_buffer);
-
315 
-
316  // determine result
-
317  FAUSTFLOAT** p_float_buffer = with_output_buffer ? p_buffer_out : p_buffer;
-
318  p_dsp->compute(samples, p_buffer, p_float_buffer);
-
319 
-
320  // update buffer with data from faust
-
321  convertFloatBufferToInt<T>(samples, p_float_buffer, (void*) write_data);
-
322  // write data to final output
-
323  result = p_out->write(write_data, len);
-
324  }
-
325  return result;
-
326  }
-
327 
-
328 
-
330  void allocateFloatBuffer(int samples, bool allocate_out){
-
331  if (samples>buffer_allocated){
-
332  if (p_buffer[0]!=nullptr){
-
333  for (int j=0;j<cfg.channels;j++){
-
334  delete[]p_buffer[j];
-
335  p_buffer[j] = nullptr;
-
336  }
-
337  }
-
338  if (p_buffer_out!=nullptr && p_buffer_out[0]!=nullptr){
-
339  for (int j=0;j<cfg.channels;j++){
-
340  delete[]p_buffer_out[j];
-
341  p_buffer_out[j] = nullptr;
-
342  }
-
343  }
-
344  }
-
345  if (p_buffer[0]==nullptr){
-
346  const int ch = cfg.channels;
-
347  for (int j=0;j<ch;j++){
-
348  p_buffer[j] = new FAUSTFLOAT[samples];
-
349  }
-
350  buffer_allocated = samples;
-
351  }
-
352  if (allocate_out){
-
353  if (p_buffer_out[0]==nullptr){
-
354  const int ch = cfg.channels;
-
355  for (int j=0;j<ch;j++){
-
356  p_buffer_out[j] = new FAUSTFLOAT[samples];
-
357  }
-
358  }
-
359  }
-
360  }
-
361 
-
362  void deleteFloatBuffer() {
-
363  if (p_buffer!=nullptr) {
-
364  for (int j=0;j<cfg.channels;j++){
-
365  if (p_buffer[j]!=nullptr) delete p_buffer[j];
-
366  }
-
367  delete[] p_buffer;
-
368  p_buffer = nullptr;
-
369  }
-
370  if (p_buffer_out!=nullptr) {
-
371  for (int j=0;j<cfg.channels;j++){
-
372  if (p_buffer_out[j]!=nullptr) delete p_buffer_out[j];
-
373  }
-
374  delete[] p_buffer_out;
-
375  p_buffer_out = nullptr;
-
376  }
-
377  }
-
378 
-
379  FAUSTFLOAT noteToFrequency(uint8_t x) {
-
380  FAUSTFLOAT note = x;
-
381  return 440.0 * pow(2.0f, (note-69)/12);
-
382  }
-
383 
-
384 };
+
147  LOGD("FaustStream::write: %d", len);
+
148  switch(cfg.bits_per_sample){
+
149  case 8:
+
150  return writeT<int8_t>(write_data, len);
+
151  case 16:
+
152  return writeT<int16_t>(write_data, len);
+
153  case 24:
+
154  return writeT<int24_t>(write_data, len);
+
155  case 32:
+
156  return writeT<int32_t>(write_data, len);
+
157  default:
+
158  TRACEE();
+
159  }
+
160  return 0;
+
161  }
+
162 
+
163  int available() override {
+
164  return DEFAULT_BUFFER_SIZE;
+
165  }
+
166 
+
167  int availableForWrite() override {
+
168  return DEFAULT_BUFFER_SIZE / bytes_per_frame; // we limit the write size
+
169  }
+
170 
+
172  virtual FAUSTFLOAT labelValue(const char*label) {
+
173  return ui.getValue(label);
+
174  }
+
175 
+
177  virtual bool setLabelValue(const char*label, FAUSTFLOAT value){
+
178  if (!is_read && !is_write) LOGE("setLabelValue must be called after begin");
+
179  bool result = ui.setValue(label, value);
+
180  LOGI("setLabelValue('%s',%f) -> %s", label, value, result?"true":"false");
+
181  return result;
+
182  }
+
183 
+
184  virtual bool setMidiNote(int note){
+
185  FAUSTFLOAT frq = noteToFrequency(note);
+
186  return setFrequency(frq);
+
187  }
+
188 
+
189  virtual bool setFrequency(FAUSTFLOAT freq){
+
190  return setLabelValue("freq", freq);
+
191  }
+
192 
+
193  virtual FAUSTFLOAT frequency() {
+
194  return labelValue("freq");
+
195  }
+
196 
+
197  virtual bool setBend(FAUSTFLOAT bend){
+
198  return setLabelValue("bend", bend);
+
199  }
+
200 
+
201  virtual FAUSTFLOAT bend() {
+
202  return labelValue("bend");
+
203  }
+
204 
+
205  virtual bool setGain(FAUSTFLOAT gain){
+
206  return setLabelValue("gain", gain);
+
207  }
+
208 
+
209  virtual FAUSTFLOAT gain() {
+
210  return labelValue("gain");
+
211  }
+
212 
+
213  virtual bool midiOn(int note, FAUSTFLOAT gain){
+
214  if (gate_exists) setLabelValue("gate",1.0);
+
215  return setMidiNote(note) && setGain(gain);
+
216  }
+
217 
+
218  virtual bool midiOff(int note){
+
219  if (gate_exists) setLabelValue("gate",0.0);
+
220  return setMidiNote(note) && setGain(0.0);
+
221  }
+
222 
+
223  protected:
+
224  bool is_init = false;
+
225  bool is_read = false;
+
226  bool is_write = false;
+
227  bool gate_exists = false;
+
228  bool with_output_buffer;
+
229  int bytes_per_sample;
+
230  int bytes_per_frame;
+
231  int buffer_allocated;
+
232  float float_to_int_factor = 32767;
+
233  DSP *p_dsp = nullptr;
+
234  AudioInfo cfg;
+
235  Print *p_out=nullptr;
+
236  FAUSTFLOAT** p_buffer=nullptr;
+
237  FAUSTFLOAT** p_buffer_out=nullptr;
+
238  UI ui;
+
239 
+
241  bool checkChannels() {
+
242  bool result = true;
+
243 
+
244  // update channels
+
245  int num_outputs = p_dsp->getNumOutputs();
+
246  if (cfg.channels!=num_outputs){
+
247  cfg.channels = num_outputs;
+
248  LOGW("Updating channels to %d", num_outputs);
+
249  }
+
250 
+
251  if (num_outputs>0){
+
252  if (num_outputs==cfg.channels){
+
253  is_read = true;
+
254  } else {
+
255  LOGE("NumOutputs %d is not matching with number of channels %d", num_outputs, cfg.channels);
+
256  result = false;
+
257  }
+
258  if (p_dsp->getNumInputs()!=0 && p_dsp->getNumInputs()!=cfg.channels){
+
259  LOGE("NumInputs is not matching with number of channels");
+
260  result = false;
+
261  }
+
262  if (p_dsp->getNumInputs()>0){
+
263  if (p_out!=nullptr){
+
264  is_write = true;
+
265  } else {
+
266  LOGE("Faust expects input - you need to provide and AudioStream in the constructor");
+
267  result = false;
+
268  }
+
269  }
+
270  }
+
271  return result;
+
272  }
+
273 
+
275  template <class T>
+
276  void convertFloatBufferToInt(int samples, FAUSTFLOAT**p_float_in, void *data_out){
+
277  T *dataT = (T*) data_out;
+
278  int frameCount = samples/cfg.channels;
+
279  for (int j=0; j<frameCount; j++){
+
280  for (int i=0;i<cfg.channels;i++){
+
281  float sample = p_float_in[i][j];
+
282  // clip input
+
283  if(sample > 1.0f){
+
284  sample = 1.0f;
+
285  }
+
286  if(sample < -1.0f){
+
287  sample = -1.0f;
+
288  }
+
289  dataT[(j*cfg.channels)+i] = sample * float_to_int_factor;
+
290  }
+
291  }
+
292  }
+
293 
+
295  template <class T>
+
296  void convertIntBufferToFloat(int samples, void *data_in, FAUSTFLOAT**p_float_out ){
+
297  T *dataT = (T*) data_in;
+
298  int frameCount = samples/cfg.channels;
+
299  for(int j=0;j<frameCount;j++){
+
300  for(int i=0;i<cfg.channels;i++){
+
301  p_float_out[i][j] = static_cast<FAUSTFLOAT>(dataT[(j*cfg.channels)+i]) / float_to_int_factor;
+
302  }
+
303  }
+
304  }
+
305 
+
307  template <class T>
+
308  size_t writeT(const uint8_t *write_data, size_t len) {
+
309  size_t result = 0;
+
310  if (is_write){
+
311  TRACED();
+
312  int samples = len / bytes_per_sample;
+
313  int frames = samples / cfg.channels;
+
314  // prepare float input for faust
+
315  allocateFloatBuffer(samples, with_output_buffer);
+
316  convertIntBufferToFloat<T>(samples, (void*) write_data, p_buffer);
+
317 
+
318  // determine result
+
319  FAUSTFLOAT** p_float_buffer = with_output_buffer ? p_buffer_out : p_buffer;
+
320  p_dsp->compute(frames, p_buffer, p_float_buffer);
+
321 
+
322  // update buffer with data from faust
+
323  convertFloatBufferToInt<T>(samples, p_float_buffer, (void*) write_data);
+
324  // write data to final output
+
325  result = p_out->write(write_data, len);
+
326  }
+
327  return result;
+
328  }
+
329 
+
330 
+
332  void allocateFloatBuffer(int samples, bool allocate_out){
+
333  if (samples>buffer_allocated){
+
334  if (p_buffer[0]!=nullptr){
+
335  for (int j=0;j<cfg.channels;j++){
+
336  delete[]p_buffer[j];
+
337  p_buffer[j] = nullptr;
+
338  }
+
339  }
+
340  if (p_buffer_out!=nullptr && p_buffer_out[0]!=nullptr){
+
341  for (int j=0;j<cfg.channels;j++){
+
342  delete[]p_buffer_out[j];
+
343  p_buffer_out[j] = nullptr;
+
344  }
+
345  }
+
346  }
+
347  if (p_buffer[0]==nullptr){
+
348  const int ch = cfg.channels;
+
349  for (int j=0;j<ch;j++){
+
350  p_buffer[j] = new FAUSTFLOAT[samples];
+
351  }
+
352  buffer_allocated = samples;
+
353  }
+
354  if (allocate_out){
+
355  if (p_buffer_out[0]==nullptr){
+
356  const int ch = cfg.channels;
+
357  for (int j=0;j<ch;j++){
+
358  p_buffer_out[j] = new FAUSTFLOAT[samples];
+
359  }
+
360  }
+
361  }
+
362  }
+
363 
+
364  void deleteFloatBuffer() {
+
365  if (p_buffer!=nullptr) {
+
366  for (int j=0;j<cfg.channels;j++){
+
367  if (p_buffer[j]!=nullptr) delete p_buffer[j];
+
368  }
+
369  delete[] p_buffer;
+
370  p_buffer = nullptr;
+
371  }
+
372  if (p_buffer_out!=nullptr) {
+
373  for (int j=0;j<cfg.channels;j++){
+
374  if (p_buffer_out[j]!=nullptr) delete p_buffer_out[j];
+
375  }
+
376  delete[] p_buffer_out;
+
377  p_buffer_out = nullptr;
+
378  }
+
379  }
+
380 
+
381  FAUSTFLOAT noteToFrequency(uint8_t x) {
+
382  FAUSTFLOAT note = x;
+
383  return 440.0 * pow(2.0f, (note-69)/12);
+
384  }
385 
-
386 
-
387 } // namespace
+
386 };
+
387 
388 
-
389 
+
389 } // namespace
+
390 
+
391 
Minimum implementation of UI parameters. We only support the setting and getting of values.
Definition: AudioFaustDSP.h:51
virtual bool exists(const char *label)
checks if a label exists
Definition: AudioFaustDSP.h:129
Base class for all Audio Streams. It support the boolean operator to test if the object is ready with...
Definition: AudioStreams.h:47
@@ -445,16 +447,16 @@
size_t readBytes(uint8_t *data, size_t len) override
Used if FaustStream is used as audio source.
Definition: AudioFaust.h:116
FaustStream(Print &out, bool useSeparateOutputBuffer=true)
Constructor for Faust as Singal Processor - changing an input signal and sending it to out.
Definition: AudioFaust.h:24
FaustStream(bool useSeparateOutputBuffer=true)
Constructor for Faust as Audio Source.
Definition: AudioFaust.h:19
-
virtual FAUSTFLOAT labelValue(const char *label)
Determines the value of a parameter.
Definition: AudioFaust.h:171
-
void convertFloatBufferToInt(int samples, FAUSTFLOAT **p_float_in, void *data_out)
Converts the float buffer to int values.
Definition: AudioFaust.h:275
-
void convertIntBufferToFloat(int samples, void *data_in, FAUSTFLOAT **p_float_out)
Converts the int buffer to float values.
Definition: AudioFaust.h:295
-
bool checkChannels()
Checks the input and output channels and updates the is_write or is_read scenario flags.
Definition: AudioFaust.h:240
+
virtual FAUSTFLOAT labelValue(const char *label)
Determines the value of a parameter.
Definition: AudioFaust.h:172
+
void convertFloatBufferToInt(int samples, FAUSTFLOAT **p_float_in, void *data_out)
Converts the float buffer to int values.
Definition: AudioFaust.h:276
+
void convertIntBufferToFloat(int samples, void *data_in, FAUSTFLOAT **p_float_out)
Converts the int buffer to float values.
Definition: AudioFaust.h:296
+
bool checkChannels()
Checks the input and output channels and updates the is_write or is_read scenario flags.
Definition: AudioFaust.h:241
void end()
Ends the processing.
Definition: AudioFaust.h:103
-
size_t writeT(const uint8_t *write_data, size_t len)
Used if FaustStream is used as audio sink or filter.
Definition: AudioFaust.h:307
-
void allocateFloatBuffer(int samples, bool allocate_out)
Allocate the buffer that is needed by faust.
Definition: AudioFaust.h:330
+
size_t writeT(const uint8_t *write_data, size_t len)
Used if FaustStream is used as audio sink or filter.
Definition: AudioFaust.h:308
+
void allocateFloatBuffer(int samples, bool allocate_out)
Allocate the buffer that is needed by faust.
Definition: AudioFaust.h:332
bool begin(AudioInfo cfg)
Checks the parameters and starts the processing.
Definition: AudioFaust.h:54
size_t write(const uint8_t *write_data, size_t len) override
Used if FaustStream is used as audio sink or filter.
Definition: AudioFaust.h:146
-
virtual bool setLabelValue(const char *label, FAUSTFLOAT value)
Defines the value of a parameter.
Definition: AudioFaust.h:176
+
virtual bool setLabelValue(const char *label, FAUSTFLOAT value)
Defines the value of a parameter.
Definition: AudioFaust.h:177
static int64_t maxValue(int value_bits_per_sample)
provides the biggest number for the indicated number of bits
Definition: AudioTypes.h:241
Definition: NoArduino.h:51
Memory manager which uses psram when it is available.
Definition: AudioFaustDSP.h:180