-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added base class for double buffered effects
- Loading branch information
1 parent
569eda7
commit 7c34ee9
Showing
14 changed files
with
120 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
HephAudio/HeaderFiles/AudioEffects/DoubleBufferedAudioEffect.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
#include "HephAudioShared.h" | ||
#include "AudioEffect.h" | ||
|
||
/** @file */ | ||
|
||
namespace HephAudio | ||
{ | ||
/** | ||
* @brief base class for audio effects that use a temporary buffer while processing. | ||
*/ | ||
class DoubleBufferedAudioEffect : public AudioEffect | ||
{ | ||
public: | ||
using AudioEffect::Process; | ||
|
||
protected: | ||
/** @copydoc default_constructor */ | ||
DoubleBufferedAudioEffect(); | ||
|
||
/** @copydoc AudioEffect(size_t) */ | ||
explicit DoubleBufferedAudioEffect(size_t threadCount); | ||
|
||
public: | ||
/** @copydoc destructor */ | ||
virtual ~DoubleBufferedAudioEffect() = default; | ||
|
||
virtual void Process(AudioBuffer& buffer, size_t startIndex, size_t frameCount) override; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
HephAudio/SourceFiles/AudioEffects/DoubleBufferedAudioEffect.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "AudioEffects/DoubleBufferedAudioEffect.h" | ||
#include "Exceptions/InvalidArgumentException.h" | ||
|
||
using namespace Heph; | ||
|
||
namespace HephAudio | ||
{ | ||
DoubleBufferedAudioEffect::DoubleBufferedAudioEffect() : AudioEffect() {} | ||
|
||
DoubleBufferedAudioEffect::DoubleBufferedAudioEffect(size_t threadCount) : AudioEffect(threadCount) {} | ||
|
||
void DoubleBufferedAudioEffect::Process(AudioBuffer& buffer, size_t startIndex, size_t frameCount) | ||
{ | ||
if (startIndex > buffer.FrameCount()) | ||
{ | ||
HEPH_RAISE_AND_THROW_EXCEPTION(this, InvalidArgumentException(HEPH_FUNC, "startIndex out of bounds.")); | ||
} | ||
|
||
const size_t endIndex = startIndex + frameCount; | ||
if (endIndex > buffer.FrameCount()) | ||
{ | ||
HEPH_RAISE_AND_THROW_EXCEPTION(this, InvalidArgumentException(HEPH_FUNC, "(startIndex + frameCount) exceeds the buffer's frame count.")); | ||
} | ||
|
||
const AudioFormatInfo& formatInfo = buffer.FormatInfo(); | ||
AudioBuffer resultBuffer(this->CalculateOutputFrameCount(buffer), formatInfo.channelLayout, formatInfo.sampleRate, BufferFlags::AllocUninitialized); | ||
|
||
if (startIndex > 0) | ||
{ | ||
(void)memcpy(resultBuffer.begin(), buffer.begin(), startIndex * formatInfo.FrameSize()); | ||
} | ||
|
||
if (endIndex < buffer.FrameCount()) | ||
{ | ||
(void)memcpy(resultBuffer.begin() + endIndex, buffer.begin() + endIndex, (buffer.FrameCount() - endIndex) * formatInfo.FrameSize()); | ||
} | ||
|
||
if (this->threadCount == 1) | ||
this->ProcessST(buffer, resultBuffer, startIndex, frameCount); | ||
else | ||
this->ProcessMT(buffer, resultBuffer, startIndex, frameCount); | ||
|
||
buffer = std::move(resultBuffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters