From 5f088fab3c23143e6d4e9045fbe2799b48cddd24 Mon Sep 17 00:00:00 2001 From: Iliyas Jorio Date: Sun, 28 Feb 2021 23:42:36 +0100 Subject: [PATCH] Sound: honor initNoInterp --- src/Sound/SoundManager.cpp | 13 ++++++++++++- src/Sound/cmixer.cpp | 10 +++++++--- src/Sound/cmixer.h | 3 +++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Sound/SoundManager.cpp b/src/Sound/SoundManager.cpp index 007e550..3d80c83 100644 --- a/src/Sound/SoundManager.cpp +++ b/src/Sound/SoundManager.cpp @@ -84,6 +84,7 @@ enum ApplyParametersMask kApplyParameters_PanAndGain = 1 << 0, kApplyParameters_Pitch = 1 << 1, kApplyParameters_Loop = 1 << 2, + kApplyParameters_Interpolation = 1 << 3, kApplyParameters_All = 0xFFFFFFFF }; @@ -107,6 +108,7 @@ public: Byte playbackNote; double pitchMult; bool loop; + bool interpolate; bool temporaryPause = false; @@ -120,6 +122,7 @@ public: , playbackNote(kMiddleC) , pitchMult(1.0) , loop(false) + , interpolate(false) { macChannel->channelImpl = (Ptr) this; @@ -170,6 +173,12 @@ public: { source.SetInterpolation(interpolate); } + + // Interpolation + if (mask & kApplyParameters_Loop) + { + source.SetLoop(loop); + } } ChannelImpl* GetPrev() const @@ -332,7 +341,9 @@ OSErr SndNewChannel(SndChannelPtr* macChanPtr, short synth, long init, SndCallBa // Set up (**macChanPtr).callBack = userRoutine; - new ChannelImpl(*macChanPtr, transferMacChannelOwnership); + auto channelImpl = new ChannelImpl(*macChanPtr, transferMacChannelOwnership); + + channelImpl->interpolate = !(init & initNoInterp); //--------------------------- // Done diff --git a/src/Sound/cmixer.cpp b/src/Sound/cmixer.cpp index bbe6065..99db0c5 100644 --- a/src/Sound/cmixer.cpp +++ b/src/Sound/cmixer.cpp @@ -45,8 +45,6 @@ using namespace cmixer; #define BUFFER_MASK (BUFFER_SIZE - 1) -static constexpr bool INTERPOLATED_RESAMPLING = false; - //----------------------------------------------------------------------------- // Global mixer @@ -229,6 +227,7 @@ void Source::ClearPrivate() nextfill = 0; loop = false; rewind = true; + interpolate = false; // DON'T touch active. The source may still be in gMixer! gain = 0; pan = 0; @@ -345,7 +344,7 @@ void Source::Process(int len) } this->position += count * FX_UNIT; } - else if (INTERPOLATED_RESAMPLING) + else if (interpolate) { // Resample audio (with linear interpolation) and add to buffer for (int i = 0; i < count; i++) @@ -432,6 +431,11 @@ void Source::SetLoop(bool newLoop) loop = newLoop; } +void Source::SetInterpolation(bool newInterpolation) +{ + interpolate = newInterpolation; +} + void Source::Play() { gMixer.Lock(); diff --git a/src/Sound/cmixer.h b/src/Sound/cmixer.h index 8eea111..e68c4ff 100644 --- a/src/Sound/cmixer.h +++ b/src/Sound/cmixer.h @@ -55,6 +55,7 @@ namespace cmixer bool loop; // Whether the source will loop when `end` is reached bool rewind; // Whether the source will rewind before playing bool active; // Whether the source is part of `sources` list + bool interpolate; // Interpolated resampling when played back at a non-native rate double gain; // Gain set by `cm_set_gain()` double pan; // Pan set by `cm_set_pan()` std::function onComplete; // Callback @@ -99,6 +100,8 @@ namespace cmixer void SetLoop(bool loop); + void SetInterpolation(bool interpolation); + void Play(); void Pause();