BASS“播放”一个流

时间:2011-08-24 19:08:01

标签: c++ audio stream bass

你好朋友开发者,

我有一个问题,我正在做一个射击游戏,但我不确定当爆炸发生时如何实施,因为爆炸总是相同的声音并且可以在短时间内发生,即声音甚至没有结束,另一次爆炸发生。我的问题是,如何在同一个流中不止一次“玩”?

谢谢!

2 个答案:

答案 0 :(得分:2)

这是一个非常简单的例子:

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

虽然此示例仅播放您的声音文件一次,但您可以在每次需要声音时创建新的句柄。 但BASS_Init()BASS_Free()只能运行一次。

另一种解决方案是将声音作为样本播放:

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

答案 1 :(得分:0)

假设我们正在谈论相同的Bass Audio API,请导航到BASS\Channels\Bass_ChannelPlay()的在线文档。致电Bass_ChannelPlay()通过您现有的爆炸手柄并将restart设置为true - 有关详细信息,请参阅文档。