3

Hello friends developers,

I have a question, I am doing a shooting game, but I'm not sure how to implement when an explosion happens, because the explosion is always the same sound over and can occur in a short time, ie, the sound is not even ending and another explosion happens. My question is, how to "play" more than once in the same stream?

Thanks!

Yargon
  • 101
  • 1
  • 2
  • 4

2 Answers2

2

Here's a very simple example:

int device = -1; // Default Sounddevice
int freq = 44100; // Sample rate (Hz)
HSTREAM streamHandle; // Handle for open stream


/* Initialize output device */
BASS_Init(device, freq, 0, 0, NULL);


/* Load your soundfile and play it */
streamHandle = BASS_StreamCreateFile(FALSE, "your_file.mp3", 0, 0, 0);
BASS_ChannelPlay(streamHandle, FALSE);


/* As very last, close Bass */
BASS_Free();

While this example plays your soundfile only once, you can create a new handle each time you need the sound. But BASS_Init() and BASS_Free() have to run only once.

Another solution is to play the sound as a sample:

HSAMPLE streamHandle; // Handle for sample
HCHANNEL channel; // Handle for open channel of the sample


/* Initialize output device */
BASS_Init(device, freq, 0, 0, NULL);


/* Load sample and play it */
streamHandle = BASS_SampleLoad(FALSE, "your_file.mp3", 0, 0, 0);
channel = BASS_SampleGetChannel(streamHandle, FALSE);


/* Once you are done with your sample you should free it */
BASS_SampleFree(streamHandle);

/* As very last, close Bass */
BASS_Free();
ollo
  • 23,119
  • 13
  • 93
  • 146
0

Assuming we're talking about the same Bass Audio API, then navigate to the online documention for BASS\Channels\Bass_ChannelPlay(). Call Bass_ChannelPlay() passing your existing handle for the explosion and setting restart to true - see the documentation for more information.

Keldon Alleyne
  • 2,053
  • 15
  • 23