Howdy, Stranger!

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

Sound() only allows one track at a time?

edited March 2014 in Questions Posts: 277

Hey everybody,

So Codea2 is out, it runs super smoothly on my ipad retina, and I'm a happy camper (thanks to everyone involved).

I'm digging a little in the new music() function: is there really only one track playing allowed at a time? Say, I want to play an mp3 file as the background music, and then, on top, some wind noise mp3, combat sound (mp3), stepping noise, etc.

Is that not possible at all?

Tagged:

Comments

  • JohnJohn Admin Mod
    Posts: 639

    The music() function is for playing single music track in the background and sound() can be used to play sound effects and other noises on top. You can use sound() on with mp3 files too.

  • Posts: 277

    oh this is fantastic... thanks!

  • Posts: 22

    But sound() is for the synthesizer, so you can´t have a music track in the background and have for instance a voice on top, can you? Is it possible to use the synthesizer for background music? Like making sounds on top of each other? (Haven´t had the time to try it out)

  • SimeonSimeon Admin Mod
    edited March 2014 Posts: 5,430

    @Pirke sound() can now play other types of sound effects. Just tap the sound() function to see the picker, you can play .wav and .caf files (not sure about mp3). Edit: you can also adjust the pitch and volume of sound effects.

  • Posts: 211

    when I put music() , this "erases" my buttons sounds :(

  • JohnJohn Admin Mod
    Posts: 639

    To stop playing the current music track use music.stop()

    There are a few undocumented features with sound() as well, which I will put into the reference in the next update.

    If you play a named sound (not a generated one) it returns a SoundSource object, which has a few properties and functions you can use to control it. You can also make sound effects loop.

    source = sound(name, [volume, pitch, pan, loop])
    
    -- whether the sound is looping or not (boolean)
    source.looping 
    
    -- volume of this particular sound source (number)
    source.volume  
    
    -- pitch of this sound, also how fast it plays (number)
    source.pitch
    
    -- whether this effect is paused or not (boolean)
    source.paused
    
    -- whether this effect is muted or not (boolean)
    source.muted
    
    -- the pan of the sound, alternates between the left and right speakers (number)
    source.pan
    
    -- whether the sound is currently playing (boolean)
    source.playing
    

    This is pretty useful for various effects, such as playing a repeating engine sound and modulating the pitch and volume based on the current speed, gear etc. You can also use it to fade sounds in and out, etc.

  • Posts: 211

    Thanks @John!

  • Posts: 22

    Eyh! That´s super! A world of noises just opened up. :D

  • Posts: 2,043

    @John, that's great. Lots of nifty possibilities with that.

  • Posts: 1,976

    @John Screenshot + bookmark

  • dave1707dave1707 Mod
    Posts: 8,675

    @SkyTheCoder All of the above sound options are listed in the built in documentation under sound/music. The sound option names are the same as the music option names and work the same, so you can see information there.

  • Posts: 1,976

    @dave1707 I know, I re-read the documentation. Screenshot + bookmark anyway though, so if someone asks how to change the pan of a sound or something I can direct them to this page.

Sign In or Register to comment.