Adding mixer class - but it has some linking problems...

pull/85/head
Holger Wirtz 3 years ago
parent 82a49637b6
commit 97fb9ea5c6
  1. 2
      src/Makefile
  2. 134
      src/effect_mixer.cpp
  3. 74
      src/effect_mixer.h
  4. 42
      src/minidexed.cpp
  5. 4
      src/minidexed.h

@ -9,7 +9,7 @@ CMSIS_DIR = ../CMSIS_5/CMSIS
OBJS = main.o kernel.o minidexed.o config.o userinterface.o uimenu.o \ OBJS = main.o kernel.o minidexed.o config.o userinterface.o uimenu.o \
mididevice.o midikeyboard.o serialmididevice.o pckeyboard.o \ mididevice.o midikeyboard.o serialmididevice.o pckeyboard.o \
sysexfileloader.o performanceconfig.o perftimer.o \ sysexfileloader.o performanceconfig.o perftimer.o \
effect_platervbstereo.o effect_compressor.o effect_mixer.o effect_compressor.o effect_platervbstereo.o
include ./Synth_Dexed.mk include ./Synth_Dexed.mk
include ./Rules.mk include ./Rules.mk

@ -1,38 +1,22 @@
// Taken from https://github.com/manicken/Audio/tree/templateMixer // Taken from https://github.com/manicken/Audio/tree/templateMixer
// Adapted for MiniDexed by Holger Wirtz <dcoredump@googlemail.com> // Adapted for MiniDexed by Holger Wirtz <dcoredump@googlemail.com>
/* 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 <cstdlib> #include <cstdlib>
#include <stdint.h> #include <stdint.h>
#include <assert.h> #include <assert.h>
#include "arm_math.h" #include "arm_math.h"
#include "effect_mixer.h" #include "effect_mixer.h"
template <int NN> AudioMixer<NN>::AudioMixer(uint16_t len)
{
buffer_length=len;
for (uint8_t i=0; i<NN; i++)
multiplier[i] = UNITY_GAIN;
sumbufL=(float32_t*)malloc(sizeof(float32_t) * buffer_length);
arm_fill_f32(0.0, sumbufL, len);
}
template <int NN> void AudioMixer<NN>::gain(uint8_t channel, float32_t gain) template <int NN> void AudioMixer<NN>::gain(uint8_t channel, float32_t gain)
{ {
if (channel >= NN) return; if (channel >= NN) return;
@ -56,50 +40,108 @@ template <int NN> void AudioMixer<NN>::gain(float32_t gain)
} }
} }
template <int NN> void AudioMixer<NN>::doAddMix(uint8_t channel, float32_t* in, float32_t* out, uint16_t len) template <int NN> void AudioMixer<NN>::doAddMix(uint8_t channel, float32_t* in)
{ {
float32_t* tmp=malloc(sizeof(float32_t)*len); float32_t* tmp=malloc(sizeof(float32_t)*buffer_length);
assert(tmp!=NULL); assert(tmp!=NULL);
assert(in);
arm_scale_f32(in,multiplier[channel],tmp,len); if(multiplier[channel]!=UNITY_GAIN)
arm_add_f32(out, tmp, out, len); arm_scale_f32(in,multiplier[channel],tmp,buffer_length);
arm_add_f32(sumbufL, tmp, sumbufL, buffer_length);
if(sumbufL)
arm_fill_f32(0.0, sumbufL, buffer_length);
free(tmp); free(tmp);
} }
template <int NN> void AudioMixer<NN>::get_mix(float32_t* buffer, uint16_t len) template <int NN> void AudioMixer<NN>::getMix(float32_t* buffer)
{ {
assert(buffer); assert(buffer);
assert(sumbuf); assert(sumbufL);
arm_copy_f32 (sumbuf, buffer, len); arm_copy_f32(sumbufL, buffer, buffer_length);
} }
template <int NN> void AudioStereoMixer<NN>::doAddMix(uint8_t channel, float32_t* inL, float32_t* inR, float32_t* outL, float32_t* outR, uint16_t len) template <int NN> AudioStereoMixer<NN>::AudioStereoMixer(uint16_t len) : AudioMixer<NN>(len)
{ {
float32_t* tmp=malloc(sizeof(float32_t)*len); buffer_length=len;
for (uint8_t i=0; i<NN; i++)
panorama[i] = UNITY_PANORAMA;
assert(tmp!=NULL); sumbufR=(float32_t*)malloc(sizeof(float32_t) * buffer_length);
arm_fill_f32(0.0, sumbufR, buffer_length);
}
template <int NN> void AudioStereoMixer<NN>::pan(uint8_t channel, float32_t pan)
{
if (channel >= NN) return;
if (pan > MAX_PANORAMA)
pan = MAX_PANORAMA;
else if (pan < MIN_PANORAMA)
pan = MIN_PANORAMA;
panorama[channel] = pan;
}
// panorama template <int NN> void AudioStereoMixer<NN>::doAddMix(uint8_t channel, float32_t* in)
for(uint16_t i=0;i<len;i++)
{ {
float32_t* tmp=malloc(sizeof(float32_t)*buffer_length);
assert(tmp!=NULL);
assert(in);
// left // left
arm_scale_f32(inL,AudioMixer<NN>::multiplier[channel],tmp,len); arm_scale_f32(in, 1.0f-panorama[channel], tmp, buffer_length);
arm_add_f32(outL, tmp, outL, len); if(multiplier[channel]!=UNITY_GAIN)
arm_scale_f32(tmp,AudioMixer<NN>::multiplier[channel],tmp,buffer_length);
arm_add_f32(sumbufL, tmp, sumbufL, buffer_length);
// right // right
arm_scale_f32(inR,AudioMixer<NN>::multiplier[channel],tmp,len); arm_scale_f32(in, panorama[channel], tmp, buffer_length);
arm_add_f32(outR, tmp, outR, len); if(multiplier[channel]!=UNITY_GAIN)
arm_scale_f32(tmp,AudioMixer<NN>::multiplier[channel],tmp,buffer_length);
arm_add_f32(sumbufR, tmp, sumbufR, buffer_length);
if(sumbufL)
arm_fill_f32(0.0, sumbufL, buffer_length);
if(sumbufR)
arm_fill_f32(0.0, sumbufR, buffer_length);
free(tmp);
} }
template <int NN> void AudioStereoMixer<NN>::doAddMix(uint8_t channel, float32_t* inL, float32_t* inR)
{
float32_t* tmp=malloc(sizeof(float32_t)*buffer_length);
assert(tmp!=NULL);
assert(inL);
assert(inR);
// left
if(multiplier[channel]!=UNITY_GAIN)
arm_scale_f32(inL,AudioMixer<NN>::multiplier[channel],tmp,buffer_length);
arm_add_f32(sumbufL, tmp, sumbufL, buffer_length);
// right
if(multiplier[channel]!=UNITY_GAIN)
arm_scale_f32(inR,AudioMixer<NN>::multiplier[channel],tmp,buffer_length);
arm_add_f32(sumbufR, tmp, sumbufR, buffer_length);
if(sumbufL)
arm_fill_f32(0.0, sumbufL, buffer_length);
if(sumbufR)
arm_fill_f32(0.0, sumbufR, buffer_length);
free(tmp); free(tmp);
} }
template <int NN> void AudioMixer<NN>::get_mix(float32_t* bufferL, float32_t bufferL, uint16_t len) template <int NN> void AudioStereoMixer<NN>::getMix(float32_t* bufferL, float32_t* bufferR)
{ {
assert(bufferR); assert(bufferR);
assert(bufferL); assert(bufferL);
assert(sumbuf); assert(sumbufL);
arm_copy_f32 (sumbuf[0], bufferL, len); assert(sumbufR);
arm_copy_f32 (sumbuf[1], bufferR, len); arm_copy_f32 (sumbufL, bufferL, buffer_length);
arm_copy_f32 (sumbufR, bufferR, buffer_length);
} }

@ -1,87 +1,45 @@
// Taken from https://github.com/manicken/Audio/tree/templateMixer // Taken from https://github.com/manicken/Audio/tree/templateMixer
// Adapted for MiniDexed by Holger Wirtz <dcoredump@googlemail.com> // Adapted for MiniDexed by Holger Wirtz <dcoredump@googlemail.com>
/* 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 template_mixer_h_ #ifndef template_mixer_h_
#define template_mixer_h_ #define template_mixer_h_
#include "arm_math.h" #include "arm_math.h"
#include <stdint.h> #include <stdint.h>
#define UNITYGAIN 1.0f #define UNITY_GAIN 1.0f
#define MAX_GAIN 1.0f #define MAX_GAIN 1.0f
#define MIN_GAIN 0.0f #define MIN_GAIN 0.0f
#define UNITY_PANORAMA 1.0f
#define MAX_PANORAMA 1.0f
#define MIN_PANORAMA 0.0f
template <int NN> class AudioMixer template <int NN> class AudioMixer
{ {
public: public:
AudioMixer(uint16_t len) AudioMixer(uint16_t len);
{ void doAddMix(uint8_t channel, float32_t* in);
for (uint8_t i=0; i<NN; i++)
multiplier[i] = UNITYGAIN;
sumbufL=(float32_t*)malloc(sizeof(float32_t) * len);
arm_fill_f32(0.0, sumbufL, len);
};
void doAddMix(uint8_t channel, float32_t* in, uint16_t len);
/**
* this sets the individual gains
* @param channel
* @param gain
*/
void gain(uint8_t channel, float32_t gain); void gain(uint8_t channel, float32_t gain);
/**
* set all channels to specified gain
* @param gain
*/
void gain(float32_t gain); void gain(float32_t gain);
void get_mix(float32_t* buffer, uint16_t len); void getMix(float32_t* buffer);
protected: protected:
float32_t multiplier[NN]; float32_t multiplier[NN];
float32_t* sumbufL; float32_t* sumbufL;
uint16_t buffer_length;
}; };
template <int NN> class AudioStereoMixer : public AudioMixer<NN> template <int NN> class AudioStereoMixer : public AudioMixer<NN>
{ {
public: public:
AudioStereoMixer(uint16_t len) AudioStereoMixer(uint16_t len);
{ void pan(uint8_t channel, float32_t pan);
AudioMixer<NN>(len); void doAddMix(uint8_t channel, float32_t* in);
for (uint8_t i=0; i<NN; i++) void doAddMix(uint8_t channel, float32_t* inL, float32_t* inR);
panorama[i] = 0.0; void getMix(float32_t* bufferL, float32_t* bufferR);
sumbufR=(float32_t*)malloc(sizeof(float32_t) * len);
arm_fill_f32(0.0, sumbufR, len);
};
void doAddMix(uint8_t channel, float32_t* inL, float32_t* inR, uint16_t len);
void get_mix(float32_t* bufferL, float32_t* bufferR, uint16_t len);
protected: protected:
using AudioMixer<NN>::sumbufL;
using AudioMixer<NN>::multiplier;
using AudioMixer<NN>::buffer_length;
float32_t panorama[NN]; float32_t panorama[NN];
float32_t* sumbufR; float32_t* sumbufR;
}; };

@ -115,7 +115,7 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt,
#endif #endif
// BEGIN setup tg_mixer // BEGIN setup tg_mixer
//tg_mixer = new AudioStereoMixer<8>(pConfig->GetChunkSize()); tg_mixer = new AudioStereoMixer<8>(pConfig->GetChunkSize());
// END setup tgmixer // END setup tgmixer
// BEGIN setup reverb // BEGIN setup reverb
@ -748,7 +748,6 @@ void CMiniDexed::ProcessSound (void)
// //
// now mix the output of all TGs // now mix the output of all TGs
float32_t SampleBuffer[2][nFrames];
uint8_t indexL=0, indexR=1; uint8_t indexL=0, indexR=1;
if (m_bChannelsSwapped) if (m_bChannelsSwapped)
@ -757,41 +756,28 @@ void CMiniDexed::ProcessSound (void)
indexR=0; indexR=0;
} }
// init left sum output
assert (SampleBuffer[0]!=NULL);
arm_fill_f32(0.0, SampleBuffer[0], nFrames);
// init right sum output
assert (SampleBuffer[1]!=NULL);
arm_fill_f32(0.0, SampleBuffer[1], nFrames);
assert (CConfig::ToneGenerators == 8); assert (CConfig::ToneGenerators == 8);
// BEGIN stereo panorama and TG mixing // BEGIN stereo panorama and TG mixing
for (uint8_t i = 0; i < CConfig::ToneGenerators; i++) for (uint8_t i = 0; i < CConfig::ToneGenerators; i++)
{ {
float32_t tmpBuffer[2][nFrames]; tg_mixer->pan(i,m_fPan[i]);
tg_mixer->doAddMix(i,m_OutputLevel[i]);
assert (tmpBuffer[0]!=NULL);
arm_fill_f32(0.0, tmpBuffer[0], nFrames);
assert (tmpBuffer[1]!=NULL);
arm_fill_f32(0.0, tmpBuffer[1], nFrames);
m_PanoramaSpinLock.Acquire ();
// calculate left panorama of this TG
arm_scale_f32(m_OutputLevel[i], 1.0f-m_fPan[i], tmpBuffer[0], nFrames);
// add left panorama output of this TG to sum output
arm_add_f32(SampleBuffer[indexL], tmpBuffer[0], SampleBuffer[indexL], nFrames);
// calculate right panorama of this TG
arm_scale_f32(m_OutputLevel[i], m_fPan[i], tmpBuffer[1], nFrames);
// add right panaorama output of this TG to sum output
arm_add_f32(SampleBuffer[indexR], tmpBuffer[1], SampleBuffer[indexR], nFrames);
//tg_mixer->doAddMix(i,tmpBuffer[0],tmpBuffer[1],nFrames);
m_PanoramaSpinLock.Release ();
} }
// END stereo panorama and TG mixing // END stereo panorama and TG mixing
// BEGIN adding reverb // BEGIN adding reverb
float32_t SampleBuffer[2][nFrames];
// init left sum output
assert (SampleBuffer[0]!=NULL);
arm_fill_f32(0.0, SampleBuffer[0], nFrames);
// init right sum output
assert (SampleBuffer[1]!=NULL);
arm_fill_f32(0.0, SampleBuffer[1], nFrames);
tg_mixer->getMix(SampleBuffer[indexL], SampleBuffer[indexR]);
if (m_nParameter[ParameterReverbEnable]) if (m_nParameter[ParameterReverbEnable])
{ {
float32_t ReverbBuffer[2][nFrames]; float32_t ReverbBuffer[2][nFrames];

@ -42,7 +42,7 @@
#include "common.h" #include "common.h"
#include "effect_platervbstereo.h" #include "effect_platervbstereo.h"
#include "effect_compressor.h" #include "effect_compressor.h"
//#include "effect_mixer.h" #include "effect_mixer.h"
class CMiniDexed class CMiniDexed
#ifdef ARM_ALLOW_MULTI_CORE #ifdef ARM_ALLOW_MULTI_CORE
@ -176,7 +176,7 @@ private:
bool m_bProfileEnabled; bool m_bProfileEnabled;
AudioEffectPlateReverb* reverb; AudioEffectPlateReverb* reverb;
//AudioStereoMixer<8>* tg_mixer; AudioStereoMixer<8>* tg_mixer;
CSpinLock m_PanoramaSpinLock; CSpinLock m_PanoramaSpinLock;
CSpinLock m_ReverbSpinLock; CSpinLock m_ReverbSpinLock;

Loading…
Cancel
Save