From 92442b5699b03791afd63d4517b08eb14b888bb0 Mon Sep 17 00:00:00 2001 From: boblark Date: Thu, 9 Mar 2023 19:50:06 -0800 Subject: [PATCH] Add AudioMathConstant_F32 --- AudioMathConstant_F32.cpp | 13 +++++++++++++ AudioMathConstant_F32.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 AudioMathConstant_F32.cpp create mode 100644 AudioMathConstant_F32.h diff --git a/AudioMathConstant_F32.cpp b/AudioMathConstant_F32.cpp new file mode 100644 index 0000000..897d652 --- /dev/null +++ b/AudioMathConstant_F32.cpp @@ -0,0 +1,13 @@ +#include "AudioMathConstant_F32.h" + +void AudioMathConstant_F32::update(void) { + audio_block_f32_t *block; + + block = AudioStream_F32::allocate_f32(); + if (!block) return; + + for(int i=0; i<128; i++) + block->data[i] = constant; + AudioStream_F32::transmit(block); + AudioStream_F32::release(block); + } diff --git a/AudioMathConstant_F32.h b/AudioMathConstant_F32.h new file mode 100644 index 0000000..125f891 --- /dev/null +++ b/AudioMathConstant_F32.h @@ -0,0 +1,36 @@ +/* + * AudioMathConstant_F32 + * + * Created: Bob Larkin, March 2023 + * Purpose: Outputs a block of floating point numbers, all the same. + * Default value is 0.0f + * + * This outputs a single, constant stream of audio data (ie, it is mono) + * + * MIT License. use at your own risk. +*/ +#ifndef _AudioMathConstant_F32_H +#define _AudioMathConstant_F32_H + +#include "AudioStream_F32.h" + +class AudioMathConstant_F32 : public AudioStream_F32 +{ + //GUI: inputs:0, outputs:1 //this line used for automatic generation of GUI node + public: + AudioMathConstant_F32(void) : AudioStream_F32(0, NULL) {}; + AudioMathConstant_F32(const AudioSettings_F32 &settings) : AudioStream_F32(0, NULL) { + sample_rate_Hz = settings.sample_rate_Hz; + block_size = settings.audio_block_samples; + }; + + void setConstant(float32_t _constant) { constant = _constant; } + + virtual void update(void); + + private: + float sample_rate_Hz = AUDIO_SAMPLE_RATE; + uint16_t block_size = AUDIO_BLOCK_SAMPLES; + float32_t constant = 0.0f; +}; +#endif