diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index abfe811..d37c066 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,7 +1,7 @@ { "configurations": [ { - "name": "Win32", + "name": "RaspberryPI", "includePath": [ "${workspaceFolder}/src/**", "${workspaceFolder}/CMSIS_5/CMSIS/Core/Include/**", @@ -12,17 +12,13 @@ ], "defines": [ "_DEBUG", - "UNICODE", - "_UNICODE", "RPI=4", "ARM_ALLOW_MULTI_CORE" ], - "windowsSdkVersion": "10.0.19041.0", - "compilerPath": "cl.exe", "cStandard": "c17", "cppStandard": "c++20", - "intelliSenseMode": "windows-msvc-x64", - "configurationProvider": "ms-vscode.makefile-tools" + "compilerPath": "", + "intelliSenseMode": "linux-clang-arm64" } ], "version": 4 diff --git a/.vscode/settings.json b/.vscode/settings.json index 67172f4..3cc8ed9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -82,7 +82,33 @@ "span": "cpp", "regex": "cpp", "valarray": "cpp", - "shared_mutex": "cpp" + "shared_mutex": "cpp", + "xlocbuf": "cpp", + "charconv": "cpp", + "codecvt": "cpp", + "coroutine": "cpp", + "csetjmp": "cpp", + "csignal": "cpp", + "cuchar": "cpp", + "filesystem": "cpp", + "format": "cpp", + "locale": "cpp", + "queue": "cpp", + "scoped_allocator": "cpp", + "stack": "cpp", + "typeindex": "cpp", + "xfacet": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xstddef": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "netfwd": "cpp", + "*.def": "cpp" }, "C_Cpp.errorSquiggles": "disabled", "C_Cpp.intelliSenseEngine": "Tag Parser", diff --git a/src/CFileDevice.hpp b/src/CFileDevice.hpp new file mode 100644 index 0000000..ccd6cd6 --- /dev/null +++ b/src/CFileDevice.hpp @@ -0,0 +1,54 @@ +#pragma once + +#include "extra_features.h" + +#include +#include +#include +#include +#include +#include + +class CFileDevice : public CDevice +{ + DISALLOW_COPY_AND_ASSIGN(CFileDevice); + +private: + CFileDevice() + : m_file(new FIL()) + { + FRESULT res = f_open(this->m_file, "SD:/debuglog.txt", FA_WRITE | FA_CREATE_ALWAYS); + assert(res == FR_OK); + } + +public: + static void UseMeForLogger() + { + CLogger::Get()->SetNewTarget(&CFileDevice::GetInstance()); + } + + static CFileDevice& GetInstance() + { + static CFileDevice Instance; + + return Instance; + } + + ~CFileDevice() + { + f_sync(this->m_file); + f_close(this->m_file); + } + + virtual int Write(const void* pBuffer, size_t nCount) override + { + UINT nb; + f_write(this->m_file, pBuffer, nCount, &nb); + f_sync(this->m_file); + + return (int)nb; + } + +private: + FIL* m_file; +}; diff --git a/src/kernel.cpp b/src/kernel.cpp index 4397cd9..a5d848a 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -22,6 +22,8 @@ #include #include +#include "CFileDevice.hpp" + LOGMODULE ("kernel"); CKernel *CKernel::s_pThis = 0; @@ -50,6 +52,7 @@ bool CKernel::Initialize (void) return FALSE; } + CFileDevice::UseMeForLogger(); mLogger.RegisterPanicHandler (PanicHandler); if (!m_GPIOManager.Initialize ()) diff --git a/src/minidexed.cpp b/src/minidexed.cpp index 18cfadd..960bd8d 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -149,8 +149,7 @@ CMiniDexed::CMiniDexed ( this->setMasterVolume(1.0); #if defined(MIXING_CONSOLE_ENABLE) - this->m_UI.log("Init Mixing Console..."); - this->mixing_console_ = new Mixer(static_cast(pConfig->GetSampleRate()), pConfig->GetChunkSize() / 2); + this->mixing_console_ = new Mixer(static_cast(pConfig->GetSampleRate()), CConfig::MaxChunkSize); for (uint8_t i = 0; i < CConfig::ToneGenerators; i++) { this->mixing_console_->setInputSampleBuffer(i, m_OutputLevel[i]); @@ -315,10 +314,10 @@ bool CMiniDexed::Initialize (void) return false; } -#ifndef ARM_ALLOW_MULTI_CORE - m_pSoundDevice->SetWriteFormat (SoundFormatSigned16, 1); // 16-bit Mono -#else +#if defined(ARM_ALLOW_MULTI_CORE) m_pSoundDevice->SetWriteFormat (SoundFormatSigned16, 2); // 16-bit Stereo +#else + m_pSoundDevice->SetWriteFormat (SoundFormatSigned16, 1); // 16-bit Mono #endif m_nQueueSizeFrames = m_pSoundDevice->GetQueueSizeFrames (); @@ -332,7 +331,7 @@ bool CMiniDexed::Initialize (void) return false; } #endif - + return true; } @@ -447,7 +446,7 @@ void CMiniDexed::Run (unsigned nCore) m_pTG[nTG]->getSamples (m_OutputLevel[nTG],m_nFramesToProcess); #if defined(MIXING_CONSOLE_ENABLE) - this->mixing_console_->preProcessInputSampleBuffer(nTG); + this->mixing_console_->preProcessInputSampleBuffer(nTG, this->m_nFramesToProcess); #endif } } @@ -1765,7 +1764,7 @@ void CMiniDexed::ProcessSound (void) m_pTG[i]->getSamples (m_OutputLevel[i], nFrames); #if defined(MIXING_CONSOLE_ENABLE) - this->mixing_console_->preProcessInputSampleBuffer(i); + this->mixing_console_->preProcessInputSampleBuffer(i, nFrames); #endif } diff --git a/src/mixing_console.hpp b/src/mixing_console.hpp index 3a28bf0..221fca6 100644 --- a/src/mixing_console.hpp +++ b/src/mixing_console.hpp @@ -49,7 +49,7 @@ public: inline void setInputSample(size_t in, float32_t sampleL, float32_t sampleR); inline void setInputSampleBuffer(size_t in, float32_t* samples); inline void setInputSampleBuffer(size_t in, float32_t* samplesL, float32_t* samplesR); - inline void preProcessInputSampleBuffer(size_t in); + inline void preProcessInputSampleBuffer(size_t in, size_t nSamples); // Return section inline void setReturnLevel(MixerOutput ret, MixerOutput dest, float32_t lvl); @@ -87,6 +87,7 @@ private: float32_t* input_sample_buffer_[StereoChannels::kNumChannels][nb_inputs]; float32_t input_samples_[StereoChannels::kNumChannels][nb_inputs + MixerOutput::kFXCount - 1]; float32_t levels_[MixerOutput::kFXCount][nb_inputs + MixerOutput::kFXCount - 1]; + volatile size_t m_nSamples; FXElement* fx_[MixerOutput::kFXCount]; FXUnit2* tube_; @@ -317,7 +318,8 @@ private: template MixingConsole::MixingConsole(float32_t sampling_rate, size_t buffer_size) : FXBase(sampling_rate), - BufferSize(buffer_size) + BufferSize(buffer_size), + m_nSamples(0) { for(size_t i = 0; i < nb_inputs; ++i) { @@ -433,29 +435,33 @@ void MixingConsole::setInputSampleBuffer(size_t in, float32_t* sample } template -void MixingConsole::preProcessInputSampleBuffer(size_t in) +void MixingConsole::preProcessInputSampleBuffer(size_t in, size_t nSamples) { assert(in < nb_inputs); + assert(nSamples <= this->BufferSize); float32_t* samples = this->tg_input_sample_buffer_[in]; - if(samples != nullptr) + if(samples == nullptr) return; + + this->m_nSamples = nSamples; + if(nSamples > 0) { if(this->pan_[StereoChannels::Left ][in] != 0.0f) { - arm_scale_f32(samples, this->pan_[StereoChannels::Left ][in], this->input_sample_buffer_[StereoChannels::Left ][in], this->BufferSize); + arm_scale_f32(samples, this->pan_[StereoChannels::Left ][in], this->input_sample_buffer_[StereoChannels::Left ][in], nSamples); } else { - memset(this->input_sample_buffer_[StereoChannels::Left ][in], 0, this->BufferSize * sizeof(float32_t)); + memset(this->input_sample_buffer_[StereoChannels::Left ][in], 0, nSamples * sizeof(float32_t)); } if(this->pan_[StereoChannels::Right][in] != 0.0f) { - arm_scale_f32(samples, this->pan_[StereoChannels::Right][in], this->input_sample_buffer_[StereoChannels::Right][in], this->BufferSize); + arm_scale_f32(samples, this->pan_[StereoChannels::Right][in], this->input_sample_buffer_[StereoChannels::Right][in], nSamples); } else { - memset(this->input_sample_buffer_[StereoChannels::Right][in], 0, this->BufferSize * sizeof(float32_t)); + memset(this->input_sample_buffer_[StereoChannels::Right][in], 0, nSamples * sizeof(float32_t)); } } else @@ -590,15 +596,15 @@ void MixingConsole::reset() template void MixingConsole::processSample(float32_t& outL, float32_t& outR) { - const size_t bufferSize = nb_inputs + MixerOutput::kFXCount - 1; + const size_t nBuffers = nb_inputs + MixerOutput::kFXCount - 1; float32_t fx_inputs_[MixerOutput::kFXCount][StereoChannels::kNumChannels]; float32_t fx_outputs_[MixerOutput::kFXCount][StereoChannels::kNumChannels]; for(size_t i = 0; i < MixerOutput::kFXCount; ++i) { // Compute the samples that will feed the MixerOutput and process MixerOutput - fx_inputs_[i][StereoChannels::Left ] = arm_weighted_sum_f32(this->input_samples_[StereoChannels::Left ], this->levels_[i], bufferSize); - fx_inputs_[i][StereoChannels::Right] = arm_weighted_sum_f32(this->input_samples_[StereoChannels::Right], this->levels_[i], bufferSize); + fx_inputs_[i][StereoChannels::Left ] = arm_weighted_sum_f32(this->input_samples_[StereoChannels::Left ], this->levels_[i], nBuffers); + fx_inputs_[i][StereoChannels::Right] = arm_weighted_sum_f32(this->input_samples_[StereoChannels::Right], this->levels_[i], nBuffers); // Process the FX this->fx_[i]->processSample( @@ -627,7 +633,8 @@ void MixingConsole::processSample(float32_t& outL, float32_t& outR) template void MixingConsole::process(float32_t* outL, float32_t* outR) { - for(size_t s = 0; s < this->BufferSize; ++s) + size_t nSamples = this->m_nSamples; + for(size_t s = 0; s < nSamples; ++s) { for(size_t in = 0; in < nb_inputs; ++in) { @@ -642,6 +649,8 @@ void MixingConsole::process(float32_t* outL, float32_t* outR) ++outL; ++outR; } + + this->m_nSamples = 0; } template diff --git a/src/userinterface.cpp b/src/userinterface.cpp index 0027aab..e60fd95 100644 --- a/src/userinterface.cpp +++ b/src/userinterface.cpp @@ -236,7 +236,7 @@ void CUserInterface::DisplayWrite (const char *pMenu, const char *pParam, const LCDWrite (Msg); } -// #if defined(DEBUG) +#if defined(DEBUG) #include #include #include @@ -319,7 +319,7 @@ void CUserInterface::log(int v, bool clear) } } -// #endif +#endif // DEBUG void CUserInterface::LCDWrite (const char *pString) { diff --git a/src/userinterface.h b/src/userinterface.h index ac5a09e..81e5af1 100644 --- a/src/userinterface.h +++ b/src/userinterface.h @@ -60,16 +60,16 @@ public: // To be called from the MIDI device on reception of a MIDI CC message void UIMIDICmdHandler (unsigned nMidiCh, unsigned nMidiCmd, unsigned nMidiData1, unsigned nMidiData2); -// #ifdef DEBUG +#if defined(DEBUG) public: void clear(); void log(const char* txt, bool clear = true); void log(float32_t v, bool clear = true); void log(unsigned v, bool clear = true); void log(int v, bool clear = true); -// #else +#endif + private: -// #endif void LCDWrite (const char *pString); // Print to optional HD44780 display private: