Add files via upload

master
DragonSifu 7 years ago committed by GitHub
parent c57604163c
commit 4f7edfcc61
  1. 29
      OpenAudio_ArduinoLibrary.h
  2. 107
      filter_moog_f32.cpp
  3. 92
      filter_moog_f32.h
  4. 81
      synth_dc_f32.cpp
  5. 99
      synth_dc_f32.h

@ -0,0 +1,29 @@
#include <AudioStream_F32.h>
#include <AudioControlSGTL5000_Extended.h>
#include <control_tlv320aic3206.h>
#include "AudioCalcEnvelope_F32.h"
#include "AudioCalcGainWDRC_F32.h"
#include "AudioConfigFIRFilterBank_F32.h"
#include "AudioControlTester.h"
#include "AudioConvert_F32.h"
#include "AudioEffectCompressor_F32.h"
#include "AudioEffectCompWDRC_F32.h"
#include "AudioEffectEmpty_F32.h"
#include "AudioEffectGain_F32.h"
#include "AudioFilterBiquad_F32.h"
#include <AudioFilterFIR_F32.h>
#include <AudioFilterIIR_F32.h>
#include "AudioMixer_F32.h"
#include "AudioMultiply_F32.h"
#include "AudioSettings_F32.h"
#include "input_i2s_f32.h"
#include "output_i2s_f32.h"
#include "play_queue_f32.h"
#include "record_queue_f32.h"
#include "filter_moog_f32.h"
#include "synth_pinknoise_f32.h"
#include "synth_sine_f32.h"
#include "synth_waveform_F32.h"
#include "synth_dc_f32.h"
#include "synth_whitenoise_f32.h"

@ -0,0 +1,107 @@
/* Audio Library for Teensy 3.X
* Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com
*
* Development of this audio library was funded by PJRC.COM, LLC by sales of
* Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop
* open source software by purchasing Teensy or other PJRC products.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice, development funding notice, and this permission
* notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "filter_moog_f32.h"
#if defined(KINETISK)
void AudioFilterMoog_F32::update_fixed(const float *in,float *lp)
{
for (int i = 0; i < 2*AUDIO_BLOCK_SAMPLES; i++) {
float cs = tanhf(in[i/2] * driv);
y_a = y_a + g * (tanhf(cs - q * ((y_d_1 + y_d)/2) - tanhf(y_a)));
y_b = y_b + g * (tanhf(y_a) - tanhf(y_b));
y_c = y_c + g * (tanhf(y_b) - tanhf(y_c));
y_d_1 = y_d;
y_d = y_d + g * (tanhf(y_c) - tanhf(y_d));
lp[i/2] = y_d;
}
}
void AudioFilterMoog_F32::update_variable(const float *in,const float *ctl, float *lp)
{
int over=2;
float nf=basef*(exp2f(ctl[0/over]*oct));
frequency(nf,false);
for (int i = 0; i < 2*AUDIO_BLOCK_SAMPLES; i++) {
float cs = tanhf(in[i/over] * driv);
y_a = y_a + g * (tanhf(cs - q * ((y_d_1 + y_d)/2) - tanhf(y_a)));
y_b = y_b + g * (tanhf(y_a) - tanhf(y_b));
y_c = y_c + g * (tanhf(y_b) - tanhf(y_c));
y_d_1 = y_d;
y_d = y_d + g * (tanhf(y_c) - tanhf(y_d));
lp[i/over] = y_d;
}
}
void AudioFilterMoog_F32::update(void)
{
audio_block_f32_t *input_block=NULL, *control_block=NULL;
audio_block_f32_t *lowpass_block=NULL;
input_block = receiveReadOnly_f32(0);
control_block = receiveReadOnly_f32(1);
if (!input_block) {
if (control_block) release(control_block);
return;
}
lowpass_block = allocate_f32();
if (!lowpass_block) {
release(input_block);
if (control_block) release(control_block);
return;
}
if (control_block) {
update_variable(input_block->data, control_block->data, lowpass_block->data);
release(control_block);
} else {
update_fixed(input_block->data, lowpass_block->data);
}
AudioStream_F32::release(input_block);
AudioStream_F32::transmit(lowpass_block, 0);
AudioStream_F32::release(lowpass_block);
return;
}
#elif defined(KINETISL)
void AudioFilterMoog_F32::update(void)
{
audio_block_f32_t *block;
block = receiveReadOnly_f32(0);
if (block) AudioStream_F32::release(block);
block = receiveReadOnly_f32(1);
if (block) AudioStream_F32::release(block);
}
#endif

@ -0,0 +1,92 @@
/* Audio Library for Teensy 3.X
* Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com
*
* Development of this audio library was funded by PJRC.COM, LLC by sales of
* Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop
* open source software by purchasing Teensy or other PJRC products.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice, development funding notice, and this permission
* notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef filter_moog_f32_h_
#define filter_moog_f32_h_
#include "Arduino.h"
#include "AudioStream_f32.h"
#include "utility/dspinst.h"
#include "arm_math.h"
class AudioFilterMoog_F32: public AudioStream_F32
{
float g;
float q;
float driv;
float oct;
float basef;
float y_a;
float y_b;
float y_c;
float y_d;
float y_d_1;
public:
AudioFilterMoog_F32() : AudioStream_F32(2, inputQueueArray) {
frequency(1000);
resonance(1);
drive(1);
octave(1);
y_a = 0;
y_b = 0;
y_c = 0;
y_d = 0;
y_d_1 = 0;
}
void frequency(float freq,bool setf=true) {
if (freq < 20.0) freq = 20.0;
else if (freq > AUDIO_SAMPLE_RATE_EXACT/2.5) freq = AUDIO_SAMPLE_RATE_EXACT/2.5;
g = 1 - expf(-2 * tanf(2 * M_PI * freq/(2 * AUDIO_SAMPLE_RATE_EXACT)));
// Serial.println(freq);
if(setf)
basef=freq;
}
void resonance(float qi) {
if (qi < 0.7) qi = 0.7;
else if (qi > 5.0) qi = 5.0;
q=qi;
}
void octave(float n) {
if (n < 0.0) n = 0.0;
else if (n > 6.9999) n = 6.9999;
oct=n;
}
void drive(float d) {
if (d > 10.0f) d = 10.0f;
if (d < 0.1f) d = 0.1f;
driv = d;
}
virtual void update(void);
private:
void update_fixed(const float *in,float *lp);
void update_variable(const float *in, const float *ctl, float *lp);
audio_block_f32_t *inputQueueArray[2];
};
#endif

@ -0,0 +1,81 @@
/* Audio Library for Teensy 3.X
* Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com
*
* Development of this audio library was funded by PJRC.COM, LLC by sales of
* Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop
* open source software by purchasing Teensy or other PJRC products.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice, development funding notice, and this permission
* notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "synth_dc_f32.h"
void AudioSynthWaveformDc_F32::update(void)
{
audio_block_f32_t *block;
float *p, *end;
float count;
block = allocate_f32();
if (!block) return;
// inc = allocate_f32();
// if (!inc) return;
uint32_t block_length = (uint32_t)block->length;
p = (float *)(block->data);
end = p + AUDIO_BLOCK_SAMPLES;
if (state == 0) {
// steady DC output, simply fill the buffer with fixed value
arm_fill_f32(magnitude,p,block_length);
} else {
// transitioning to a new DC level
//count = (target - magnitude) / increment;
count = (target-magnitude)/ increment;
// Serial.println(count);
// Serial.println(target);
if (count >= AUDIO_BLOCK_SAMPLES) {
// this update will not reach the target
// arm_scale_f32(incblock->data,increment,inc->data,AUDIO_BLOCK_SAMPLES);
// arm_offset_f32(inc->data,magnitude,p,AUDIO_BLOCK_SAMPLES);
do {
magnitude += increment;
*p++ = magnitude;
} while (p < end);
} else {
// this update reaches the target
while (count >= 0) {
count --;
magnitude += increment;
*p++ = magnitude;
}
magnitude = target;
state = 0;
if(p < end) {
arm_fill_f32(magnitude,p,end-p);
// Serial.println(end-p);
}
}
}
AudioStream_F32::transmit(block);
AudioStream_F32::release(block);
}

@ -0,0 +1,99 @@
/* Audio Library for Teensy 3.X
* Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com
*
* Development of this audio library was funded by PJRC.COM, LLC by sales of
* Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop
* open source software by purchasing Teensy or other PJRC products.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice, development funding notice, and this permission
* notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef synth_dc_f32_h_
#define synth_dc_f32_h_
#include "Arduino.h"
#include "AudioStream_f32.h"
#include "utility/dspinst.h"
#include "arm_math.h"
// compute (a - b) / c
// handling 32 bit interger overflow at every step
// without resorting to slow 64 bit math
class AudioSynthWaveformDc_F32 : public AudioStream_F32
{
public:
AudioSynthWaveformDc_F32() : AudioStream_F32(0, NULL), state(0), magnitude(0) {}
// immediately jump to the new DC level
void amplitude(float n) {
if (n > 1.0) n = 1.0;
else if (n < -1.0) n = -1.0;
// int i;
// int32_t m = (int32_t)(n * 0x7fff);
__disable_irq();
magnitude = n;
state = 0;
// incblock = allocate_f32();
// for(i=0;i<AUDIO_BLOCK_SAMPLES;i++)
// incblock->data[i]=i+1;
__enable_irq();
}
// slowly transition to the new DC level
void amplitude(float n, float milliseconds) {
if (milliseconds <= 0.0) {
amplitude(n);
return;
}
if (n > 1.0) n = 1.0;
else if (n < -1.0) n = -1.0;
float c = (milliseconds*(AUDIO_SAMPLE_RATE_EXACT/1000.0));
if (c == 0) {
amplitude(n);
return;
}
// int32_t t = (int32_t)(n * 0x7fff);
__disable_irq();
target = n;
if (target == magnitude) {
state = 0;
__enable_irq();
return;
}
increment = (target-magnitude)/ c;
if (increment == 0) {
increment = (target > magnitude) ? 1 : -1;
}
state = 1;
__enable_irq();
}
float read(void) {
return magnitude;
}
virtual void update(void);
private:
uint8_t state; // 0=steady output, 1=transitioning
float magnitude; // current output
float target; // designed output (while transitiong)
float increment; // adjustment per sample (while transitiong)
// audio_block_f32_t *incblock;
};
#endif
Loading…
Cancel
Save