Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add idle.wav option #706

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions props/prop_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ class PropBase : CommandParser, Looper, protected SaberBase, public ModeInterfac
SaveColorChangeIfNeeded();
// First free all styles, then allocate new ones to avoid memory
// fragmentation.
hybrid_font.idle_player_.Free();
hybrid_font.idling_ = true;
FreeBladeStyles();
current_preset_.SetPreset(preset_num);
AllocateBladeStyles();
Expand Down
1 change: 1 addition & 0 deletions sound/effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ EFFECT2(lock, lock);
EFFECT(swng);
EFFECT(slsh);
EFFECT(quote);
EFFECT2(idle, idle); // Plays when blade is off

// Looped swing fonts. (SmoothSwing V1/V2)
EFFECT2(swingl, swingl); // Looped swing, LOW
Expand Down
51 changes: 46 additions & 5 deletions sound/hybrid_font.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class HybridFont : public SaberBase, public Looper {
RefPtr<BufferedWavPlayer> next_hum_player_;
RefPtr<BufferedWavPlayer> swing_player_;
RefPtr<BufferedWavPlayer> lock_player_;
RefPtr<BufferedWavPlayer> idle_player_;

void PlayMonophonic(const Effect::FileID& f, Effect* loop, float xfade = 0.003f) {
EnableAmplifier();
Expand Down Expand Up @@ -423,6 +424,7 @@ class HybridFont : public SaberBase, public Looper {
}

void SB_On(EffectLocation location) override {
StopIdleSound();
// If preon exists, we've already queed up playing the poweron and hum.
bool already_started = state_ == STATE_WAIT_FOR_ON && SFX_preon;
bool faston = state_ != STATE_WAIT_FOR_ON;
Expand Down Expand Up @@ -472,15 +474,17 @@ class HybridFont : public SaberBase, public Looper {
}

void SB_Off(OffType off_type, EffectLocation location) override {
idling_ = true;
bool most_blades = location.on_blade(0);
SFX_in.SetFollowing( most_blades ? &SFX_pstoff : nullptr );
switch (off_type) {
case OFF_CANCEL_PREON:
if (state_ == STATE_WAIT_FOR_ON) {
state_ = STATE_OFF;
}
break;
if (state_ == STATE_WAIT_FOR_ON) {
state_ = STATE_OFF;
}
break;
case OFF_IDLE:
StopIdleSound();
break;
case OFF_FAST:
SFX_in.SetFollowing(nullptr);
Expand Down Expand Up @@ -799,8 +803,44 @@ class HybridFont : public SaberBase, public Looper {
SaberBase::DoEffect(EFFECT_POSTOFF, saved_location_);
}
}
// Wait for retraction sounds to finish, then play idle.wav
#ifdef ENABLE_IDLE_SOUND
if (idling_) {
if (GetWavPlayerPlaying(&SFX_in) || GetWavPlayerPlaying(&SFX_pstoff)) {
return;
} else {
idling_ = false;
StartIdleSound();
}
}
#endif
}

void StopIdleSound() {
#ifdef ENABLE_IDLE_SOUND
idling_ = false;
if (idle_player_ && idle_player_->isPlaying()) {
idle_player_->set_fade_time(0.5);
idle_player_->FadeAndStop();
idle_player_.Free();
STDOUT.println("End idle wav Player");
}
#endif
}

void StartIdleSound() {
if (SFX_idle && (!idle_player_ || !idle_player_->isPlaying())) {
idle_player_ = GetFreeWavPlayer();
if (idle_player_) {
PVLOG_DEBUG << "************ Playing idle.wav\n";
idle_player_->PlayOnce(&SFX_idle);
} else {
STDOUT.println("Out of WAV players!");
}
}
}
bool swinging_ = false;

bool swinging_ = false;
void SB_Motion(const Vec3& gyro, bool clear) override {
if (active_state() && !(SFX_lockup && SaberBase::Lockup())) {
StartSwing(gyro,
Expand All @@ -817,6 +857,7 @@ class HybridFont : public SaberBase, public Looper {
ProffieOSErrors::low_battery();
}

bool idling_ = true;
private:
uint32_t last_micros_;
uint32_t last_swing_micros_;
Expand Down