Fixed stereo panning.

pull/112/head
Holger Wirtz 3 years ago
parent 6532d29d85
commit 89cd9cf069
  1. 2
      MicroDexed.ino
  2. 29
      effect_stereo_panorama.cpp
  3. 7
      effect_stereo_panorama.h

@ -5,7 +5,7 @@
Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android
(c)2018-2021 H. Wirtz <wirtz@parasitstudio.de>
M. Koslowski <positionhigh@gmx.de>
(c)2021 M. Koslowski <positionhigh@gmx.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

@ -68,7 +68,19 @@ inline float mapfloat(float val, float in_min, float in_max, float out_min, floa
void AudioEffectStereoPanorama::panorama(float p)
{
pan = mapfloat(p, -1.0, 1.0, 1.0, 0.0);
//pan = mapfloat(p, -1.0, 1.0, 1.0, 0.0);
if (p == 0.5)
pan_l = pan_r = 1.0;
else if (p > 0.5)
{
pan_r = 0.5 - abs(0.5 - p);
pan_l = 1.0 - pan_r;
}
else
{
pan_l = 0.5 - abs(0.5 - p);
pan_r = 1.0 - p;
}
}
void AudioEffectStereoPanorama::update(void)
@ -92,17 +104,16 @@ void AudioEffectStereoPanorama::update(void)
arm_q15_to_float(in[0]->data, in_f[0], AUDIO_BLOCK_SAMPLES);
arm_q15_to_float(in[1]->data, in_f[1], AUDIO_BLOCK_SAMPLES);
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]};
for (uint16_t n = 0; n < AUDIO_BLOCK_SAMPLES; n++)
{
out_p[0][n] = int16_t(in_f[0][n] * _pseudo_log * fsin * SHRT_MAX);
out_p[1][n] = int16_t(in_f[1][n] * _pseudo_log * fcos * SHRT_MAX);
out_p[0][n] = int16_t(in_f[0][n] * _pseudo_log * fcos * SHRT_MAX);
out_p[1][n] = int16_t(in_f[1][n] * _pseudo_log * fsin * SHRT_MAX);
out_f[0][n] = in_f[0][n] * pan_r;
out_f[0][n] += in_f[1][n] * pan_l;
out_f[1][n] = in_f[1][n] * pan_r;
out_f[1][n] += in_f[0][n] * pan_l;
}
arm_float_to_q15(out_f[0], out[0]->data, AUDIO_BLOCK_SAMPLES);
arm_float_to_q15(out_f[1], out[1]->data, AUDIO_BLOCK_SAMPLES);
}
if (in[0] != (audio_block_t*)&zeroblock)

@ -35,7 +35,8 @@ class AudioEffectStereoPanorama : public AudioStream
AudioEffectStereoPanorama(void):
AudioStream(1, inputQueueArray)
{
pan = 0.5;
pan_l = 1.0;
pan_r = 1.0;
}
virtual void update(void);
@ -45,7 +46,9 @@ class AudioEffectStereoPanorama : public AudioStream
audio_block_t *inputQueueArray[2];
audio_block_t *out[2];
float in_f[2][AUDIO_BLOCK_SAMPLES];
float pan;
float out_f[2][AUDIO_BLOCK_SAMPLES];
float pan_l;
float pan_r;
const float _pseudo_log = 1048575 / (float)(1 << 20);
};

Loading…
Cancel
Save