Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Playing and Controling Multiple Songs  (Read 10678 times)

0 Members and 1 Guest are viewing this topic.

Servant

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 1
    • View Profile
Playing and Controling Multiple Songs
« on: May 28, 2003, 08:23:38 PM »

I am looking at the WME 1.0.1 (b) documentation on Scripting in WME, Scripting language reference, Game object.

Under the Music functions I find functions like:
PlayMusic, StopMusic, PauseMusic, ResumeMusic, SetMusicPosition, GetMusicPosition.

Q1) The documentation for these functions leads me to believe that only one music file can be played at a time. Is this true?

Q2) If I am wrong, how can multiple songs be played at one time?

Q3) Additionally, how can I control each song's volume individually as it is playing?
Logged
Servant

Brassfire

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 69
    • View Profile
    • The Unknown Hero
Re:Playing and Controling Multiple Songs
« Reply #1 on: May 28, 2003, 08:34:29 PM »

Is there a possibility for crossfading between songs?

Is there an ability to pan the sounds across the scene, like if a bird had a sound effect attached, and the bird flew across the sky, would you be able to program the chirp to where the bird was in the scene?

Of if you had a river at one corner of the screen, could you position the music of the river to sound like it was coming from that area, even when the scene scrolls?

The sound effects are a separate thing than the music, correct?

~Questions from the non-programmer ;)
Logged

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 690
    • View Profile
Re:Playing and Controling Multiple Songs
« Reply #2 on: May 29, 2003, 12:09:46 AM »

I just wanted to give you some examples for the function - until I discovered that I tested them in some other engine, not in WME!  :o

Unfortunately it seems to me as if all these things are not possible yet, unless there are some hidden undocumented features?!

Under the Music functions I find functions like:
PlayMusic, StopMusic, PauseMusic, ResumeMusic, SetMusicPosition, GetMusicPosition.

Right, and actually I don't understand the difference between PlaySound() and PlayMusic() anymore... ?! Did I ever or am I just too tired ?

Anyway - it would be useful to have handles for these functions instead of just boolean return codes. And to add these handles to the parameter lists of all music functions.
And to add "SetMusicVolume()" as a function.

Uhm - I'm thinking about something like that:

Code: [Select]
var britney_music = Game.PlayMusic("music\britney.ogg", true);
var garbage_music = Game.PlayMusic("music\garbage.ogg", true);

actor.Talk("WHOAAH - two radios are too much!");
actor.Talk("I'll make Britney shutting up and pump up Garbage's volume!");

Game.StopMusic(britney_music);
Game.SetMusicVolume(garbage_music, 255);

(I hope to convince the reader by using selected band names... ;) !)

Is there a possibility for crossfading between songs?

Crossfading would be very easy this way... hmmm... Mnemonic ?

Is there an ability to pan the sounds across the scene, like if a bird had a sound effect attached, and the bird flew across the sky, would you be able to program the chirp to where the bird was in the scene?

I guess that's not possible yet, it would require something like a SetMusicPan() function. I'm not sure if this is useful, but I like the next one:

Of if you had a river at one corner of the screen, could you position the music of the river to sound like it was coming from that area, even when the scene scrolls?

Great idea... attaching a music/sound to some object and giving it a percentage value, how strong it should be panned depending to its position in the viewport.

Hehe. I guess this thread became a big wishlist topic now...  ;D

Good night, it took me 8 (EIGHT!) modifications after saving and HOURS to complete this message... (that's because of odnorf who is blaming me via MSN currently!  ;)
« Last Edit: May 29, 2003, 12:35:22 AM by Jerrot »
Logged
Mooh!

odnorf

  • w00t?
  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 7
  • Offline Offline
  • Gender: Male
  • Posts: 1456
  • Lamp dog!
    • View Profile
Re:Playing and Controling Multiple Songs
« Reply #3 on: May 29, 2003, 12:50:23 AM »

Those are very good suggestions. More and better music/sound/speech fuctions are surely needed. Especially the crossfading thing would be great. Count one more vote Jan.

OFF-TOPIC:
Good night, it took me 8 (EIGHT!) modifications after saving and HOURS to complete this message... (that's because of odnorf who is blaming me via MSN currently!  ;)

Hey! :) I am the one that gave you the idea to post something like that but I wasn't really expecting you to do it :) And I am not responsible for those 8 modifications. *You* were tired and you were making new mistakes in every edit.
Logged
fl*p

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:Playing and Controling Multiple Songs
« Reply #4 on: May 30, 2003, 07:04:38 PM »

OK, first of all I'd like to apologize I didn't reply earlier. I was away the past three days.

Q1) The documentation for these functions leads me to believe that only one music file can be played at a time. Is this true?
That's true.

Q2) If I am wrong, how can multiple songs be played at one time?
Technically, there's no difference between music and a sound, the only difference is you can set different global volume for music and for all the sounds. OK, there's always only one music channel, but you can as well use the "sound entities" to simulate multiple music channels. You can control them individually (position, volume, pause etc.). Sound entities can be created in SceneEdit, just like the other entities (select the "Free entities" node and then click the "Add entity" button and selecs "Souund entity". Those entities provide the PlaySound, PauseSound, SetSoundPosition, SetSoundVolume ... methods mentioned above.

Q3) Additionally, how can I control each song's volume individually as it is playing?
I already anwered this one; I you go with the sound entities approach, just call the SetSoundVolume() method on your sound entities.



Is there a possibility for crossfading between songs?
Again, with the use of multiple sound entities and with a bit of scripting, you could do the crossfading between songs by setting their volume appropriately.


Is there an ability to pan the sounds across the scene, like if a bird had a sound effect attached, and the bird flew across the sky, would you be able to program the chirp to where the bird was in the scene?
All the sounds made by entities/actors are automatically panned according to the object's position on screen (it's possible to disable the panning when needed). Although it's been reported to me that the default panning is not always sufficient and that it would be better to be able to define exactly how much the sound should be panned. So, I'll add some property for setting that.

The sound effects are a separate thing than the music, correct?
Not necessarily, see above.


I guess that's not possible yet, it would require something like a SetMusicPan() function.
Yeah, that's what I was talking about ;)


Anyway, although this way I described is (IMHO) pretty flexible, it probably isn't exactly easy. Would you prefer a build-in multiple music channels/crossfading? I think two channels would be enough, right?


EDIT: A very raw scripting reference for entities: http://dead-code.org/misc/scripting_ref_entity.html
EDIT2: Oops, the colors were not meant to be that way, wrong css file...
« Last Edit: May 30, 2003, 07:10:54 PM by Mnemonic »
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

odnorf

  • w00t?
  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 7
  • Offline Offline
  • Gender: Male
  • Posts: 1456
  • Lamp dog!
    • View Profile
Re:Playing and Controling Multiple Songs
« Reply #5 on: May 30, 2003, 07:12:22 PM »

Quote
Anyway, although this way I described is (IMHO) pretty flexible, it probably isn't exactly easy. Would you prefer a build-in multiple music channels/crossfading? I think two channels would be enough, right?

YES! Althought I really liked the method Jerrot suggests. It's flexible and easy.
Logged
fl*p

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 690
    • View Profile
Re:Playing and Controling Multiple Songs
« Reply #6 on: June 04, 2003, 03:35:34 PM »

hi mnemonic!

Technically, there's no difference between music and a sound, the only difference is you can set different global volume for music and for all the sounds. OK, there's always only one music channel, but you can as well use the "sound entities" to

Oh... I'm sorry, I just didn't know them yet. I understand how to script these examples by using this method, I'll try to create a sample script for these purposes.
So the real "Music" functions would be obsolete for this purpose, but I'm not sure what happens when changing the scene, the sound entity would stop, wouldn't it ?! But I'd like the music to fade/crossover when changing the scene... hmmm...

Quote
Although it's been reported to me that the default panning is not always sufficient and that it would be better to be able to define exactly how much the sound should be panned. So, I'll add some property for setting that.

yes... because the engine CAN'T know the current perspective or the room material. ;)

Quote
The sound effects are a separate thing than the music, correct?
Not necessarily, see above.

If I'm right with my thought about changing the scene, seperate music functions (that don't care about different scenes) would be useful.

Quote
Anyway, although this way I described is (IMHO) pretty flexible, it probably isn't exactly easy. Would you prefer a build-in multiple music channels/crossfading? I think two channels would be enough, right?

I'll first have to play around with the existing functions now to continue this thread and to answer your question... :)
Logged
Mooh!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:Playing and Controling Multiple Songs
« Reply #7 on: June 04, 2003, 03:54:30 PM »

but I'm not sure what happens when changing the scene, the sound entity would stop, wouldn't it ?! But I'd like the music to fade/crossover when changing the scene... hmmm...

Good point, damn! ::)
Well, you'd have to use external entities (Game.LoadEntity), not the ones created in SceneEdit.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 690
    • View Profile
Re:Playing and Controling Multiple Songs
« Reply #8 on: June 05, 2003, 03:03:45 AM »

Well, you'd have to use external entities (Game.LoadEntity), not the ones created in SceneEdit.

Ok, ok... you won! :)
I played around with it - well, it looks weird but it really works!  ;D

BTW: How about a section for "scriptlets & plugins" ?

Now, maybe there is a better way, but for a first release it already works. Don't mind to comment anyway to improve this !

I used 2 music files and my goal was a fading crossover when jumping to the next scene.

First I had to create two simple empty entities for my music files. I guess not everything here is needed and I'm not even sure, if I couldn't use one file for both entities. However - I chose the position to center the entity on a 800x600 game screen (thinking about panning...).

music\mus1.entity :

Code: [Select]
ENTITY {
  NAME="mus1"
  SUBTYPE="SOUND"
  CAPTION=""
  ACTIVE=TRUE
  X=400
  Y=300
  SCALABLE=FALSE
  INTERACTIVE=FALSE
  COLORABLE=FALSE
}

music\mus2.entity :

Code: [Select]
ENTITY {
  NAME="mus2"
  SUBTYPE="SOUND"
  CAPTION=""
  ACTIVE=TRUE
  X=400
  Y=300
  SCALABLE=FALSE
  INTERACTIVE=FALSE
  COLORABLE=FALSE
}

Notice that I didn't load any soundfile yet.

In the Game.script I added two lines before changing to the scene to load the entities:

Code: [Select]
global music1 = Game.LoadEntity("music\mus1.entity");
global music2 = Game.LoadEntity("music\mus2.entity");

Ok. Now we jump into our scene. I wanted this scene to play "music\mus2.ogg" when entering.

I added these lines to the scene_init.script:

Code: [Select]
// remember our global entities and initialize some counter var

global music1;
global music2;
var counter;

// when entering a scene, we don't know, which entity is playing the
// music currently. so we have to check this here

if (music1.IsSoundPlaying())
{

  // music1 was playing. now we set the volume of music2 to 0 (mute)
  // and load the new music.

  music2.SetSoundVolume(0);
  music2.PlaySound("music\mus2.ogg");

  // this is a very simple crossover. counting to 100, the volume of music1
  // is decreased to zero, while the volume of music2 is increased to 100.

  for(counter=1; counter<=100; counter=counter+1)
  {
    music1.SetSoundVolume(100-counter);
    music2.SetSoundVolume(counter);
    Sleep(50);
  }

  // that's it. music1 is mute, so we can stop it now.

  music1.StopSound();
}
else if (music2.IsSoundPlaying())
{

  // we have to do the same again for the case, that music2 was playing.
  // it's the same as above, I just switched music1 and music2.
  // (I guess this could be done easier!)

  music1.SetSoundVolume(0);
  music1.PlaySound("music\mus2.ogg");
  for(counter=1; counter<=100; counter=counter+1)
  {
    music2.SetSoundVolume(100-counter);
    music1.SetSoundVolume(counter);
    Sleep(50);
  }
  music2.StopSound();
}
else
{

  // in case no music was playing (e.g. when starting the game) we just have
  // to load the sound file into one of our sound entities. I decided for music1 ;)

  music1.SetSoundVolume(100);
  music1.PlaySound("music\mus2.ogg");
}

Tadaaa!  :D
Logged
Mooh!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:Playing and Controling Multiple Songs
« Reply #9 on: June 05, 2003, 07:16:13 AM »

Yeah, excellent! That's exactly what I had on my mind 8) I'll test it in the evening, I think we could even eliminate those two entity files.

EDIT: btw do you *ever* sleep???
« Last Edit: June 05, 2003, 07:58:21 AM by Mnemonic »
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 690
    • View Profile
Re:Playing and Controling Multiple Songs
« Reply #10 on: June 05, 2003, 09:18:49 AM »

Yeah, excellent! That's exactly what I had on my mind 8) I'll test it in the evening, I think we could even eliminate those two entity files.

Great! And you're right, I already tested it with only one entity file (just changed both "LoadEntity()" calls to the same file) - it works the same.

It would make sense to hold the volumes for both "channels" in a variable, so something similiar to "SetMusicVolume()" would be possible.

I'll wait until you tested it - maybe you find some more improvements before I post the final scripts into the new (THANKS!  ;D) snippets board.

EDIT: btw do you *ever* sleep???

Sleep ? What a waste of time... nah, sure! My work starts at about(!) 9:30-10am and I need 2 minutes from my bed to my computer. Fetching a cup of coffee or tea from the kitchen included. And yesterday I had to work until 5am, so some WME scripting in a break was very relaxing. Next time I'll publish my verb bar code. ;)
Logged
Mooh!

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 690
    • View Profile
Re:Playing and Controling Multiple Songs
« Reply #11 on: June 05, 2003, 09:56:59 AM »

Me again!

I just discovered, that the positioning of these free sound entities does not affect the panning - I used the two entity files as I posted them above, but changed their X positions to 0 and 799.

But - it sounds as if both are just centered ? I even tried it with mono files for the same result.
Logged
Mooh!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:Playing and Controling Multiple Songs
« Reply #12 on: June 05, 2003, 09:14:55 PM »

But - it sounds as if both are just centered ? I even tried it with mono files for the same result.

It's a stupid stupid bug :-[ The sound panning doesn't work for the "sound" entities (duh!). Just remove the SUBTYPE="SOUND" line from the entity definition and the sound panning should start working. I'm gonna fix that ASAP.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 690
    • View Profile
Re:Playing and Controling Multiple Songs
« Reply #13 on: June 06, 2003, 12:03:11 AM »

It's a stupid stupid bug :-[ The sound panning doesn't work for the "sound" entities (duh!). Just remove the SUBTYPE="SOUND" line from the entity definition and the sound panning should start working. I'm gonna fix that ASAP.

That's a good one!  ;)
Yeah, indeed - it works without the SUBTYPE line. I finally discovered the attribute "SoundPanning" in the docs, but obviously it's already set to "true" by default. Should be inserted into the docs. :)
Logged
Mooh!
 

Page created in 0.062 seconds with 24 queries.