parent
213160d30f
commit
9a78c14a76
@ -1,114 +0,0 @@ |
|||||||
/*
|
|
||||||
Copyright (c) 2019-2021 H. Wirtz |
|
||||||
|
|
||||||
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 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 <Arduino.h> |
|
||||||
#include <Audio.h> |
|
||||||
#include "effect_auto_pan.h" |
|
||||||
|
|
||||||
/*************************************************************************/ |
|
||||||
// A u d i o E f f e c t A u t o P a n
|
|
||||||
// Written by Holger Wirtz
|
|
||||||
// 20191205 - initial version
|
|
||||||
|
|
||||||
static const audio_block_t zeroblock = { |
|
||||||
0, 0, 0, { |
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
||||||
#if AUDIO_BLOCK_SAMPLES > 16 |
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
||||||
#endif |
|
||||||
#if AUDIO_BLOCK_SAMPLES > 32 |
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
||||||
#endif |
|
||||||
#if AUDIO_BLOCK_SAMPLES > 48 |
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
||||||
#endif |
|
||||||
#if AUDIO_BLOCK_SAMPLES > 64 |
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
||||||
#endif |
|
||||||
#if AUDIO_BLOCK_SAMPLES > 80 |
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
||||||
#endif |
|
||||||
#if AUDIO_BLOCK_SAMPLES > 96 |
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
||||||
#endif |
|
||||||
#if AUDIO_BLOCK_SAMPLES > 112 |
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
||||||
#endif |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
void AudioEffectAutoPan::update(void) |
|
||||||
{ |
|
||||||
audio_block_t *in; |
|
||||||
audio_block_t *mod; |
|
||||||
audio_block_t *out[2]; |
|
||||||
|
|
||||||
in = receiveReadOnly(0); |
|
||||||
if (!in) |
|
||||||
in = (audio_block_t*)&zeroblock; |
|
||||||
|
|
||||||
mod = receiveReadOnly(1); |
|
||||||
if (!mod) |
|
||||||
mod = (audio_block_t*)&zeroblock; |
|
||||||
|
|
||||||
out[0] = allocate(); |
|
||||||
out[1] = allocate(); |
|
||||||
|
|
||||||
if (in && mod && out[0] && out[1]) |
|
||||||
{ |
|
||||||
arm_q15_to_float(in->data, in_f, AUDIO_BLOCK_SAMPLES); |
|
||||||
arm_q15_to_float(mod->data, pan_f, AUDIO_BLOCK_SAMPLES); |
|
||||||
arm_offset_f32(pan_f, 1.0, pan_f, AUDIO_BLOCK_SAMPLES); |
|
||||||
arm_scale_f32(pan_f, PI / 4.0, pan_f, AUDIO_BLOCK_SAMPLES); // PI/4
|
|
||||||
|
|
||||||
// right
|
|
||||||
for (uint8_t n = 0; n < AUDIO_BLOCK_SAMPLES; n++) |
|
||||||
out_f[0][n] = in_f[n] * _pseudo_log * arm_sin_f32(pan_f[n]); |
|
||||||
arm_float_to_q15 (out_f[0], out[0]->data, AUDIO_BLOCK_SAMPLES); |
|
||||||
// left
|
|
||||||
for (uint8_t n = 0; n < AUDIO_BLOCK_SAMPLES; n++) |
|
||||||
out_f[1][n] = in_f[n] * _pseudo_log * arm_cos_f32(pan_f[n]); |
|
||||||
arm_float_to_q15 (out_f[1], out[1]->data, AUDIO_BLOCK_SAMPLES); |
|
||||||
|
|
||||||
if (in) |
|
||||||
{ |
|
||||||
release(in); |
|
||||||
} |
|
||||||
if (in != (audio_block_t*)&zeroblock) |
|
||||||
{ |
|
||||||
release(in); |
|
||||||
} |
|
||||||
if (mod != (audio_block_t*)&zeroblock) |
|
||||||
{ |
|
||||||
release(mod); |
|
||||||
} |
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 2; i++) |
|
||||||
{ |
|
||||||
if (out[i]) |
|
||||||
{ |
|
||||||
transmit(out[i], i); |
|
||||||
release(out[i]); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,54 +0,0 @@ |
|||||||
/*
|
|
||||||
Copyright (c) 2019-2021 H. Wirtz |
|
||||||
|
|
||||||
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 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 effect_auto_pan_h_ |
|
||||||
#define effect_auto_pan_h_ |
|
||||||
|
|
||||||
#include "Arduino.h" |
|
||||||
#include "AudioStream.h" |
|
||||||
|
|
||||||
/*************************************************************************/ |
|
||||||
// A u d i o E f f e c t A u t o P a n
|
|
||||||
// Written by Holger Wirtz
|
|
||||||
// 20191205 - inital version
|
|
||||||
|
|
||||||
class AudioEffectAutoPan : public AudioStream |
|
||||||
{ |
|
||||||
public: |
|
||||||
AudioEffectAutoPan(void): |
|
||||||
AudioStream(2, inputQueueArray) |
|
||||||
{ |
|
||||||
; |
|
||||||
} |
|
||||||
|
|
||||||
virtual void update(void); |
|
||||||
|
|
||||||
private: |
|
||||||
audio_block_t *inputQueueArray[2]; |
|
||||||
audio_block_t *out[2]; |
|
||||||
float in_f[AUDIO_BLOCK_SAMPLES]; |
|
||||||
float out_f[2][AUDIO_BLOCK_SAMPLES]; |
|
||||||
float pan_f[AUDIO_BLOCK_SAMPLES]; |
|
||||||
const float _pseudo_log = 1048575 / (float)(1 << 20); |
|
||||||
}; |
|
||||||
|
|
||||||
#endif |
|
@ -1,2 +0,0 @@ |
|||||||
#pragma once |
|
||||||
#include <Arduino.h> |
|
Loading…
Reference in new issue