Music player & background music

  • #1, by dramaminiWednesday, 17. September 2014, 10:58 10 years ago
    Hi!

    I'm working on a first person adventure.
    In a certain scene, I have put a gramophone and a vinyl record with a playlist of 10 songs.
    I would like to choose the background music by clicking the prefered song in tracklist.
    For example, when I click "track02", I would like this song to be set as background music.

    Additionaly, when "Track02" is finished, "Track03" should start playing automaticaly, then "Track04" etc... (Like a regular vinyl record.)

    Finaly, the music should continue in all scenes except menu.
    If track10 is finished, then background music stops.

    Is that possible? Any ideas?

    * Congratulations for Visionaire, it is a great product
    ** I wish you could add a rippling water effect for static background images (like "Riven"), it is a must-have plugin for first person adventures! wink
    *** Sorry for my bad english

    Newbie

    44 Posts


  • #2, by SimonSWednesday, 17. September 2014, 12:38 10 years ago
    Hi,

    that's not that easy... One way to do this might be setting the music then wait the length of the music and set the next music... Don't believe that is a good approach. The other approach would be using lua, I can try to code something if you want, would involve http://wiki.visionaire-tracker.net/wiki/StartSound and http://wiki.visionaire-tracker.net/wiki/GetSoundProperty.

    As for a ripple effect, I'm updating shaders at the time and it will have some warping effects.

    Thread Captain

    1582 Posts

  • #3, by dramaminiWednesday, 17. September 2014, 13:01 10 years ago
    I would be greatful if you could help me with the code...

    I tried to use songs as sounds, in order to use the action "Wait until sound is finished", but when I change scene, the sound stops...

    *Perfect! You are the best

    Newbie

    44 Posts

  • #4, by SimonSWednesday, 17. September 2014, 13:10 10 years ago
    Okay here is what I tried:

    musicplayer_songs = {"vispath:data/sounds/sounds/episode_1/chapter_1/0000_ballon_platzt.ogg",
    "vispath:data/sounds/sounds/episode_1/chapter_1/0000_nehmen_1.ogg",
    "vispath:data/sounds/sounds/episode_1/chapter_1/0000_presse.ogg",
    "vispath:data/sounds/sounds/episode_1/chapter_1/0000_tuer_auf.ogg",
    "vispath:data/sounds/sounds/episode_1/chapter_1/1001_auftauchende_zahnbuerste.ogg",
    "vispath:data/sounds/sounds/episode_1/chapter_1/1001_erbkiste_ruetteln.ogg",
    "vispath:data/sounds/sounds/episode_1/chapter_2/2007_quietschen_fluegelschlag.ogg"}
    musicplayer_config = {active = false, currentsound = 1, currentid = -1}
    
    function musicPlayerMain()
    	if(musicplayer_config.currentid~=-1)then
    		local offset = getSoundProperty(musicplayer_config.currentid, "offset")
    		if(offset==-1)then
    			musicplayer_config.currentsound = musicplayer_config.currentsound + 1
    			if(musicplayer_config.currentsound == table.getn(musicplayer_songs) + 1) then
    				unregisterEventHandler("mainLoop", "musicPlayerMain")
    				musicplayer_config.currentsound = 1
    				return
    			end
    			musicplayer_config.currentid=startSound(musicplayer_songs[musicplayer_config.currentsound])
    		end
    	end
    end
    
    registerEventHandler("mainLoop", "musicPlayerMain")
    
    function startMusicPlayer()
    	musicplayer_config.currentid=startSound(musicplayer_songs[1])
    end
    


    Replace the sounds on top with you own, the vispath: tells the engine that these files should be packed into the vis if you export the game, better use always / instead of \ for the crossplatformness. I haven't tested how the script behaves with savegames and how it behaves with menus.

    Thread Captain

    1582 Posts

  • #5, by afrlmeWednesday, 17. September 2014, 13:27 10 years ago
    One way to make sure it is remembered in savegames would be to make sure it writes current offset value & name of current track (or table index value) into vs values & on scene start query if sound is not active & have it play sound stored in value from the offset value stored in the other value.

    As for the water ripples: if Simon's warp effect (once added does not do the trick) then you might consider using a tool to generate water effects on your image & then export the effect as individual frames which can then be imported into vs as an animation.

    http://www.xiberpix.net/SqirlzReflect.html (one of the other members on here linked it a while back)

    Imperator

    7285 Posts

  • #6, by dramaminiThursday, 18. September 2014, 15:36 10 years ago
    Thank you Simon and AFRLme for your help!

    I Tried the script but I cannot hear any sound.. Probably I make a mistake with paths...
    I replaced the sounds but...nothing.

    What should I do if my project is at this directory?
    "C:/Visionaire/MyGame/Audio/Music/Playlist/Track01.ogg"

    This is what I did:
    1. Replaced paths: "vispath:Audio/Music/Playlist/Track01.ogg"
    2. Created a new Script entry, named it "MusicPlayer", unticked "definition script" at properties
    3. At my playlist scene, created hotspots for every track. Left click action for every hotspot and then used "Call script" -> "MusicPlayer"

    Is this right?

    Newbie

    44 Posts

  • #7, by afrlmeThursday, 18. September 2014, 16:24 10 years ago
    Definition scripts are used to define variables & functions on game launch, whereas executed scripts are best suited for scripts that do not contain functions etc, as you need to explicitly call the function to execute it.

    Your sounds should be located in a folder inside of your projects root folder, hence what you wrote above in (1) should be correct. I believe filenames are case sensitive, not sure about folder names though.

    vispath: represents the root folder of your game project & thus if your projects .ved file or .vis file is located in c:/visionaire/mygame/ then it will return just that.

    What Simon's script is doing is checking the currently playing tracks offset (playtime) against the max playtime of the track & is also checking if the index is less than or equal to the max amount of tracks listed in the table & if the track index number returned is greater than the max amount of tracks then it automatically kills the loop.

    Quick note: each time you executed the script in method 2 & 3 you mentioned above, you were technically resetting the script back to the initial default values. See line 8 of the script.

    To start the music playing I believe you need to perform an execute a script action part containing...
    startMusicPlayer()
    

    ...I have not written this script & without studying/testing it I can't say for certain. I would have probably written it differently than this, but that's me.

    Imperator

    7285 Posts

  • #8, by dramaminiWednesday, 24. September 2014, 03:41 10 years ago

    Thank you! I can hear now, but the script is not working very well...

    i. When I change scene, it goes to next song.
    ii. When I click Track02 I hear Track01
    iii. When I click track01 and click track01 again,
    the song is playing twice.
    iv. Same problem occures when I click Trak02 etc..

    That's what i did and works:

    A. Ten hotspots, one for every song. "Track01, Track02 ... Track10"

    B. "Track01" Left Click Action:
    Quit action Left Click Track02 , Quit action Left Click Track03, etc..
    Change background music "Track01"
    Pause for x seconds (x for the song duration)
    Change background music "Track02"
    Pause for x seconds
    ....
    Change background music "Track10"
    Pause for x seconds
    Change background music ""
    Quit Current Action

    C. Same as B for Track02, 03, 04, etc...

    -------------------------------------------------

    Some questions:

    1. How can I pause or resume a track?

    2. Is there a way to "force" a sound to continue playing at scene change, even if there is a fade out effect inserted?

    3. Music in background has a "fade in / fade out" effect by default.
    Is there a way to choose on or off, at certain tracks?

    4. Music in visionaire has by default, a "compressor / limiter" effect inserted.
    Can I turn it off? This is good for low volume sounds or for preventing sounds to clip, but high volume mastered songs, sound a little bit pushed.

    I'm a musician and sound engineer, not programmer, maybe that's why I find it a little bit difficult under certain circumstances in my project. smile

    Also, I think that would be nice and usefull if there were "layers" for music in visionaire.
    For example one layer for Background music, one for ambient sounds and one for sound effects so all these can be mixed together.

    Newbie

    44 Posts

  • #9, by afrlmeWednesday, 24. September 2014, 04:16 10 years ago
    I haven't read everything you have written, as it's late & it's too much text for me to process.

    Lua started sounds do not work in the same way as sounds started via the editor. Sounds started via lua get added to a table & given an id number. There is no real limitation to the amount of sounds you can start with the lua method, other than the limitations of your computer.

    It does not check if a sound already exists/is active & thus it will duplicate said sound if you start the sound again, & again etc.. As a failsafe you could create a value or variable in which you declare the currently active background song & then you query if song does not equal current song & then decide what to do with said information.

    Are you sure vs has a limiter & or compressor module enabled? I've not noticed it myself - I wasn't a sound engineer but I dabbled in music production for 5 years or so.

    With the lua audio commands you can use them to play as many sounds as you like & use the parameters to mix them as you please. Essentially same as audio tracks & modulation. I hope some effect modules like reverb, echo, distortion & filter eq are added at some point in the future.

    According to the data structure it says that you can script the normal editor background music path, volume & balance. Oh speaking of balance I think only mono channel sounds can be panned. I can't remember if David fixed it so that stereo sounds could also be panned. I have bad memory.

    Imperator

    7285 Posts

  • #10, by dramaminiSaturday, 25. October 2014, 20:18 10 years ago
    Thank you so much for your help and guidance!

    I would like to ask something else:

    Music for background has a "fade in" effect.
    That means, that when you play a music file, the volume level of the audio file starts from zero and about 1 second later, reaches the specified volume value. (e.g. Music Level = 100)

    Unfortunately, this causes a bug: If you change background music and then try to move to another scene faster than 1 second, the music volume never reaches 100% of level, but stays at lower values.
    When you change background music you have to wait (e.g. 1 or 2 seconds) and then you should try to change scene. Only this way you can keep your audio volume at desirable level.

    Is there any way to solve this issue?

    Newbie

    44 Posts