friend 们,您好!
我有一个问题,我正在做射击游戏,但是我不确定爆炸发生时如何实现,因为爆炸总是发出相同的声音,并且可能会在很短的时间内发生,即声音甚至没有结束并发生另一场爆炸。我的问题是,如何在同一视频流中多次“播放”?
谢谢!
最佳答案
这是一个非常简单的示例:
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();