Directional and fading sound files.

Started by Alynn, Mon 27/10/2003 23:46:07

Previous topic - Next topic

Alynn

Ok... I looked... and looked... and LOOOKED... and cant find it...

Is there any way to have fading and maybe even directional sounds in your views...

I have a character chopping wood in a forest... I would like the sound when he hits the tree to get louder as you get closer to him, and quiet as you move away. The current forest room is 700 pixels wide, so it is a scrolling room...

anyway... is it possible?

CB..

#1
check the

PlayAmbientSound

information in the help files

here yu go this is what it says


PlayAmbientSound
PlayAmbientSound (int channel, int sound, int volume, int x, int y)

Plays a looping sound effect in the background.
CHANNEL is the sound channel number. Currently this must always be 1, but in future multiple ambient sounds at once may be supported in which case you would be able to specify a different channel.

SOUND is the sound number, which identifies the file to load. The game will try to load SOUNDx.MP3 and SOUNDx.WAV, where X is the sound number you specify here.

VOLUME is the volume of the sound. This can be from 1 to 255, where 255 is the loudest. Generally you won't want to make this very loud since it's only supposed to be a background noise, such as a humming machine room or flowing water.

X and Y allow you to specify co-ordinates if you want a directional ambient sound. If you just pass X and Y as zero, the sound will be played at the specified volume throughout the room. However, if there is a certain spot in the room where the sound is emanating from, you can pass its co-ordinates here, and the sound will get louder as the player approaches that spot in the room. In this case, the VOLUME parameter specifies the maximum possible volume, when the player is standing right on the spot.

NOTE: The sound will stop when the player leaves the room.

NOTE: In order to optimise the looping of the sound, the entire sound effect is loaded into memory. Therefore, do not use this function to play normal background music with, since music files tend to be very large and are better streamed from disk with the normal music functions.

Example:

PlayAmbientSound (1, 10, 150, 250, 110);

starts SOUND10.MP3 playing in the background, at a medium volume and coming from co-ordinates (250, 110).

Alynn

Bah...

Maybe sounds eminating from characters should have ambient sounds built in... I'm going to have to extend this wave to get the timing down correct and take it off the char...

Thanks...

CB..


Alynn

Quote from: CB.. on Tue 28/10/2003 11:35:23
yur a sheep?

No... that would be baaaaaaaaaaaa

this was bah! Most famous for being in front of humbug...

Alynn

This is just a snippit

Code: ags
if ((character[1].frame==4) & (character[1].loop==4)) {
    if (isBetween(600, 700, wherex)){
      if (IsSoundPlaying()==0){
        SetChannelVolume(3, 205);
        StrFormat(buffer, "%d", 205);
        SetLabelText(4, 1, buffer);
        PlaySoundEx(1, 3);
      }
    }
    else if (isBetween(550, 600, wherex)){
      if (IsSoundPlaying()==0){
        SetChannelVolume(3, 230);
        StrFormat(buffer, "%d", 230);
        SetLabelText(4, 1, buffer);
        PlaySoundEx(1, 3);
      }
    }
    else if (isBetween(450, 550, wherex)){
      if (IsSoundPlaying()==0){
        SetChannelVolume(3, 255);
        StrFormat(buffer, "%d", 255);
        SetLabelText(4, 1, buffer);
        PlaySoundEx(1, 3);
      }
    }
    else if (isBetween(400, 450, wherex)){
      if (IsSoundPlaying()==0){
        SetChannelVolume(3, 230);
        StrFormat(buffer, "%d", 230);
        SetLabelText(4, 1, buffer);
        PlaySoundEx(1, 3);
      }
    }
    else if (isBetween(350, 400, wherex)){
      if (IsSoundPlaying()==0){
        SetChannelVolume(3, 205);
        StrFormat(buffer, "%d", 205);
        SetLabelText(4, 1, buffer);
        PlaySoundEx(1, 3);
      }
    }
  }


Ok first dont worry about the StrFormat and the SetLabel... thats just for debugging... wherex is initialized as character[0].x.... this sits in my repeatedly execute....

Basicly... it doesnt work... the volume isnt turning down or up... just staying at 255 (at least to my ears...) but the gui i have for debugging is changing just fine...

any thoughts?

Gilbert

#6
You're making a 800x600 game right? Then the valid x coordinates is from 0 to 399, NOT 0 to 799.

Oooops wasn't reading your post thoroughly.

Maybe the volume are set to too close in value, so can't spot a difference, try setting one of them to be much lower and see if there're difference.

Alynn

#7
lowest volume is 30 at x co-ordnants 0-50... at x co-ord 500 its 255... you should be able to tell a difference.... but there isnt one (at 30 you should barely be able to hear it I think...




NM I found it... it looks like SetChannelVolume has to be called after the PlaySoundEx...

Gilbert

Strange, hopefully that's not a bug. Will there be possible a SetChannelVolume() outside of that function?

If the problem persists, I'll try to raise it in the tech. forum.

BTW, what's the problem with PlayAmbientSound() ? You really don't need to use so many checking and PlaySoundEx().

One thing I'll see is that you may not need to enclose every stuff in the if (IsSoundPlaying()==0){} thingie (unless that's indended to), as you can also change the channel volume while the sound is still playing (though you may not want to start playing a new sound before one had ended).

Alynn

The sound is so short (sound of an axe hitting wood) that it plays twice during that single frame of animation, making it sound horrible so I had to add the IsSoundPlaying check so it would only fire once during that frame of animation...

The reason playambient wont work for me is ambient sound automaticly loops the sound, when I only want it to play when the axe hits the tree, and trying to edit that sound by putting silence in the right places was getting tedius (I spent 3 hours trying to get the timing down and I could never get it perfect) So this is pretty much the only solution I have at this point. At least to get the effect that I am searching for.

SMF spam blocked by CleanTalk