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();