Code cleanup for src/minidexed.*

Move implementation of constructors to minidexed.cpp
Reorder member variables
pull/37/head
Rene Stange 3 years ago
parent adadc17690
commit e65b4f6654
  1. 244
      src/minidexed.cpp
  2. 124
      src/minidexed.h

@ -20,42 +20,50 @@
#include "minidexed.h" #include "minidexed.h"
#include <circle/logger.h> #include <circle/logger.h>
#include <stdio.h> #include <stdio.h>
#include <assert.h>
LOGMODULE ("minidexed"); LOGMODULE ("minidexed");
CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt)
: CDexedAdapter (CConfig::MaxNotes, pConfig->GetSampleRate ()),
m_pConfig (pConfig),
m_UI (this, pConfig),
m_MIDIKeyboard (this, pConfig),
m_PCKeyboard (this),
m_SerialMIDI (this, pInterrupt, pConfig),
m_bUseSerial (false),
m_GetChunkTimer ("GetChunk",
1000000U * pConfig->GetChunkSize ()/2 / pConfig->GetSampleRate ()),
m_bProfileEnabled (m_pConfig->GetProfileEnabled ())
{
};
bool CMiniDexed::Initialize (void) bool CMiniDexed::Initialize (void)
{ {
if (!m_UI.Initialize ()) if (!m_UI.Initialize ())
{ {
return false; return false;
} }
m_SysExFileLoader.Load (); m_SysExFileLoader.Load ();
if (m_SerialMIDI.Initialize ()) if (m_SerialMIDI.Initialize ())
{ {
LOGNOTE ("Serial MIDI interface enabled"); LOGNOTE ("Serial MIDI interface enabled");
m_bUseSerial = true; m_bUseSerial = true;
} }
activate(); activate ();
ProgramChange (0); ProgramChange (0);
setTranspose (24); setTranspose (24);
return true; return true;
} }
void CMiniDexed::Process(boolean bPlugAndPlayUpdated) void CMiniDexed::Process (bool bPlugAndPlayUpdated)
{ {
if (m_pConfig->GetProfileEnabled ())
{
m_GetChunkTimer.Dump ();
}
m_UI.Process ();
m_MIDIKeyboard.Process (bPlugAndPlayUpdated); m_MIDIKeyboard.Process (bPlugAndPlayUpdated);
m_PCKeyboard.Process (bPlugAndPlayUpdated); m_PCKeyboard.Process (bPlugAndPlayUpdated);
@ -64,6 +72,13 @@ void CMiniDexed::Process(boolean bPlugAndPlayUpdated)
{ {
m_SerialMIDI.Process (); m_SerialMIDI.Process ();
} }
m_UI.Process ();
if (m_bProfileEnabled)
{
m_GetChunkTimer.Dump ();
}
} }
void CMiniDexed::BankSelectLSB (unsigned nBankLSB) void CMiniDexed::BankSelectLSB (unsigned nBankLSB)
@ -79,126 +94,171 @@ void CMiniDexed::BankSelectLSB (unsigned nBankLSB)
m_SysExFileLoader.SelectVoiceBank (nBankLSB); m_SysExFileLoader.SelectVoiceBank (nBankLSB);
} }
void CMiniDexed::ProgramChange (unsigned program) void CMiniDexed::ProgramChange (unsigned nProgram)
{ {
if (program > 31) if (nProgram > 31)
{ {
return; return;
} }
uint8_t Buffer[156]; uint8_t Buffer[156];
m_SysExFileLoader.GetVoice (program, Buffer); m_SysExFileLoader.GetVoice (nProgram, Buffer);
loadVoiceParameters (Buffer); loadVoiceParameters (Buffer);
m_UI.ProgramChanged (program); m_UI.ProgramChanged (nProgram);
}
//// PWM //////////////////////////////////////////////////////////////////////
CMiniDexedPWM::CMiniDexedPWM (CConfig *pConfig, CInterruptSystem *pInterrupt)
: CMiniDexed (pConfig, pInterrupt),
CPWMSoundBaseDevice (pInterrupt, pConfig->GetSampleRate (),
pConfig->GetChunkSize ())
{
} }
bool CMiniDexedPWM::Initialize (void) bool CMiniDexedPWM::Initialize (void)
{ {
if (!CMiniDexed::Initialize()) if (!CMiniDexed::Initialize ())
{ {
return false; return false;
} }
return Start (); return Start ();
} }
unsigned CMiniDexedPWM::GetChunk(u32 *pBuffer, unsigned nChunkSize) unsigned CMiniDexedPWM::GetChunk (u32 *pBuffer, unsigned nChunkSize)
{ {
m_GetChunkTimer.Start(); if (m_bProfileEnabled)
{
unsigned nResult = nChunkSize; m_GetChunkTimer.Start ();
}
int16_t int16_buf[nChunkSize/2]; unsigned nResult = nChunkSize;
getSamples(nChunkSize/2, int16_buf); int16_t SampleBuffer[nChunkSize/2];
getSamples (nChunkSize/2, SampleBuffer);
for (unsigned i = 0; nChunkSize > 0; nChunkSize -= 2) // fill the whole buffer for (unsigned i = 0; nChunkSize > 0; nChunkSize -= 2) // fill the whole buffer
{ {
s32 nSample = int16_buf[i++]; s32 nSample = SampleBuffer[i++];
nSample += 32768; nSample += 32768;
nSample *= GetRangeMax()/2; nSample *= GetRangeMax()/2;
nSample /= 32768; nSample /= 32768;
*pBuffer++ = nSample; // 2 stereo channels *pBuffer++ = nSample; // 2 stereo channels
*pBuffer++ = nSample; *pBuffer++ = nSample;
} }
m_GetChunkTimer.Stop(); if (m_bProfileEnabled)
{
m_GetChunkTimer.Stop ();
}
return(nResult); return nResult;
}; };
//// I2S //////////////////////////////////////////////////////////////////////
CMiniDexedI2S::CMiniDexedI2S (CConfig *pConfig, CInterruptSystem *pInterrupt,
CI2CMaster *pI2CMaster)
: CMiniDexed (pConfig, pInterrupt),
CI2SSoundBaseDevice (pInterrupt, pConfig->GetSampleRate (),
pConfig->GetChunkSize (), false, pI2CMaster,
pConfig->GetDACI2CAddress ())
{
}
bool CMiniDexedI2S::Initialize (void) bool CMiniDexedI2S::Initialize (void)
{ {
if (!CMiniDexed::Initialize()) if (!CMiniDexed::Initialize ())
{ {
return false; return false;
} }
return Start (); return Start ();
} }
unsigned CMiniDexedI2S::GetChunk(u32 *pBuffer, unsigned nChunkSize) unsigned CMiniDexedI2S::GetChunk (u32 *pBuffer, unsigned nChunkSize)
{ {
m_GetChunkTimer.Start(); if (m_bProfileEnabled)
{
unsigned nResult = nChunkSize; m_GetChunkTimer.Start ();
}
int16_t int16_buf[nChunkSize/2]; unsigned nResult = nChunkSize;
getSamples(nChunkSize/2, int16_buf); int16_t SampleBuffer[nChunkSize/2];
getSamples (nChunkSize/2, SampleBuffer);
for (unsigned i = 0; nChunkSize > 0; nChunkSize -= 2) // fill the whole buffer for (unsigned i = 0; nChunkSize > 0; nChunkSize -= 2) // fill the whole buffer
{ {
s32 nSample = int16_buf[i++]; s32 nSample = SampleBuffer[i++];
nSample <<= 8; nSample <<= 8;
*pBuffer++ = nSample; // 2 stereo channels *pBuffer++ = nSample; // 2 stereo channels
*pBuffer++ = nSample; *pBuffer++ = nSample;
} }
m_GetChunkTimer.Stop(); if (m_bProfileEnabled)
{
m_GetChunkTimer.Stop ();
}
return(nResult); return nResult;
}; };
//// HDMI /////////////////////////////////////////////////////////////////////
CMiniDexedHDMI::CMiniDexedHDMI (CConfig *pConfig, CInterruptSystem *pInterrupt)
: CMiniDexed (pConfig, pInterrupt),
CHDMISoundBaseDevice (pInterrupt, pConfig->GetSampleRate (),
pConfig->GetChunkSize ())
{
}
bool CMiniDexedHDMI::Initialize (void) bool CMiniDexedHDMI::Initialize (void)
{ {
if (!CMiniDexed::Initialize()) if (!CMiniDexed::Initialize ())
{ {
return false; return false;
} }
return Start (); return Start ();
} }
unsigned CMiniDexedHDMI::GetChunk(u32 *pBuffer, unsigned nChunkSize) unsigned CMiniDexedHDMI::GetChunk(u32 *pBuffer, unsigned nChunkSize)
{ {
m_GetChunkTimer.Start(); if (m_bProfileEnabled)
{
unsigned nResult = nChunkSize; m_GetChunkTimer.Start ();
}
int16_t int16_buf[nChunkSize/2];
unsigned nFrame = 0;
getSamples(nChunkSize/2, int16_buf); unsigned nResult = nChunkSize;
for (unsigned i = 0; nChunkSize > 0; nChunkSize -= 2) // fill the whole buffer int16_t SampleBuffer[nChunkSize/2];
{ getSamples (nChunkSize/2, SampleBuffer);
s32 nSample = int16_buf[i++];
nSample <<= 8;
nSample = ConvertIEC958Sample (nSample, nFrame); unsigned nFrame = 0;
for (unsigned i = 0; nChunkSize > 0; nChunkSize -= 2) // fill the whole buffer
{
s32 nSample = SampleBuffer[i++];
nSample <<= 8;
if (++nFrame == IEC958_FRAMES_PER_BLOCK) nSample = ConvertIEC958Sample (nSample, nFrame);
nFrame = 0; if (++nFrame == IEC958_FRAMES_PER_BLOCK)
{
nFrame = 0;
}
*pBuffer++ = nSample; // 2 stereo channels *pBuffer++ = nSample; // 2 stereo channels
*pBuffer++ = nSample; *pBuffer++ = nSample;
} }
m_GetChunkTimer.Stop(); if (m_bProfileEnabled)
{
m_GetChunkTimer.Stop();
}
return(nResult); return nResult;
}; };

@ -21,94 +21,84 @@
#define _minidexed_h #define _minidexed_h
#include "dexedadapter.h" #include "dexedadapter.h"
#include <stdint.h>
#include <math.h>
#include <circle/interrupt.h>
#include <circle/i2cmaster.h>
#include <circle/types.h>
#include <circle/pwmsoundbasedevice.h>
#include <circle/i2ssoundbasedevice.h>
#include <circle/hdmisoundbasedevice.h>
#include "config.h" #include "config.h"
#include "userinterface.h"
#include "sysexfileloader.h" #include "sysexfileloader.h"
#include "midikeyboard.h" #include "midikeyboard.h"
#include "pckeyboard.h" #include "pckeyboard.h"
#include "serialmididevice.h" #include "serialmididevice.h"
#include "perftimer.h" #include "perftimer.h"
#include "userinterface.h" #include <stdint.h>
#include <circle/types.h>
#include <circle/interrupt.h>
#include <circle/i2cmaster.h>
#include <circle/pwmsoundbasedevice.h>
#include <circle/i2ssoundbasedevice.h>
#include <circle/hdmisoundbasedevice.h>
class CMiniDexed : public CDexedAdapter class CMiniDexed : public CDexedAdapter
{ {
public: public:
CMiniDexed(CConfig *pConfig, CInterruptSystem *pInterrupt) CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt);
: CDexedAdapter (CConfig::MaxNotes, pConfig->GetSampleRate ()),
m_MIDIKeyboard (this, pConfig), virtual bool Initialize (void);
m_PCKeyboard (this),
m_SerialMIDI (this, pInterrupt, pConfig), void Process (bool bPlugAndPlayUpdated);
m_bUseSerial (FALSE),
m_pConfig (pConfig), void BankSelectLSB (unsigned nBankLSB);
m_UI (this, pConfig), void ProgramChange (unsigned nProgram);
m_GetChunkTimer ("GetChunk", 1000000U * pConfig->GetChunkSize ()/2 / pConfig->GetSampleRate ())
{ private:
}; CConfig *m_pConfig;
virtual bool Initialize (void); CUserInterface m_UI;
void Process(boolean bPlugAndPlayUpdated); CSysExFileLoader m_SysExFileLoader;
void BankSelectLSB (unsigned nBankLSB); CMIDIKeyboard m_MIDIKeyboard;
void ProgramChange (unsigned program); CPCKeyboard m_PCKeyboard;
CSerialMIDIDevice m_SerialMIDI;
private: bool m_bUseSerial;
CMIDIKeyboard m_MIDIKeyboard;
CPCKeyboard m_PCKeyboard; protected:
CSerialMIDIDevice m_SerialMIDI; CPerformanceTimer m_GetChunkTimer;
boolean m_bUseSerial; bool m_bProfileEnabled;
CSysExFileLoader m_SysExFileLoader;
CConfig *m_pConfig;
CUserInterface m_UI;
protected:
CPerformanceTimer m_GetChunkTimer;
}; };
//// PWM //////////////////////////////////////////////////////////////////////
class CMiniDexedPWM : public CMiniDexed, public CPWMSoundBaseDevice class CMiniDexedPWM : public CMiniDexed, public CPWMSoundBaseDevice
{ {
public: public:
CMiniDexedPWM(CConfig *pConfig, CInterruptSystem *pInterrupt) CMiniDexedPWM (CConfig *pConfig, CInterruptSystem *pInterrupt);
: CMiniDexed(pConfig, pInterrupt),
CPWMSoundBaseDevice (pInterrupt, pConfig->GetSampleRate (), pConfig->GetChunkSize ()) bool Initialize (void);
{
} unsigned GetChunk (u32 *pBuffer, unsigned nChunkSize);
bool Initialize (void);
unsigned GetChunk (u32 *pBuffer, unsigned nChunkSize);
}; };
//// I2S //////////////////////////////////////////////////////////////////////
class CMiniDexedI2S : public CMiniDexed, public CI2SSoundBaseDevice class CMiniDexedI2S : public CMiniDexed, public CI2SSoundBaseDevice
{ {
public: public:
CMiniDexedI2S(CConfig *pConfig, CInterruptSystem *pInterrupt, CI2CMaster *pI2CMaster) CMiniDexedI2S (CConfig *pConfig, CInterruptSystem *pInterrupt,
: CMiniDexed(pConfig, pInterrupt), CI2CMaster *pI2CMaster);
CI2SSoundBaseDevice (pInterrupt, pConfig->GetSampleRate (), pConfig->GetChunkSize (),
FALSE, pI2CMaster, pConfig->GetDACI2CAddress ()) bool Initialize (void);
{
} unsigned GetChunk (u32 *pBuffer, unsigned nChunkSize);
bool Initialize (void);
unsigned GetChunk (u32 *pBuffer, unsigned nChunkSize);
}; };
//// HDMI /////////////////////////////////////////////////////////////////////
class CMiniDexedHDMI : public CMiniDexed, public CHDMISoundBaseDevice class CMiniDexedHDMI : public CMiniDexed, public CHDMISoundBaseDevice
{ {
public: public:
CMiniDexedHDMI(CConfig *pConfig, CInterruptSystem *pInterrupt) CMiniDexedHDMI (CConfig *pConfig, CInterruptSystem *pInterrupt);
: CMiniDexed(pConfig, pInterrupt),
CHDMISoundBaseDevice (pInterrupt, pConfig->GetSampleRate (), pConfig->GetChunkSize ()) bool Initialize (void);
{
} unsigned GetChunk (u32 *pBuffer, unsigned nChunkSize);
bool Initialize (void);
unsigned GetChunk (u32 *pBuffer, unsigned nChunkSize);
}; };
#endif #endif

Loading…
Cancel
Save