Howdy, Stranger!

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

Sequencing audio

Hello,

I was wondering if there was anyway to sequence audio so the audio file plays not only once you get to a certain passage (which I know how to do) but also when the previous audio file is finished?

I'm trying to put music to it but i need it to gradually build over time as the player progresses.

Any ideas?

Im using sugarcube in twine 2.

Cheers

Comments

  • If you mean like in a playlist, then is there some reason you can't make a playlist out of the two pieces of audio?
  • edited April 2016
    Thanks for replying!


    To further explain:
    On the first passage, i have a song set to loop.
    On the second passage(and only on the second passage), i want to change to another song, but only after the first has finished.
    Same for the third and forth passages...

    The reason I don't just have a bunch of songs lined up in a playlist is because I want to write the music to smoothly transition depending on how far the player is into the story, so it all feels like one piece of music synced to what the player is reading.
    I could do this if there was some kind of macro that queues up the next audio file after the player has moved on to the next passage. If it where just a playlist the the next song would play no matter where the player was, and if it where multiple playlists the second would stop the first.

    Hopefully that makes sense.

    If this is just all impossible it would be good to know, just so i don't go ahead and write a bunch of music i can't use!

    Cheers
  • edited April 2016
    The HTML5 media elements, specifically the <audio> element, which is what underpins SugarCube's audio macros, are not perfectly suited to what you want to accomplish. They can, in theory, be used to do what you seem to want. There are, however, a number of factors in play, so I cannot give you a definitive answer without knowing more.

    Will your songs be gapless?

    How do you want the transition to occur? Will they be able to flow from one into the next directly or will they need a very brief crossfade?

    Assuming you have it ready, have you tried looping the first song (e.g. using the <<audio>> macro) to see if it loops to your satisfaction?

    Do you intend for your project to be available on mobile devices?
  • It's intentionally pretty sparse piano music, allowing me plenty of dead air to transition between each loop. No crossfades needed hopefully. I have a basic outline for the piece of music, from beginning to end, about 2 mins long, that I can cut into pieces and loop for about 15-20 seconds each. The first loop sounds great, it's just making sure it's not cut off by the next that's the problem.

    Not the end of the world if it doesn't run on mobile, but curious as to why that's relevant.

    Thanks again.
  • edited May 2016
    loops wrote: »
    It's intentionally pretty sparse piano music, allowing me plenty of dead air to transition between each loop. No crossfades needed hopefully. I have a basic outline for the piece of music, from beginning to end, about 2 mins long, that I can cut into pieces and loop for about 15-20 seconds each. The first loop sounds great, it's just making sure it's not cut off by the next that's the problem.
    Well, that sounds pretty much like an ideal situation for the HTML5 media elements, so it should be totally doable with them.

    One last question. Do you want the transitions to happen on specific passages (i.e. by name) or simply by virtue of having moved forward (i.e. by turn)?

    I should be able to write up a custom macro for this fairly quick—probably within a day. Since you haven't mentioned a version for SugarCube , I'm assuming that you're unfortunately using what comes bundled with Twine 2, which would be v1.

    loops wrote: »
    Not the end of the world if it doesn't run on mobile, but curious as to why that's relevant.
    Mobile browsers are not the same as desktop browsers. They, in general, have more restrictions about what you can do with various elements and APIs.

    In particular to the HTML5 media elements, they require user interaction to function and various things are disallowed (e.g. In the iOS browser core, adjusting the track volume, which is important when attempting to do a crossfade, is, bizarrely, disallowed—n.b. I'm not talking about the system/master volume).
  • edited May 2016
    Actually i'm using sugarcube 2.
    I guess having the transitions happen on specific passages rather than by turn would allow for more control?

    That would be amazing if you would, not sure how I could thank you.
  • loops wrote: »
    Actually i'm using sugarcube 2.
    Bless you.


    Anyway, you can find the new <<audioloopto>> macro set package on SugarCube 2's site (under: Downloads > Add-ons). The name is kind of gimp, but I didn't give it much thought.

    Install instructions, macro arguments, and basic usage should be covered by the package docs (read them), however, let me go over the usage a bit here.

    You'll need to use the <<cacheaudio>> macro as normal to setup your tracks—StoryInit is the likely place. Once that's done you'll need to setup how you want the loop transitioning to work—you should probably do that just after your <<cacheaudio>> section. That might look something like the following:
    /*
    	Loop track "A" until it ends while the current passage is "Primus",
    	then play track "B" instead.
    */
    <<audioloopto "A" "Primus" "B">>
    
    /*
    	Loop track "B" until it ends while the current passage is "Secundus",
    	then play track "C" instead.
    */
    <<audioloopto "B" "Secundus" "C">>
    
    /*
    	Loop track "C" until it ends while the current passage is "Tertius",
    	then play track "D" instead.
    */
    <<audioloopto "C" "Tertius" "D">>
    
    You should get the idea.

    Finally, all you need to do to kick everything off is to start playback of track "A", like so:
    <<audio "A" play>>
    
    n.b. The package docs cover this, but do not pass <<audio>> the loop action. The <<audioloopto>> macro itself handles looping—it must be done programmatically in this case to be able to switch to another track.

    The macros were tested in several browsers, including two mobile devices (iPhone and Kindle Fire HDX w/ Silk), and everything seems to work as intended—honestly, I was only worried about the mobile browsers.
  • edited May 2016
    Hiya,

    This is great! Thank you so much for doing this.
    If i could be so bold as bother you about some of the little issues i've come across just in the 30 mins i've spent with it...

    It stops all other audio from playing; I had some background noise going on which actually helps cover up the transitions between the loops, is there any thing i can do to change that?

    Is there a way to trigger the next track from a selection of passages. I have a junction point allowing the player to go to 4 different passages, but i want every passage to play the same loop. I tried:

    <<audioloopto "A" "here" "B">>
    <<audioloopto "A" "there" "B">>
    <<audioloopto "A" "or maybe round the corner" "B">>

    But that breaks it and keeps playing "A" whilst "B" plays.

    If none if that is doable, don't worry. This is great and will deff be useful.

    Thanks again!
  • edited May 2016
    loops wrote: »
    It stops all other audio from playing; I had some background noise going on which actually helps cover up the transitions between the loops, is there any thing i can do to change that?
    The macro does not change the playback state of any tracks, save for when the looped track ends. Even then it only loops the primary track again or initiates playback of the next track. Essentially, it only acts as a modifier to the looped track.

    Either you're doing something to cause the issue or something weird is going on. Just to ensure I'm not blowing smoke out my arse, I just tested your scenario and it worked as expected for me.

    How are you playing the background music?

    loops wrote: »
    Is there a way to trigger the next track from a selection of passages. I have a junction point allowing the player to go to 4 different passages, but i want every passage to play the same loop. I tried:

    <<audioloopto "A" "here" "B">>
    <<audioloopto "A" "there" "B">>
    <<audioloopto "A" "or maybe round the corner" "B">>

    But that breaks it and keeps playing "A" whilst "B" plays.
    Heh. I thought of that earlier this morning and I've already updated the macro set (about 30 mins ago as I post this) to allow you to do exactly that—just grab the updated package.

    A looped track may now have any number of passage triggers to other tracks—nor are you limited to using the same track. Your example is exactly how you'd do it as well. For example:
    <<audioloopto "A" "Primus"   "B">>
    <<audioloopto "A" "Secundus" "B">>
    <<audioloopto "A" "Tertius"  "C">>
    <<audioloopto "A" "Quartus"  "D">>
    
  • Amaaaaazing.
    It works. Thank you.

    The only last problem is the background noise stopping. I know kinda whats causing it:
    I set the background audio to 'fadeover to' on the same passage that the first loop starts. For some reason this fades the background audio out completely.
    It works fine if i just change the volume though.

    Any ideas?
  • loops wrote: »
    The only last problem is the background noise stopping. I know kinda whats causing it:
    I set the background audio to 'fadeover to' on the same passage that the first loop starts. For some reason this fades the background audio out completely.
    It works fine if i just change the volume though.

    Actually,
    I think it's effecting that macro throughout. Not just where both of those macros appear.
    Which is annoying as it's kinda crucial that i have those fades.
  • loops wrote: »
    loops wrote: »
    Actually,
    I think it's effecting that macro throughout. Not just where both of those macros appear.
    Which is annoying as it's kinda crucial that i have those fades.

    Actually, Actually,
    I think it's when I'm using two different audio macros in the same passage.
    In an earlier passage i fade out and then fade in a track 20 seconds later.
    It used to work, but isn't now. The two things that have changed is your new macros, and I also had to update from sugarcube 2.3 to 2.6 as the new macros required me too.

    Sorry for the spamming.
  • It's not any combination of the audio macros, built-in or the new add-on. They are, for the most part, designed to work together.

    loops wrote: »
    I set the background audio to 'fadeover to' on the same passage that the first loop starts. For some reason this fades the background audio out completely.
    It works fine if i just change the volume though.
    That was the clue. The issue is not within the audio macros at all.

    It seems that I broke SugarCube's clamping method when I did the ES6 (ES2015) refactor. /headdesk /headdesk /headdesk

    I'll need to issue a new release to fix the bug. Should be later today.
  • Cool, look forward to it.

    Thanks for doing all of this. Messing around with the audio stuff was one of my main motivations for getting into twine, so I really do appreciate all the help.
  • The new release of SugarCube 2 (v2.6.1) is out. Took a little longer than expected—pain meds are sapping my focus.

    Try it out and let me know if you have any further issues.
  • Sorry, been busy with work. Just had a chance to run through and see if everything is working and it is and it's great and thank you so much.
  • Heya, meeeee again.

    Was wondering if I could get your advice on issue to do with this macro. The looped audio will only switch to the other track whilst the player is on the passage that forces it to do so, this is fine 98% of the time. However if the player skims through that passage and clicks on to the next one before the first loop ends, the loop will carry on as before and not change to the next audio file as the player is no longer on that passage.

    Does that make sense and is there anything i can do about this?

    Thanks

  • Just a note that I haven't forgotten about this—my hobby time has been extremely limited as of late.
  • Okay, @loops. I've implemented some queuing within the <<audioloopto>> macro set which should resolve your current issue. I've updated the package on SugarCube 2's site (under: Downloads > Add-ons).
Sign In or Register to comment.