Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
ccbSetSceneNodeProperty of Sound node?

Dieter
Guest
Quote
2023-08-26 10:06:42

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)


okeoke
Registered User
Quote
2023-08-26 11:30:54

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") {
a.f.c = f;
a.f.b = g;
a.f.d = h;
} else if (b == "Rotation") {
a.V.c = f;
a.V.b = g;
a.V.d = h;
} else if (b == "Scale") {
a.sa.c = f;
a.sa.b = g;
a.sa.d = h;
} else if (b == "Target") d != null && pc(d, new s(f, g, h));
else if (b == "UpVector") {
if (d != null) d.zb = new s(f, g, h);
} else if (b == "FieldOfView_Degrees") d != null && vf(d, n.Vo(c));
else if (b == "AspectRatio") d != null && cf(d, c);
else if (b == "Animation") e != null && gc(e, c, e.ec);
else if (b == "Looping") e != null && Zf(e, c);
else if (b == "FramesPerSecond") e != null && Yf(e, c * 0.001);
else if (b == "AnimationBlending") {
if (e != null) e.se = c;
} else if (b == "BlendTimeMs") {
if (e != null) e.nd = c;
} else if (b == "Radius") {
if (m != null) m.Ra.Ka = c;
} else if (b == "Color") {
if (m != null) m.Ra.na = n.Uo(j);
} else if (b == "Direction") {
if (m != null) {
m.Ra.Na = new s(f, g, h);
m.Ra.Na.normalize();
}
} else if (b == "FogColor") n.$.qa.ac = j;
else if (b == "Realtime Shadows" && a === Nh()) n.$.qa.wi = c == true;
else if (b == "BackgroundColor" && a === Nh()) n.$.qa.eg = j;
else if (b == "AmbientLight") n.$.qa.Xb = n.Uo(j);
else if (b == "Bloom") n.$.qa.Pc[Dg].Gc = c == true;
else if (b == "Black and White") n.$.qa.Pc[Sg].Gc = c == true;
else if (b == "Invert") n.$.qa.Pc[Qg].Gc = c == true;
else if (b == "Blur") n.$.qa.Pc[Og].Gc = c == true;
else if (b == "Colorize") n.$.qa.Pc[Rg].Gc = c == true;
else if (b == "Vignette") n.$.qa.Pc[Tg].Gc = c == true;
else if (b == "Bloom_BlurIterations") n.$.qa.$l = c >> 0;
else if (b == "Bloom_Treshold") n.$.qa.am = c;
else if (b == "Blur_Iterations") n.$.qa.bm = c >> 0;
else if (b == "Colorize_Color") n.$.qa.bi = c;
else if (b == "Vignette_Intensity") n.$.qa.cm = c >> 0;
else if (b == "Vignette_RadiusA") n.$.qa.dm = c >> 0;
else if (b == "Vignette_RadiusB") n.$.qa.em = c >> 0;
else if (b == "Name") a.n = c;

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;



okeoke
Registered User
Quote
2023-08-26 11:37:56

Also you will not be able to get a good crossfade effect by changing volume linearly, you need to adjust volumes logarithmically.


okeoke
Registered User
Quote
2023-08-26 11:50:01

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);
// Use an equal-power crossfading curve:
var gain1 = Math.cos(x * 0.5*Math.PI);
var gain2 = Math.cos((1.0 - x) * 0.5*Math.PI);
this.ctl1.gainNode.gain.value = gain1;
this.ctl2.gainNode.gain.value = gain2;



Dieter
Guest
Quote
2023-08-26 14:21:19

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.


Dieter
Guest
Quote
2023-08-26 15:26:42

Well, I tried
ccbGetSceneNodeFromName('music').Yg = 0.5;
It does nothing. Did it work for you?


Dieter
Guest
Quote
2023-08-26 15:30:57

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...


okeoke
Registered User
Quote
2023-08-26 16:33:03

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.


okeoke
Registered User
Quote
2023-08-26 16:38:09

Ok, I've read the previous post - nice you've sorted that out.


Dieter
Guest
Quote
2023-08-26 16:54:55

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 ^^


Dieter
Guest
Quote
2023-08-27 00:52:23

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.


Dieter
Guest
Quote
2023-08-27 16:05:09

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.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inter?ational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact