You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.2 KiB
114 lines
3.2 KiB
5 years ago
|
/*
|
||
3 years ago
|
Copyright (c) 2018-2022 H. Wirtz
|
||
5 years ago
|
|
||
|
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>
|
||
5 years ago
|
#include "limits.h"
|
||
5 years ago
|
#include "effect_mono_stereo.h"
|
||
5 years ago
|
|
||
|
/*************************************************************************/
|
||
5 years ago
|
// A u d i o E f f e c t M o n o S t e r e o
|
||
5 years ago
|
// Written by Holger Wirtz
|
||
5 years ago
|
// 20191122 - initial version
|
||
5 years ago
|
|
||
3 years ago
|
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
|
||
|
}
|
||
|
};
|
||
|
|
||
3 years ago
|
#ifndef _MAPFLOAT
|
||
5 years ago
|
#define _MAPFLOAT
|
||
|
inline float mapfloat(float val, float in_min, float in_max, float out_min, float out_max)
|
||
5 years ago
|
{
|
||
5 years ago
|
return (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||
5 years ago
|
}
|
||
5 years ago
|
#endif
|
||
5 years ago
|
|
||
5 years ago
|
void AudioEffectMonoStereo::panorama(float p)
|
||
|
{
|
||
4 years ago
|
pan = mapfloat(p, -1.0, 1.0, 1.0, 0.0);
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
void AudioEffectMonoStereo::update(void)
|
||
5 years ago
|
{
|
||
|
audio_block_t *in;
|
||
|
audio_block_t *out[2];
|
||
|
|
||
|
in = receiveReadOnly(0);
|
||
3 years ago
|
if (!in)
|
||
3 years ago
|
in = (audio_block_t*)&zeroblock;
|
||
5 years ago
|
|
||
5 years ago
|
out[0] = allocate();
|
||
|
out[1] = allocate();
|
||
|
|
||
5 years ago
|
if (in && out[0] && out[1])
|
||
5 years ago
|
{
|
||
5 years ago
|
arm_q15_to_float(in->data, in_f, AUDIO_BLOCK_SAMPLES);
|
||
5 years ago
|
|
||
5 years ago
|
float fsin = arm_sin_f32(pan * PI / 2.0);
|
||
|
float fcos = arm_cos_f32(pan * PI / 2.0);
|
||
|
int16_t* out_p[2] = {&out[0]->data[0], &out[1]->data[0]};
|
||
5 years ago
|
for (uint8_t n = 0; n < AUDIO_BLOCK_SAMPLES; n++)
|
||
5 years ago
|
{
|
||
5 years ago
|
*out_p[0]++ = int16_t(in_f[n] * _pseudo_log * fsin * SHRT_MAX);
|
||
|
*out_p[1]++ = int16_t(in_f[n] * _pseudo_log * fcos * SHRT_MAX);
|
||
5 years ago
|
}
|
||
3 years ago
|
}
|
||
5 years ago
|
|
||
3 years ago
|
if (in != (audio_block_t*)&zeroblock)
|
||
|
{
|
||
|
release(in);
|
||
|
}
|
||
|
if (out[0])
|
||
|
{
|
||
|
transmit(out[0], 0);
|
||
|
release(out[0]);
|
||
|
}
|
||
|
if (out[1])
|
||
|
{
|
||
|
transmit(out[1], 1);
|
||
|
release(out[1]);
|
||
5 years ago
|
}
|
||
|
}
|