Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Hi, I'm trying to use ccbSetSceneNodeProperty to play a sound, and to alter the volume. Goal is to crossfade between two themes of music. Doesn't seem to work: I tried Properties such as "PlayMode" or "Volume". For Playmode I tried to use to the string "looping" Can Audio nodes be accessed by script at all? Thanks. (for webgl) |
||||
|
Hi Dieter, It's a misfortune that js is lame and doesn't really have that debugging tools we need. If we had at least some of them, you could probably unminify copperlicht.js and check which properties are available for webgl: else if (b == "Position") { That way you would know that unfortunately, volume is not an option that you can set. Also, if it was somehow possible to just access node properties directly from browser we could probably just check all of them. For example we could set a break point or simply console log object and access it's properties. If it was possible we could probably see something like: If js was not a silly vhs, but glorious beta we would probably learn that there is minified parameter Yg which value strangely corresponds to volume value we set for sound node. Well at least js dynamically typed not like basic so we can modify this parameter directly. For example set it to 50% ccbGetSceneNodeFromName('bg').Yg = 0.5; |
||||
|
Also you will not be able to get a good crossfade effect by changing volume linearly, you need to adjust volumes logarithmically. |
||||
|
Hmm, also there is a good example: https://codepen.io/lukeandersen/... Probably, if you're using 2d sound it's a good idea to use audio context directly without coppercube - I never tried it before, and it might break other sounds. Or at least you can use formula from this example for smooth crossfade: var x = parseInt(element.value) / parseInt(element.max); |
||||
|
Thanks, very informative, despite the sarcasm. I'll see whether I can use some of this. So "Yg" is it. Stroke of genius, only a fool wouldn't immediately and intuitively know about "Yg" Besides, the lack of proper ccb functions in that respect really does force you to hack copperlicht.js. And even then, where is "PositionAbs" for instance? Not in your list and not in the Api reference. I wonder whether CC uses IrrKlang for audio, so maybe we could use IrrKlang syntax directly. We can use IrrLicht syntax in CC, as long as the target is webgl. That said, I already made a simple yet flawlessly working 3D sound engine in JS, so, facing already hours of trial and error with CC sound, it might be easier to just integrate my own 3D sound engine further into CC. It supports real 2.5D, like left and right ear, depending on player angle and soundposition. Panning isn't yet a living JS standard (or wasn't when I wrote it, like 1-2 years ago), but the big browsers support it (maybe except opera and safari). Either way, thanks. I sure recognize that your approach is more effective than mine, especially as I am still coding JS mostly in notepad. It's probably more of a spartan attitude than unawareness of the tools. |
||||
|
Well, I tried ccbGetSceneNodeFromName('music').Yg = 0.5; It does nothing. Did it work for you? |
||||
|
Uh, in my second last post, I confused the names IrrLicht and CopperLicht. I guess CopperLicht is the successor of IrrLicht. This debugging / hacking really consumes my concentration span... |
||||
|
Which version of coppercube are you using? I'm on 6.6. Here is mine ccb: https://drive.google.com/file/d/... Try and let me know if it also doesn't work. |
||||
|
Ok, I've read the previous post - nice you've sorted that out. |
||||
|
I still have V 6.4, and I will update, but not right now. I tried to load it, error msg says "was saved with newer version". Funny enough, I can start playing a sound using node.Vn=2; I can write the value of node.Yg to an alert. Altering its value however does not change the Volume. But I need Volume, and right now I'm heading towards my extension. Thanks anyway, was an interesting rabbit hole ^^ |
||||
|
Yay! Nailed it. After about a day of fruitless attempts to control CC sound scene nodes, I have integrated my own 3D sound engine into CC, and it works like a charm. Your help was very useful, in that I can now read some values: given "kiddo" is the sound node handle: a_path=kiddo.Ub.n; // gives the audio file path of the node a_loaded=kiddo.Ub.loaded; // loading complete a_volume=kiddo.Yg; a_play=kiddo.Vn; Playmode: 0=nothing, 2=looping a_2d=kiddo.Bg; // the "2D sound" boolean flag I then simply load a copy of each file as simple, independent JS audio object. The file is already cached by CC, so no loss there. If the CC node is looping, I stop it by setting playmode to zero, but set my copied sound to looping. I inherit the positions of the sound nodes, as well as radius, volume, 2D etc. This way I can set all sounds up in CC as usual, and it then extracts the required data and substitutes the whole audio stuff. Besides 3D sound with dynamic positioning and radius,Yaw angle panning and distance fall-off, I can also use all of the JS audio Api, including: Volume, panning, replay-speed (alter the replay sampling rate, eg a 44.1kHz file played at 22.05kHz is playing double as long and half as high in pitch. I used this for randomly pitched riccochet sounds in gun fights), looping on/off, pause. It's just so much better to have real 3D sound perception in a game! Mixed with 2D music, it's getting cinematic qualities. The cross-fading thing BTW I still have to implement, but it seems like a piece of cake, now that I have all required functions at my disposal. This shall be the dessert. Thanks a lot, okeoke, your hints allowed me to integrate this in a very seamless and clean way. |
||||
|
Update, I had to wait for 2 hours until the rain stopped falling, so I coded the cross-fading part, works now. I use proximity-triggers to switch to an other music theme in various areas of the world. Definitely adds a pro touch to it. I remember this impressed me a lot in "Indiana Jones, Fate of atlantis" 2D adventure. Actually, as all music pieces have a kind of smooth intro, I only have to fade away the previous sound, while the new one has already started playing. However, theoretically I could just use the negative value (1-volume) of the out-fading sound for the in-fading sound, case I need to add that. Whether it is worth polishing, extracting, documenting and releasing, IDK, as only few users seem interested in the webgl target at all. What a pity, as in my view, with these options I can take CC a lot more serious, in respect to webgl. Anyway, people can always contact me when interested. |
|