diff --git a/include/AudioEngine.h b/include/AudioEngine.h index e434b7f15b2..6aeb293c7f0 100644 --- a/include/AudioEngine.h +++ b/include/AudioEngine.h @@ -34,6 +34,7 @@ #include #include +#include #include #include "lmms_basics.h" @@ -380,8 +381,8 @@ class LMMS_EXPORT AudioEngine : public QObject int m_inputBufferRead; int m_inputBufferWrite; - surroundSampleFrame * m_outputBufferRead; - surroundSampleFrame * m_outputBufferWrite; + std::unique_ptr m_outputBufferRead; + std::unique_ptr m_outputBufferWrite; // worker thread stuff std::vector m_workers; diff --git a/include/MemoryHelper.h b/include/MemoryHelper.h deleted file mode 100644 index e709ffc8aad..00000000000 --- a/include/MemoryHelper.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2014 Simon Symeonidis - * Copyright (c) 2004-2014 Tobias Doerffel - * - * This file is part of LMMS - https://lmms.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program (see COPYING); if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - */ - -#ifndef LMMS_MEMORY_HELPER_H -#define LMMS_MEMORY_HELPER_H - -#include - -namespace lmms -{ - - -/** - * Helper class to alocate aligned memory and free it. - */ -class MemoryHelper { -public: - - static void* alignedMalloc( size_t ); - - static void alignedFree( void* ); - -private: -}; - - -} // namespace lmms - -#endif // LMMS_MEMORY_HELPER_H diff --git a/include/lmms_basics.h b/include/lmms_basics.h index b566fa781ed..5c7292ab003 100644 --- a/include/lmms_basics.h +++ b/include/lmms_basics.h @@ -128,7 +128,6 @@ constexpr char LADSPA_PATH_SEPERATOR = using sampleFrame = std::array; using surroundSampleFrame = std::array; -constexpr std::size_t LMMS_ALIGN_SIZE = 16; #define LMMS_STRINGIFY(s) LMMS_STR(s) diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 31c4a3e5cef..d4fd643acc8 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -37,7 +37,6 @@ #include "NotePlayHandle.h" #include "ConfigManager.h" #include "SamplePlayHandle.h" -#include "MemoryHelper.h" // platform-specific audio-interface-classes #include "AudioAlsa.h" @@ -137,12 +136,9 @@ AudioEngine::AudioEngine( bool renderOnly ) : // now that framesPerPeriod is fixed initialize global BufferManager BufferManager::init( m_framesPerPeriod ); - int outputBufferSize = m_framesPerPeriod * sizeof(surroundSampleFrame); - m_outputBufferRead = static_cast(MemoryHelper::alignedMalloc(outputBufferSize)); - m_outputBufferWrite = static_cast(MemoryHelper::alignedMalloc(outputBufferSize)); + m_outputBufferRead = std::make_unique(m_framesPerPeriod); + m_outputBufferWrite = std::make_unique(m_framesPerPeriod); - BufferManager::clear(m_outputBufferRead, m_framesPerPeriod); - BufferManager::clear(m_outputBufferWrite, m_framesPerPeriod); for( int i = 0; i < m_numWorkers+1; ++i ) { @@ -181,8 +177,6 @@ AudioEngine::~AudioEngine() delete m_midiClient; delete m_audioDev; - MemoryHelper::alignedFree(m_outputBufferRead); - MemoryHelper::alignedFree(m_outputBufferWrite); for (const auto& input : m_inputBuffer) { @@ -421,11 +415,11 @@ void AudioEngine::renderStageMix() AudioEngineProfiler::Probe profilerProbe(m_profiler, AudioEngineProfiler::DetailType::Mixing); Mixer *mixer = Engine::mixer(); - mixer->masterMix(m_outputBufferWrite); + mixer->masterMix(m_outputBufferWrite.get()); - MixHelpers::multiply(m_outputBufferWrite, m_masterGain, m_framesPerPeriod); + MixHelpers::multiply(m_outputBufferWrite.get(), m_masterGain, m_framesPerPeriod); - emit nextAudioBuffer(m_outputBufferRead); + emit nextAudioBuffer(m_outputBufferRead.get()); // and trigger LFOs EnvelopeAndLfoParameters::instances()->trigger(); @@ -435,7 +429,7 @@ void AudioEngine::renderStageMix() -const surroundSampleFrame *AudioEngine::renderNextBuffer() +const surroundSampleFrame* AudioEngine::renderNextBuffer() { const auto lock = std::lock_guard{m_changeMutex}; @@ -450,7 +444,7 @@ const surroundSampleFrame *AudioEngine::renderNextBuffer() s_renderingThread = false; m_profiler.finishPeriod(outputSampleRate(), m_framesPerPeriod); - return m_outputBufferRead; + return m_outputBufferRead.get(); } @@ -463,7 +457,7 @@ void AudioEngine::swapBuffers() m_inputBufferFrames[m_inputBufferWrite] = 0; std::swap(m_outputBufferRead, m_outputBufferWrite); - BufferManager::clear(m_outputBufferWrite, m_framesPerPeriod); + std::fill_n(m_outputBufferWrite.get(), m_framesPerPeriod, surroundSampleFrame{}); } diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 9ebe2c35533..3608d28486a 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -39,7 +39,6 @@ set(LMMS_SRCS core/LfoController.cpp core/LinkedModelGroups.cpp core/LocklessAllocator.cpp - core/MemoryHelper.cpp core/MeterModel.cpp core/MicroTimer.cpp core/Microtuner.cpp diff --git a/src/core/MemoryHelper.cpp b/src/core/MemoryHelper.cpp deleted file mode 100644 index 8f990d57e92..00000000000 --- a/src/core/MemoryHelper.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2014 Simon Symeonidis - * Copyright (c) 2008-2014 Tobias Doerffel - * - * This file is part of LMMS - https://lmms.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program (see COPYING); if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - */ - -#include - -#include "lmms_basics.h" -#include "MemoryHelper.h" - -namespace lmms -{ - - -/** - * Allocate a number of bytes and return them. - * @param byteNum is the number of bytes - */ -void* MemoryHelper::alignedMalloc( size_t byteNum ) -{ - int align_mask = LMMS_ALIGN_SIZE - 1; - - char* ptr = static_cast(malloc(byteNum + LMMS_ALIGN_SIZE + sizeof(int))); - - if( ptr == nullptr ) return nullptr; - - char* ptr2 = ptr + sizeof(int); - char* aligned_ptr = ptr2 + (LMMS_ALIGN_SIZE - ((size_t)ptr2 & align_mask)); - - ptr2 = aligned_ptr - sizeof( int ); - *( ( int* ) ptr2 ) = ( int )( aligned_ptr - ptr ); - - return aligned_ptr; -} - - -/** - * Free an aligned buffer - * @param _buffer is the buffer to free - */ -void MemoryHelper::alignedFree( void* _buffer ) -{ - if( _buffer ) - { - int *ptr2 = static_cast( _buffer ) - 1; - _buffer = static_cast( _buffer ) - *ptr2; - free( _buffer ); - } -} - - -} // namespace lmms