Skip to content

Commit

Permalink
fixed modulation effect bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ozguronsoy committed Nov 2, 2024
1 parent afaf2a1 commit 6db18c8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
10 changes: 10 additions & 0 deletions HephAudio/HeaderFiles/AudioEffects/AudioEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,24 @@ namespace HephAudio
/**
* Applies the effect.
* @param buffer contains the audio data which will be processed.
*
*/
virtual void Process(AudioBuffer& buffer);

/**
* Applies the effect.
* @param buffer contains the audio data which will be processed.
* @param startIndex index of the first audio frame to process.
*
*/
virtual void Process(AudioBuffer& buffer, size_t startIndex);

/**
* Applies the effect.
* @param buffer contains the audio data which will be processed.
* @param startIndex index of the first audio frame to process.
* @param frameCount number of frames to process.
*
*/
virtual void Process(AudioBuffer& buffer, size_t startIndex, size_t frameCount);

Expand Down
2 changes: 1 addition & 1 deletion HephAudio/HeaderFiles/AudioEffects/VibratoEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace HephAudio
/**
* @brief changes the pitch of the audio data periodically and mixes the result with the input signal.
*
* @important this is a non-causal effect.
* @note this is a non-causal effect.
*/
class VibratoEffect final : public ModulationEffect
{
Expand Down
15 changes: 15 additions & 0 deletions HephAudio/SourceFiles/AudioEffects/AudioEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,23 @@ namespace HephAudio
this->Process(buffer, 0, buffer.FrameCount());
}

void AudioEffect::Process(AudioBuffer& buffer, size_t startIndex)
{
if (startIndex > buffer.FrameCount())
{
HEPH_RAISE_AND_THROW_EXCEPTION(this, InvalidArgumentException(HEPH_FUNC, "startIndex out of bounds."));
}

this->Process(buffer, startIndex, buffer.FrameCount() - startIndex);
}

void AudioEffect::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."));
}

if (startIndex + frameCount > buffer.FrameCount())
{
HEPH_RAISE_AND_THROW_EXCEPTION(this, InvalidArgumentException(HEPH_FUNC, "(startIndex + frameCount) exceeds the buffer's frame count."));
Expand Down
13 changes: 12 additions & 1 deletion HephAudio/SourceFiles/AudioEffects/ModulationEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ namespace HephAudio

void ModulationEffect::Process(AudioBuffer& buffer, size_t startIndex, size_t frameCount)
{
if (startIndex + frameCount > buffer.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."));
}
Expand All @@ -28,6 +34,11 @@ namespace HephAudio
(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
Expand Down

0 comments on commit 6db18c8

Please sign in to comment.