Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

fadeoverto macro issue in sugarcube 2.11.0

edited December 2016 in Help! with 2.0
In my game I have a countdown triggered at the start to let the player know how long he has before the oxygen in his room runs out. I accompany this with a looped alarm sound called low_air.

If the player doesn't escape in time I send them to a 'death' passage, and in there I fade the text to nothing to simulate them losing consciousness.

I also want to fade the sound of the alarm out too, so I'm using:
<<audio "low_air" volume 1 fadeoverto 15 0>>
But when this passage is triggered, the alarm fades out almost immediately, instead of over the 15 seconds I've specified in the macro.

I suspect it has something to do with the fact that the same sound clip is still being looped when this command is triggered.

I suppose in that I know how long the player has before they die, I could tell the clip to fade out over that time from the beginning, but then I would have a gradual fade instead of it only fading when they actually die.

But I can't do this anyway, thinking about it, because the clip itself isn't long enough.

Comments

  • edited December 2016
    Never mind. It clicked when I wrote that last sentence.

    It won't fade over 15 seconds because the clip itself is barely 4 seconds long.

    I can be such an air-head.
  • edited December 2016
    Well that's not the problem afterall. I edited the sound clip to make it 20 seconds long and it still fades immediately.

    Are looped fades possible?
  • Would a 'for' loop help here? I am no means an expert in JS - although I kinda know how a for loop works but I'm not sure how to custom fit it to what you want exactly either. (I kinda know the basics of JS. Very basics. lol)

    Hopefully someone else can help out here.
  • Well the macro should still be fine, I use the same one in my story and it works. Have you properly replaced the initial file?
  • edited December 2016
    Yes. If you hover over an mp3 file it gives its duration and it states 18 seconds long.

    It's definitely something to do with the fact that I already have the clip looping when I try to trigger the fadeout in the 'death' passage.

    I know this because if I remove the one that's looping from the start, the fade one works as it should.

    One thing I haven't tried is creating a file of the same sound but with different names.

    I'll gave that a go now.

    [edit] Mmm, not ideal. It works in a fashion, but I have to stop the first file on entering the 'death' passage which results in an ugly clip in the sound, as one stops and the other starts.

    Gryph, my knowledge of JS is virtually non-existent, but maybe it's the answer.
  • Jud_Casper wrote: »
    Yes. If you hover over an mp3 file it gives its duration and it states 18 seconds long.

    Gryph, my knowledge of JS is virtually non-existent, but maybe it's the answer.

    I think so unless there's something in the Audio Macros documentation that will help with that. I'm deaf, so I can't really help out with it any more than general ideas.
  • Gryphbear wrote: »
    Jud_Casper wrote: »
    Yes. If you hover over an mp3 file it gives its duration and it states 18 seconds long.

    Gryph, my knowledge of JS is virtually non-existent, but maybe it's the answer.

    I think so unless there's something in the Audio Macros documentation that will help with that.
    Help with what?

  • edited December 2016
    Around here - http://www.motoslave.net/sugarcube/2/docs/macros.html#macros-cacheaudio

    I dunno. But you've probably already pored over it, since I see the fadeoverto 'action' in the first part so I'll probably stop suggesting advice on this. lol.
  • I think you may be on to something with the playlist, but I can't get my head around its usage enough to know how it might fix my problem.
  • Off the top of my head--on my tablet again, so you're not getting better than that at the moment--there shouldn't be any problems fading a looping audio track which is guaranteed to loop during the fade. I cannot rule out shenanigans, however, so I'll do a test later.

    What browser, and version, have you tried this in?
  • edited December 2016
    Thanks.

    Firefox 50.0.2 (the latest as far as I'm aware)

    If it's any help, I can guarantee that removing the audio macro that's triggered to loop from the start of the game, means that the one I'm using in the 'death' passage fades as it should.

    BUT if I have the track already looping, the fade takes about 2 seconds when the player enters the 'death' passage.

    Here's the two passages in question.

    Start passage:
    <<if visited() is 1>><<script>>setup.startCountdown(2 * 60, 'killplayer');<</script>><</if>>\
    <<timed 3s>><<audio "low_air" loop play>><</timed>>
    
    Death passage:
    <<audio "low_air" volume 1 fadeoverto 15 0>><<audio "dead_breath" play>>
    
  • [UPDATE] Don't ask me what I did (or hadn't done in the first place) but it's working now. Sorry for the wasted time.
  • edited December 2016
    At my workstation now. I'm still going to check it out, just to make sure.

    Beyond that, some unrelated observations.

    In the vacuum trap start passage, I'd expect that you'd probably want to start the air warning track playing within the same <<if>> as the countdown, rather than outside of it. For example:
    <<if visited() is 1>>
    \<<script>>setup.startCountdown(2 * 60, 'killplayer');<</script>>
    \<<timed 3s>><<audio "low_air" loop play>><</timed>>
    \<</if>>\
    

    In the asphyxiation death passage, you probably don't really need to set the volume of "low_air" to 1 in this case, since the track is currently looping and, presumably, already at max volume. If you were going to need to adjust the volume anywhere, it would likely be on the initial play. For example:
    \<<timed 3s>><<audio "low_air" volume 1 loop play>><</timed>>
    
    And:
    <<audio "low_air" fadeoverto 15 0>><<audio "dead_breath" play>>
    
  • Thanks. I'll go clean it up now.
  • edited December 2016
    Okay. It turns out to be a legitimate issue with the audio subsystem's fading code. It only manifests on looped tracks whose remaining duration is less than the requested fade duration.

    Since your original track's total duration was approximately 4 seconds, its remaining duration at any point during playback was definitely less than the 15 second fade you were attempting, thus triggering the issue.

    Your current approximately 20 second track may or may not trigger the issue. If the fade started before, or slightly after, 5 seconds into a playback loop, it would either not trigger the issue or not be noticeable if it did. On the other hand, if the fade started nearer to the end of a playback loop, then you should still be able to notice an abrupt fade.

    I'll have a fix out soon-ish.


    Technical details for the interested (skip this if you're not): There was a bit of code which sanitized the fade duration to ensure that it was not less or greater than some sane values. On the high end, the fade duration would be clamped to the remaining duration of the track, to keep the fade from ending prematurely—though that would mean it would fade faster than asked for, so whether that was a good thing is a toss-up. Unfortunately, whether or not the track had been looped was not taken into account, thus causing the issue for looped tracks whose remaining duration for the current playback loop was less than fade duration.
  • Ah! Thanks for the update.
Sign In or Register to comment.