Skip to content

Commit

Permalink
fix: music looping (#36)
Browse files Browse the repository at this point in the history
* fix: music looping, add method to set BASS_SAMPLE_LOOP on a Channel, that was lost during Channel refactoring

* ci: bump MSVC toolset to 14.40, because 14.39 is no longer supported on Actions
  • Loading branch information
piotrmacha committed Jun 15, 2024
1 parent e538f5f commit fb336a2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ on:
msvc-toolkit:
required: false
type: string
default: 14.39
default: 14.40
project-version:
required: false
type: string
Expand Down
5 changes: 5 additions & 0 deletions src/NH/Bass/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ namespace NH::Bass
BASS_ChannelSetAttribute(m_Stream, BASS_ATTRIB_VOL, volume);
}

void Channel::SetLoop(bool loop)
{
BASS_ChannelFlags(m_Stream, BASS_SAMPLE_LOOP, loop ? BASS_SAMPLE_LOOP : 0);
}

void Channel::SlideVolume(float targetVolume, uint32_t time)
{
BASS_ChannelSlideAttribute(m_Stream, BASS_ATTRIB_VOL, targetVolume, time);
Expand Down
2 changes: 2 additions & 0 deletions src/NH/Bass/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ namespace NH::Bass

Result<void> PlayInstant(const AudioFile& audioFile) override;
void StopInstant() override;

void SetVolume(float volume) override;
void SetLoop(bool loop) override;
void SlideVolume(float targetVolume, uint32_t time) override;
void SlideVolume(float targetVolume, uint32_t time, const std::function<void()>& onFinish) override;
void SetDX8ReverbEffect(float reverbMix, float reverbTime, float inputGain, float highFreqRTRatio) override;
Expand Down
1 change: 1 addition & 0 deletions src/NH/Bass/IChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace NH::Bass
virtual void StopInstant() = 0;

virtual void SetVolume(float volume) = 0;
virtual void SetLoop(bool loop) = 0;
virtual void SlideVolume(float targetVolume, uint32_t time) = 0;
virtual void SlideVolume(float targetVolume, uint32_t time, const std::function<void()>& onFinish) = 0;
virtual void SetDX8ReverbEffect(float reverbMix, float reverbTime, float inputGain, float highFreqRTRatio) = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/NH/Bass/MusicTheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ namespace NH::Bass
if (transition.Jingle)
{
auto channel = engine.AcquireFreeChannel();
channel->SetLoop(false);
auto result = channel->PlayInstant(*transition.Jingle);
if (result) { channel->OnAudioEnds(CreateSyncHandler([channel]() { channel->Release(); })); }
else
Expand Down Expand Up @@ -184,6 +185,8 @@ namespace NH::Bass
return;
}

channel->SetLoop(effects.Loop.Active);

if (effects.ReverbDX8.Active)
{
channel->SetDX8ReverbEffect(effects.ReverbDX8.Mix, effects.ReverbDX8.Time, 0, 0.001f);
Expand Down

0 comments on commit fb336a2

Please sign in to comment.