gpt4 book ai didi

c++ - BASS "Play"流

转载 作者:太空狗 更新时间:2023-10-29 21:50:02 25 4
gpt4 key购买 nike

开发者 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();

关于c++ - BASS "Play"流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7180920/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com