Hello The Crucible, Happy New Year everyone,
For my jetpack prop, I have a few sound-types/sound playing scenarios, that I am not sure if they will be playing correctly:
-
Music from the track player, I would like it to play without interruption, the other prop sounds play in addition to the track. I suppose that is how
StartOrStopTrack()
works ? -
I have transition sounds (startidlemode, startflightmode, stopflightmode & stopidlemode), they play once and then a looping sound (idlemode or flightmode) starts.
void JetpackHelper(Effect& effect3, EffectType effect4) {
Effect::FileID file_id(&effect3, 0, 0);
jetpack_wav_player_.PlayOnce(file_id);
SaberBase::DoEffect(effect4, 0);
}
// Initial start, transition to Idle Mode (from 0 to idle)
void StartIdleMode() {
if (jetpack_wav_player_.isPlaying()) {
return;
}
JetpackHelper(SFX_startidlemode,EFFECT_STARTIDLEMODE); // start transition to idle mode
flight_ = false;
idle_ = true;
timer_ = millis(); // Reset idle timer
FastOn();
PVLOG_STATUS << "Jetpack Idling\n";
}
// Transition to Flying Mode (from idle to flying)
void StartFlightMode() {
if (jetpack_wav_player_.isPlaying()) {
return;
}
JetpackHelper(SFX_startflightmode,EFFECT_STARTFLIGHTMODE); // start transition to flight mode
flight_ = true;
idle_ = false;
PVLOG_STATUS << "Jetpack Flying\n";
}
// Transition from Flying Mode (from flying to idle)
void StopFlightMode() {
if (jetpack_wav_player_.isPlaying()) {
return;
}
JetpackHelper(SFX_stopflightmode,EFFECT_STOPFLIGHTMODE); // start transition from flight mode
flight_ = false;
idle_ = true;
}
// Stop Idle Mode (Jetpack completely off - idle to off)
void StopIdleMode() {
if (jetpack_wav_player_.isPlaying()) {
return;
}
JetpackHelper(SFX_stopidlemode,EFFECT_STOPIDLEMODE); // start transition from idle mode
flight_ = false;
idle_ = false;
Off(OFF_FAST); // Fully stop the jetpack
}
void Loop() override {
unsigned long now = millis();
// Handle missile sound playback and log completion
missile_sound_queue_.PollSoundQueue(missile_wav_player_); // Handle missile sound playback
if (!missile_sound_queue_.busy()) {
PVLOG_NORMAL << "Missile Launch Sequence Completed!\n";
}
// Stop idle mode after timeout
if (idle_ && (now - timer_ > JETPACK_IDLE_TIME)) {
StopIdleMode(); // Stop jetpack if idle for more than defined time
return; // Exit early to avoid further processing
}
// Start idle loop after transition sound finishes
if (idle_) IdlePlaying();
// Start flight loop after transition sound finishes
if (flight_) FlightPlaying();
}
- I have looping sounds (idlemode or flightmode)
void IdlePlaying() {
if (idle_ && !jetpack_wav_player_.isPlaying()) {
jetpack_wav_player_.PlayLoop(&SFX_idlemode); // Start idle loop
SaberBase::DoEffect(EFFECT_IDLEMODE,0); // is there a way to have SaberBase::DoEffect(EFFECT_IDLEMODE,0) repeat itself at the same rate as jetpack_wav_player_.PlayLoop(&SFX_idlemode) ?
}
}
//idlemode & flightmode are two sounds that I am not confident if an OLED animation can be synced while the sound is playing!
void FlightPlaying() {
if (flight_ && !jetpack_wav_player_.isPlaying()) {
jetpack_wav_player_.PlayLoop(&SFX_flightmode); // Start flight loop
SaberBase::DoEffect(EFFECT_FLIGHTMODE,0);
}
}
- The last ones are a series of sounds that I would like to play once, after one another, without gaps or interruption between each other, and they play in addition of what is already playing (sounds 1 to 3). Also, they need to trigger their
SaberBase::DoEffect
equivalent so the various OLED annimations representing these sounds can play synchronised as well.
void MissileHelper(Effect* effect1,EffectType effect2) {
PVLOG_DEBUG << "Queuing sound: \n";
missile_sound_queue_.Play(SoundToPlay(effect1));
SaberBase::DoEffect(effect2,0);
}
// I want the effects to play one after the other without overlapping or interrupting one another and without gaps.
// Sequential sound queue for missile launch sequence
void PerformMissileLaunchSequence() {
PVLOG_NORMAL << "Starting Missile Launch Sequence\n";
// create animation for OLED of viewfinder coming down
MissileHelper(&SFX_aiming, EFFECT_AIMING);
// create animation for OLED of targetting
MissileHelper(&SFX_targetting, EFFECT_TARGETTING);
// create animation for OLED of jetpack launching missile
MissileHelper(&SFX_missilelaunch, EFFECT_MISSILELAUNCH);
// create animation for OLED of explosion
MissileHelper(&SFX_missilegoesboom,EFFECT_MISSILEGOESBOOM);
if (!flight_) { // Perform "Mando Talk" if not in flight mode!
// create animation for OLED of mando & boba talking
MissileHelper(&SFX_mandotalk, EFFECT_MANDOTALK);
PVLOG_NORMAL << "Mando: Nice shot!\nBoba: I was aiming for the other one!\n";
}
// create animation for OLED of viewfinder going back up
MissileHelper(&SFX_disarm, EFFECT_DISARM);
}
And just in case you are curious, here is my latest jetpack_prop.h version 48:
jetpack_prop.h (25.6 KB)
I would love to know if you think my code could be (add General Grievous voice)âworthy of addition to your collectionâ? I believe that I reduced repetition as best as I can. If you find more repetition that I missed, please let me know. Are my sounds playing scenarios coded properly?
Thank you for reading so far,
Thank you in advance for any help/comments/review you can provide.
MTFBWYA.