Moved volume handling to internal configuration.

master
Holger Wirtz 6 years ago
parent b94ee150fc
commit 2a566a21df
  1. 40
      MicroMDAEPiano.ino
  2. 4
      config.h
  3. 4
      mdaEPiano.cpp
  4. 2
      mdaEPiano.h

@ -100,9 +100,6 @@ uint32_t xrun = 0;
uint32_t overload = 0;
uint32_t peak = 0;
uint16_t render_time_max = 0;
float vol = VOLUME;
float vol_right = 1.0;
float vol_left = 1.0;
elapsedMicros fill_audio_buffer;
elapsedMillis control_rate;
elapsedMillis autostore;
@ -197,7 +194,7 @@ void setup()
#endif
//set_volume(vol, vol_left, vol_right);
set_volume(1.0, 1.0, 1.0);
set_volume(1.0, 0.5);
#if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC)
// Initialize processor and memory measurements
@ -293,14 +290,6 @@ void loop()
peak++;
}
#ifndef TEENSY_AUDIO_BOARD
for (uint8_t i = 0; i < AUDIO_BLOCK_SAMPLES; i++)
{
audio_buffer_r[i] *= vol;
audio_buffer_l[i] *= vol;
}
#endif
queue_r.playBuffer();
queue_l.playBuffer();
}
@ -311,13 +300,9 @@ void loop()
if (control_rate > CONTROL_RATE_MS)
{
control_rate = 0;
}
}
//*************************************************************************************************
//* PROGRAM FUNCTIONS
//*************************************************************************************************
@ -446,9 +431,28 @@ bool checkMidiChannel(byte inChannel)
return (true);
}
void set_volume(float v, float vr, float vl)
void set_volume(float v, float p)
{
;
configuration.vol = v;
configuration.pan = p;
#ifdef DEBUG
Serial.print(F("Setting volume: VOL="));
Serial.print(v, DEC);
Serial.print(F("["));
Serial.print(configuration.vol, DEC);
Serial.print(F("] PAN="));
Serial.print(F("["));
Serial.print(configuration.pan, DEC);
Serial.print(F("] "));
Serial.print(pow(configuration.vol * sinf(configuration.pan * PI / 2), VOLUME_CURVE), 3);
Serial.print(F("/"));
Serial.println(pow(configuration.vol * cosf( configuration.pan * PI / 2), VOLUME_CURVE), 3);
#endif
// http://files.csound-tutorial.net/floss_manual/Release03/Cs_FM_03_ScrapBook/b-panning-and-spatialization.html
mixer_r.gain(0,sinf(p * PI / 2));
mixer_l.gain(0,cosf(p * PI / 2));
}
/******************************************************************************

@ -41,7 +41,7 @@
// AUDIO
// If nothing is defined PT8211 is used as audio output device!
//#define TEENSY_AUDIO_BOARD 1
#define TEENSY_AUDIO_BOARD 1
//#define TGA_AUDIO_BOARD 1
//*************************************************************************************************
@ -56,6 +56,7 @@
//*************************************************************************************************
#define VOLUME 0.8
#define VOLUME_CURVE 0.07
#define AUDIO_MEM 128
#define SAMPLE_RATE 44100
#define REDUCE_LOUDNESS 0
@ -75,6 +76,7 @@
//*************************************************************************************************
// Teensy Audio Shield:
#define SGTL5000_LINEOUT_LEVEL 29
//#define SDCARD_CS_PIN 10
//#define SDCARD_MOSI_PIN 7
//#define SDCARD_SCK_PIN 14

@ -240,8 +240,8 @@ void mdaEPiano::process(int16_t* outputs_r, int16_t* outputs_l)
l = 1.0;
else if (l < -1.0)
l = -1.0;
outputs_l[frame] = static_cast<int16_t>(l * vol * 0x7fff) >> REDUCE_LOUDNESS;
outputs_r[frame] = static_cast<int16_t>(r * vol * 0x7fff) >> REDUCE_LOUDNESS;
outputs_l[frame] = static_cast<int16_t>(l * configuration.vol * 0x7fff) >> REDUCE_LOUDNESS;
outputs_r[frame] = static_cast<int16_t>(r * configuration.vol * 0x7fff) >> REDUCE_LOUDNESS;
}
if (fabs(tl) < 1.0e-10) tl = 0.0f; //anti-denormal

@ -34,6 +34,8 @@
#define SILENCE 0.0001f //voice choking
#define WAVELEN 422414 //wave data bytes
extern config_t configuration;
class mdaEPianoProgram
{
friend class mdaEPiano;

Loading…
Cancel
Save