Skip to content

Commit

Permalink
Merge pull request EasyRPG#2762 from Ghabry/audio/resampler
Browse files Browse the repository at this point in the history
Resampler: Fix crackles when looping the audio
  • Loading branch information
carstene1ns authored Apr 10, 2022
2 parents 80a9836 + 05cad42 commit 87d422a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/audio_decoder_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class AudioDecoderBase {
*
* @return if looping
*/
bool GetLooping() const;
virtual bool GetLooping() const;

/**
* Enables/Disables audio stream looping.
Expand All @@ -97,14 +97,14 @@ class AudioDecoderBase {
*
* @param enable Enable/Disable looping
*/
void SetLooping(bool enable);
virtual void SetLooping(bool enable);

/**
* Gets the number of loops
*
* @return loop count
*/
int GetLoopCount() const;
virtual int GetLoopCount() const;

// Functions to be implemented by the audio decoder
/**
Expand Down
11 changes: 11 additions & 0 deletions src/audio_resampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,18 @@ bool AudioResampler::Seek(std::streamoff offset, std::ios_base::seekdir origin)
return true;
}
return false;
}

bool AudioResampler::GetLooping() const {
return wrapped_decoder->GetLooping();
}

void AudioResampler::SetLooping(bool enable) {
wrapped_decoder->SetLooping(enable);
}

int AudioResampler::GetLoopCount() const {
return wrapped_decoder->GetLoopCount();
}

std::streampos AudioResampler::Tell() const {
Expand Down
25 changes: 24 additions & 1 deletion src/audio_resampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,29 @@ class AudioResampler : public AudioDecoderBase {
*/
bool Seek(std::streamoff offset, std::ios_base::seekdir origin) override;

/**
* Gets if the audio stream will loop when the stream finishes.
*
* @return if looping
*/
bool GetLooping() const override;

/**
* Enables/Disables audio stream looping.
* When looping is enabled IsFinished will never return true and the stream
* auto-rewinds (assuming Rewind is supported)
*
* @param enable Enable/Disable looping
*/
void SetLooping(bool enable) override;

/**
* Gets the number of loops
*
* @return loop count
*/
int GetLoopCount() const override;

/**
* Wraps the tell function of the contained decoder
*
Expand All @@ -135,7 +158,7 @@ class AudioResampler : public AudioDecoderBase {
int GetTicks() const override;

/**
* Returns wheter the resampled audio stream is finished
* Returns whether the resampled is exhausted and the audio stream is finished.
*
* @return true if the stream has reached it's end
*/
Expand Down

0 comments on commit 87d422a

Please sign in to comment.