Sound: honor initNoInterp

This commit is contained in:
Iliyas Jorio 2021-02-28 23:42:36 +01:00
parent d8f5f4b324
commit 5f088fab3c
3 changed files with 22 additions and 4 deletions

View File

@ -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

View File

@ -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();

View File

@ -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<void()> onComplete; // Callback
@ -99,6 +100,8 @@ namespace cmixer
void SetLoop(bool loop);
void SetInterpolation(bool interpolation);
void Play();
void Pause();