"AnimationFrameSoundVolume"? [solved with "setSoundProperty"]

  • #1, by MachtnixSaturday, 20. February 2016, 21:00 8 years ago
    Hi!

    I have looked for a method to adjust one sound's volume only. The sound function doesn't work, because it increases and decreases all sounds of the same kind. I didn't found a function or an order to regulate only ONE sound.

    That's why I set the sound I want to adjust to the option "background-music". Now I can increase/decrease the volumne in a Lua script with Kulisse:setValue(VSceneMusicVolume, s). That works perfectly (it's the changing volume of my waterfall noise: the closer the person the louder the noise).

    Yesterday I decided to use background music. Bam! The gamer should change the volume by itself. Some doesn't like music at all, do they?

    But it wasn't that easy because I used up (verbrauche) my scene background music option.

    I searched another Lua Vis object to allow to manipulate a single sound's volume, but there wasn't one.
    Only this: AnimationFrameSoundVolume. Ah, that's sounds good. It's possible to make some slider with.

    I made a dummy object with an animation which has only one frame. Put in the music file as sound. After a lot of not working trials (and crashes) I made ONE big file with all background music I want to use as a loop, playing in a line one after another.

    After calling the animation at the beginning of the game it works (at the moment it plays only one time, but I think it will be possible to make an endless loop somehow).

    Now the second step: I have a little interface to regulate the volume. I found something like this in the "MagicalPotions"-game; I still try to understand how all this Lua works...

    But instead of music volume or sound volume I have to adress the AnimationFrameSoundVolume.

    How can I get this? I think I have to get the animation object first, then I have to get the frame index (it's only a zero frame), then the inside sound object and then I have to build some loops to increase or decrease the sound object volume's value from 0 to 100. Or something like that.

    I bang my head; I can't stand this object stuff... I can't catch /adress this object..! :-(

    Maybe I can put the background music in the normal background music tab like 99% of the developers do, but that means I have to change the single sound volume with this frame thing. Vice versa. The problem will be the same.
    Maybe the music don't stop after changing the scene, that's still bad...

    Machtnix

    edit: maybe there is another way to manipulate a single sound, by ID or link or setVolume or whatever. I don't mind.

    Thread Captain

    1097 Posts


  • #2, by afrlmeSaturday, 20. February 2016, 23:18 8 years ago
    According to the data structure page in the wiki, the "AnimationFrameSoundVolume" field is not scriptable. Whether that is true or not I have no idea - never tried manipulating it before.

    I'm not 100% following what you have written. Do you want the sound to continue seamlessly into the next scene or are you wanting it to stop at the end of the scene?

    If the latter then you could play & manipulate the sound directly with Lua & the openAL sound engine.
    -- start a linked sound
    startSound('vispath:sounds/example.ogg', {flags=1, volume=70, loop = true})
    

    -- update active sounds parameters
    local soundID = getSoundId('vispath:sounds/example.ogg')
    setSoundProperty(soundID, {flags=1, volume=80}
    


    You can find all the different sound functions (with example scripts) via this page here. Same place I got the code examples from above.

    Imperator

    7278 Posts

  • #3, by MachtnixSunday, 21. February 2016, 00:08 8 years ago
    You are my hero :-)

    OK, a lot of facts together.
    According to the data structure page in the wiki, the "AnimationFrameSoundVolume" field is not scriptable.

    Ah, f... I don't read this (I used a paper print). But this setSoundProperty you propose looks fine. Shall be what I want.

    I have three kinds of sounds:
    1. the usual SFX-effects (footsteps, noises, ambiente and so on). Could adjust with the standard setVolume.

    2. this ONE sound with volume changing depends on where the character stands. This volume changes between 0 to 50% by Lua script. I set it into the background music tab. So the sound doesn't disappear after changing interface or inventar. It's back again and there all the time - louder close to the waterfall, silent far away.

    3. and now a new background music. The player should adjust the music's volume (or mute it completely) with a simple slider interface. In this game I have only one scene. Doesn't matter if the music must play in another scene or not, because it doesn't exist. All I want is to loop the music. And the music shouldn't disappear or restart after using a interface or the save-menue.

    If I put the music into an animation frame or into a simple "play sound"-action, the music stops after changing scene or interface. It's not the best solution, I know, but I didn't found something else.

    I know, the background music tab is for using a background music. But if I do this - I have to put my adjustable sound no.2 to another place.

    I'm on the Lua wiki pages every day, but I haven't realize not yet how this "property" thing works. Looks easy now. Well, I'll try it. Thx.

    I pick up the file's ID from the source file on the HD, right?

    Machtnix

    Thread Captain

    1097 Posts

  • #4, by afrlmeSunday, 21. February 2016, 00:40 8 years ago
    The sound has to be active (playing) to be able to generate an id for it. You return that as shown in the second example I provided by using the getSoundId() function & linking it to the files path (vispath = relative to root folder containing your ved file).

    Quick note: it is technically possible to play multiple instances of the same file, at the same time which can cause issues with returning the correct soundId as it will always return the newest entry related to the specified file path from the temporary active sound table.

    P.S: the link I provided in my last post is an index of automatically generated wiki pages from code written in the engine itself. The syntax & content of them can be a little hard to understand which is why I have provided my own examples on the main script index page in the wiki, however I don't remember if I got round to adding examples & information in layman's terms for the sound functions.

    Imperator

    7278 Posts

  • #5, by MachtnixSunday, 21. February 2016, 16:20 8 years ago
    So, I'm back. After trying half a day to make the sound as continued (with conditions, and values, and animation frames, and what ever..) I found a very simple, but unlogical solution: start the sound file at every end and at every beginnung of each scene.

    So what? I start the sound with a simple "play sound"-action once and call the action after every switch. I expected (seems logical to me) that I get back 20 sounds at the same time (like an endless loop recall) if I switch to the scene 20 times... But there is only one stream. So I get my background music continued all the time, straight forward, doesn't matter if I switch to interfaces or to another scene. Well. I hope, this works in the final vis-file also...

    The "setSoundProperty" works, and now I have to make an easy slider thing to adjust the volume.

    Btw:
    I get a lot of "Warning: audio buffer is probably too small" in my log-file. That depends on my PC-system.? Or can I change this buffer somewhere like the picture cache size?
    My background music takes 10 minutes. Even as an ogg-file with a quality of "5" it's huge...

    Machtnix

    Thread Captain

    1097 Posts

  • #6, by afrlmeSunday, 21. February 2016, 16:31 8 years ago
    I have no idea if it's possible to adjust the audio buffer. I don't see anything in the data structure for it. Simon or David would probably know. Anyway if it's just a warning & the file is still playing then I wouldn't worry about it.

    Imperator

    7278 Posts

  • #7, by MachtnixSunday, 21. February 2016, 16:43 8 years ago
    Thanks.
    I believe every sound-file will be "unzipped" by (at?) playing, even it's an ogg or a mp3. A "pcm"-stereo sound file with a qualtity of 44000 and a length of ten minutes will take more than a 70 MB size, right?
    The sound is still working, but sometimes while several sounds are playing at the same time, it "freezes" a little bit, like bad received digital television... ;-)

    Nice weekend,
    Machtnix

    edit: At last I found it: http://www.visionaire-studio.net/forum/thread/vorlage-lautst.... Thank you!

    Thread Captain

    1097 Posts

  • #8, by afrlmeSunday, 21. February 2016, 23:46 8 years ago
    That's pretty old. There was a slightly newer approach to volume sliders in the advanced menu template I created the other year, however... I think I came up with an even easier method, but I don't think I got around to creating an example for it anywhere - sorry. I guess what you linked will be ok for you, plus it's in German too, which will probably be of help.

    Imperator

    7278 Posts

  • #9, by MachtnixMonday, 22. February 2016, 15:53 8 years ago
    @AFRLme: too late.... :-)
    This script by "Einzelkämpfer" works perfectly and I use it. And most important: I understand it! I can pull the slider buttons with the mouse and that's what I wanted. Increase, decrease and mute with cursor arrow buttons works also. I'm happy now.
    Btw: I found this German script on your dropbox, I think... ;-)

    I have exchanged the background music with the water noise and I can adjust the music with the music volume slider now.
    Only this ID-thing I don't understand really: the playing (!) background music gets the ID of 1, my playing sound gets 3. Doesn't matter which file is loaded. All unused sounds get an ID of -1, even there are in the game, but paused, or not. I hoped to build a selection of background music the player can choice, but it doesn't work with IDs this way. So I have to realize it with some path stuff - and that's too complicated to me yet...

    Machtnix

    Thread Captain

    1097 Posts

  • #10, by afrlmeMonday, 22. February 2016, 17:00 8 years ago
    Yeah it only generated an ID if the sound is currently playing, I think. Otherwise it returns -1.

    The best thing to do for the Lua sound engine (openAL) is to create a Lua table containing paths to various sounds.
    soundz = {} -- create a global table called "soundz"
    soundz[1] = "vispath:sounds/example1.ogg"
    soundz[2] = "vispath:sounds/example2.ogg"
    -- etc
    

    -- access an entry based on index number from "soundz" table
    startSound(soundz[1], {flags = 1, volume = 80, balance = 40, offset = 1000})
    


    As for the script you mentioned... yes I might have added it to my dropbox account. I have various things belonging to various people on it. More of a collection of stuff that people can access, although I've not added anything to it in ages as we have the wiki now & I can upload templates & resource files directly to that instead.

    Imperator

    7278 Posts

  • #11, by MachtnixMonday, 22. February 2016, 17:21 8 years ago
    Thank you. After reading it seems VERY easy to make a song selection menue.... I hope it will be :-)

    Btw: The "old" script was still in the forum:
    http://www.visionaire-studio.net/forum/thread/vorlage-lautst...

    Thread Captain

    1097 Posts