creating iMuse effect in AGS?

Started by He-Man, Tue 25/10/2005 15:13:52

Previous topic - Next topic

khnum

Quote from: Nikolas on Mon 31/10/2005 12:46:29
You could keep this track in MP3 format and have another "empty" track in WAv form. The second WAV form could be only one bar. This way you wouldn't need to track the MP3 or make it into WAV, thus wasting space and quality

Since we don't need to fade it, couldn't the empty track be a midi, so we wouldn't (at least i hope) slow the engine? Using a wav could work, but if we're also using fx, it could be a problem.

Dave Gilbert

Vel and I tried to do this very thing with the freeware version of Shivah.  During the final fight scene, Vel had this neat idea to add extra layers to a music track as the hero got closer to victory, and to remove them as he got further away.  Unfortunately, I could never get it to work.  The tracks would never synch up properly, and even cross fading sounded weird and wrong.  So we scrapped the whole idea.  A shame, really, since Vel put all that work in.

Janik

So has anyone had success doing this? modgeulator seemed to get pretty close, but I haven't heard of any progress...
Play pen and paper D&D? Then try DM Genie - software for Dungeons and Dragons!

khnum

Maybe I didi it! Just need to improve the script...
I'll post it as soon as I finish  ;)

khnum

#44
Ok, i definitively did it!
To override the break we all heard, i fade out music1, then fade in music2 strating where music1 was. (it works with oggs, mp3, and wave; i haven't tested it on midis but it should work if you use getmidiposition instead of getmp3posmillis)

Here is the code:
Code: ags

first of all put this at the beginning of the script:


int fade_switch=0, timer=0, music, mp3pos,vol;

then import the same variables into the haeder.



put this into repeatedly_execute:

if (fade_switch==1) {
  timer++;
  if (timer<=100) {
    SetMusicMasterVolume(100-timer);}
  if (timer>100){
    if (timer<=150){
      SetDigitalMasterVolume(100-(timer-100));
      mp3pos=GetMP3PosMillis();}
    if (timer==151) {
      SetMusicVolume(-2);
      PlayMusic(music);
      SeekMP3PosMillis(mp3pos);}
    if (timer>151){
      if (timer<=200){
	SetDigitalMasterVolume(50+(timer-150));}
      if (timer>200){
	if (timer<=300){		          
	  SetMusicMasterVolume(0+(timer-200));}
	if (timer==310) {
	  SetMusicVolume(-1);}
	if (timer==320) {
	  SetMusicVolume(0);}
        if (timer>320) {
          fade_switch=0;
	  timer=0;}




Ok, this is the code; now let's check the variables:

"fade_switch" is the switch that make the music change;

"music" is the music number;


to make the music change (in a room, an interaction, or wherever you want) turn the switch on (fade_switch=1), and set "music" to the number of the incoming song (i.e. music=2 for music2.ogg)

Of course you can change fade velocity, just make some calculation :)

If you're gonna use the code I'd appreciate to be in your credits, but you don't have to :P

Edit by strazer (Please use the Modify button instead of double-posting.):

I forgot: the only problem is you can't let the player set the music volume, because the script wouldn't work :( ; anyway it's easy to solve it, i'll do it (not today :P).

oh, another thing: the lawith nst part of the script works with a room with "normal" as music volume; of cours you can easily fix the script to fit any sound level  ;)

Pumaman

Thanks for sharing your solution :)

Janik

Well that looks great! Would you mind posting a demo game of it?
Play pen and paper D&D? Then try DM Genie - software for Dungeons and Dragons!

InCreator

I see better solution in a massive plugin.
What it should do, is play multiple tracks at the same time. Like, in separate channels.
But start playing both at very same moment.
Channels with adjustable volume (a crossfader between)
One track could play muted or quiet, when needed, main track quiets down and additional increases in volume... simple?

Janik

#48
You would have to takeover functionality (with a DirectSound interface) to do it in a plugin.
I tried once really quickly, but failed; I have done next to no directX programming so I had a tough time starting.

I tried using the plugin API function AGS_EngineAudioHook, but it has been disabled according to CJ.

Edit: From the API
QuoteLPDIRECTSOUND GetDirectSound();

    Returns the main IDirectSound interface that the engine is using. This command does not AddRef the pointer it returns, so you don't need to Release it.

    This function returns NULL if sound is disabled, or if the player is using the WaveOut driver rather than the DirectSound one.

    Added in version: 14

void DisableSound();

    Disables AGS's sound system completely. Use this if you want your plugin to take over all audio functionality.

    Added in version: 14

I'm not sure if you need to DisableSound in order to use the DirectSound interface...
Play pen and paper D&D? Then try DM Genie - software for Dungeons and Dragons!

monkey0506

I hope khnum doesn't mind too much, but I've taken the liberty of modularizing his code here. He's mentioned in the module description and in the wiki entry...perhaps not in the documentation itself though...

khnum

No problem, happy to see my code's been useful  :=

SMF spam blocked by CleanTalk