MusHandleSetVolume()

Syntax

int MusHandleSetVolume(musHandle handle, int volume);

Arguments

handle
the sound handle
volume
the volume scale

Description

It sets the volume scale value for the channels associated with the specified sound handle. This function allows the programmer to change the volume of songs and sound effects relevant to the values originally defined within the sound data.

The handle must be a sound handle returned by MusStartSong(), MusStartSongFromMarker(), MusStartEffect(), or MusStartEffect2(). If a handle of zero is supplied, this function will always return zero.

The volume value should be within the range of 0 to 0x100 (256), with this range representing 0% to 200% of the value defined in the original sound data. The default volume scale value for all channels is 0x80 (100%).

Return Value

Number of channels which have been changed.

Example

unsigned long SongCrossFade(unsigned long handle, int *song)
{
  int i;
  unsigned long new_handle;

  new_handle = MusStartSong(song);
  MusHandleSetVolume(song, 0);
  for (i=0x10; i<0x80; i+=0x10)
  {
    WaitForVsync();
    MusHandleSetVolume(handle, 0x80-i);
    MusHandleSetVolume(new_handle, i);
  }
  MusHandleStop(handle,0);
  return (new_handle);
}

void VolFromDistance(unsigned long handle, float distance)
{
  int scale;
  int volume;

  /* calculate distance scale */
  if (distance>=MAX_DISTANCE)
    return (0); /* sound is too far away! */
  distance = (MAX_DISTANCE-distance)*(65536.0/MAX_DISTANCE);
  scale = (int)distance;

  /* calculate volume level */
  volume = (0x80*scale)>>16;

  MusHandleSetVolume(handle, volume);
}

See Also

MusHandleSetPan(), MusStartSong(), MusStartEffect(), MusStartEffect2()