@ -125,6 +125,8 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt,
}
# endif
setMasterVolume ( 1.0 ) ;
// BEGIN setup tg_mixer
tg_mixer = new AudioStereoMixer < CConfig : : ToneGenerators > ( pConfig - > GetChunkSize ( ) / 2 ) ;
// END setup tgmixer
@ -371,6 +373,7 @@ void CMiniDexed::ProgramChange (unsigned nProgram, unsigned nTG)
assert ( m_pTG [ nTG ] ) ;
m_pTG [ nTG ] - > loadVoiceParameters ( Buffer ) ;
m_SerialMIDI . SendSystemExclusiveVoice ( nProgram , 0 , nTG ) ;
m_UI . ParameterChanged ( ) ;
}
@ -875,56 +878,70 @@ void CMiniDexed::ProcessSound (void)
}
// BEGIN TG mixing
for ( uint8_t i = 0 ; i < CConfig : : ToneGenerators ; i + + )
{
tg_mixer - > doAddMix ( i , m_OutputLevel [ i ] ) ;
reverb_send_mixer - > doAddMix ( i , m_OutputLevel [ i ] ) ;
}
// END TG mixing
// BEGIN create SampleBuffer for holding audio data
float32_t SampleBuffer [ 2 ] [ nFrames ] ;
// END create SampleBuffer for holding audio data
// get the mix of all TGs
tg_mixer - > getMix ( SampleBuffer [ indexL ] , SampleBuffer [ indexR ] ) ;
float32_t tmp_float [ nFrames * 2 ] ;
int16_t tmp_int [ nFrames * 2 ] ;
// BEGIN adding reverb
if ( m_nParameter [ ParameterReverbEnable ] )
if ( nMasterVolume > 0.0 )
{
float32_t ReverbBuffer [ 2 ] [ nFrames ] ;
float32_t ReverbSendBuffer [ 2 ] [ nFrames ] ;
arm_fill_f32 ( 0.0f , ReverbBuffer [ indexL ] , nFrames ) ;
arm_fill_f32 ( 0.0f , ReverbBuffer [ indexR ] , nFrames ) ;
arm_fill_f32 ( 0.0f , ReverbSendBuffer [ indexR ] , nFrames ) ;
arm_fill_f32 ( 0.0f , ReverbSendBuffer [ indexL ] , nFrames ) ;
m_ReverbSpinLock . Acquire ( ) ;
reverb_send_mixer - > getMix ( ReverbSendBuffer [ indexL ] , ReverbSendBuffer [ indexR ] ) ;
reverb - > doReverb ( ReverbSendBuffer [ indexL ] , ReverbSendBuffer [ indexR ] , ReverbBuffer [ indexL ] , ReverbBuffer [ indexR ] , nFrames ) ;
for ( uint8_t i = 0 ; i < CConfig : : ToneGenerators ; i + + )
{
tg_mixer - > doAddMix ( i , m_OutputLevel [ i ] ) ;
reverb_send_mixer - > doAddMix ( i , m_OutputLevel [ i ] ) ;
}
// END TG mixing
// BEGIN create SampleBuffer for holding audio data
float32_t SampleBuffer [ 2 ] [ nFrames ] ;
// END create SampleBuffer for holding audio data
// scale down and add left reverb buffer by reverb level
arm_scale_f32 ( ReverbBuffer [ indexL ] , reverb - > get_level ( ) , ReverbBuffer [ indexL ] , nFrames ) ;
arm_add_f32 ( SampleBuffer [ indexL ] , ReverbBuffer [ indexL ] , SampleBuffer [ indexL ] , nFrames ) ;
// scale down and add right reverb buffer by reverb level
arm_scale_f32 ( ReverbBuffer [ indexR ] , reverb - > get_level ( ) , ReverbBuffer [ indexR ] , nFrames ) ;
arm_add_f32 ( SampleBuffer [ indexR ] , ReverbBuffer [ indexR ] , SampleBuffer [ indexR ] , nFrames ) ;
// get the mix of all TGs
tg_mixer - > getMix ( SampleBuffer [ indexL ] , SampleBuffer [ indexR ] ) ;
m_ReverbSpinLock . Release ( ) ;
}
// END adding reverb
// BEGIN adding reverb
if ( m_nParameter [ ParameterReverbEnable ] )
{
float32_t ReverbBuffer [ 2 ] [ nFrames ] ;
float32_t ReverbSendBuffer [ 2 ] [ nFrames ] ;
// Convert dual float array (left, right) to single int16 array (left/right)
float32_t tmp_float [ nFrames * 2 ] ;
int16_t tmp_int [ nFrames * 2 ] ;
for ( uint16_t i = 0 ; i < nFrames ; i + + )
{
tmp_float [ i * 2 ] = SampleBuffer [ indexL ] [ i ] ;
tmp_float [ ( i * 2 ) + 1 ] = SampleBuffer [ indexR ] [ i ] ;
arm_fill_f32 ( 0.0f , ReverbBuffer [ indexL ] , nFrames ) ;
arm_fill_f32 ( 0.0f , ReverbBuffer [ indexR ] , nFrames ) ;
arm_fill_f32 ( 0.0f , ReverbSendBuffer [ indexR ] , nFrames ) ;
arm_fill_f32 ( 0.0f , ReverbSendBuffer [ indexL ] , nFrames ) ;
m_ReverbSpinLock . Acquire ( ) ;
reverb_send_mixer - > getMix ( ReverbSendBuffer [ indexL ] , ReverbSendBuffer [ indexR ] ) ;
reverb - > doReverb ( ReverbSendBuffer [ indexL ] , ReverbSendBuffer [ indexR ] , ReverbBuffer [ indexL ] , ReverbBuffer [ indexR ] , nFrames ) ;
// scale down and add left reverb buffer by reverb level
arm_scale_f32 ( ReverbBuffer [ indexL ] , reverb - > get_level ( ) , ReverbBuffer [ indexL ] , nFrames ) ;
arm_add_f32 ( SampleBuffer [ indexL ] , ReverbBuffer [ indexL ] , SampleBuffer [ indexL ] , nFrames ) ;
// scale down and add right reverb buffer by reverb level
arm_scale_f32 ( ReverbBuffer [ indexR ] , reverb - > get_level ( ) , ReverbBuffer [ indexR ] , nFrames ) ;
arm_add_f32 ( SampleBuffer [ indexR ] , ReverbBuffer [ indexR ] , SampleBuffer [ indexR ] , nFrames ) ;
m_ReverbSpinLock . Release ( ) ;
}
// END adding reverb
// Convert dual float array (left, right) to single int16 array (left/right)
for ( uint16_t i = 0 ; i < nFrames ; i + + )
{
if ( nMasterVolume > 0.0 & & nMasterVolume < 1.0 )
{
tmp_float [ i * 2 ] = SampleBuffer [ indexL ] [ i ] * nMasterVolume ;
tmp_float [ ( i * 2 ) + 1 ] = SampleBuffer [ indexR ] [ i ] * nMasterVolume ;
}
else if ( nMasterVolume = = 1.0 )
{
tmp_float [ i * 2 ] = SampleBuffer [ indexL ] [ i ] ;
tmp_float [ ( i * 2 ) + 1 ] = SampleBuffer [ indexR ] [ i ] ;
}
}
arm_float_to_q15 ( tmp_float , tmp_int , nFrames * 2 ) ;
}
arm_float_to_q15 ( tmp_float , tmp_int , nFrames * 2 ) ;
else
arm_fill_q15 ( 0 , tmp_int , nFrames * 2 ) ;
if ( m_pSoundDevice - > Write ( tmp_int , sizeof ( tmp_int ) ) ! = ( int ) sizeof ( tmp_int ) )
{
@ -1168,5 +1185,44 @@ void CMiniDexed::setVoiceDataElement(uint8_t data, uint8_t number, uint8_t nTG)
int16_t CMiniDexed : : checkSystemExclusive ( const uint8_t * pMessage , const uint16_t nLength , uint8_t nTG )
{
assert ( nTG < CConfig : : ToneGenerators ) ;
assert ( m_pTG [ nTG ] ) ;
return ( m_pTG [ nTG ] - > checkSystemExclusive ( pMessage , nLength ) ) ;
}
void CMiniDexed : : getSysExVoiceDump ( uint8_t * dest , uint8_t nTG )
{
uint8_t checksum = 0 ;
uint8_t data [ 155 ] ;
assert ( nTG < CConfig : : ToneGenerators ) ;
assert ( m_pTG [ nTG ] ) ;
m_pTG [ nTG ] - > getVoiceData ( data ) ;
dest [ 0 ] = 0xF0 ; // SysEx start
dest [ 1 ] = 0x43 ; // ID=Yamaha
dest [ 2 ] = GetTGParameter ( TGParameterMIDIChannel , nTG ) ; // Sub-status and MIDI channel
dest [ 3 ] = 0x00 ; // Format number (0=1 voice)
dest [ 4 ] = 0x01 ; // Byte count MSB
dest [ 5 ] = 0x1B ; // Byte count LSB
for ( uint8_t n = 0 ; n < 155 ; n + + )
{
checksum - = data [ n ] ;
dest [ 6 + n ] = data [ n ] ;
}
dest [ 161 ] = checksum & 0x7f ; // Checksum
dest [ 162 ] = 0xF7 ; // SysEx end
}
void CMiniDexed : : setMasterVolume ( float32_t vol )
{
if ( vol < 0.0 )
vol = 0.0 ;
else if ( vol > 1.0 )
vol = 1.0 ;
nMasterVolume = vol ;
}