Rendering some sound data into one new sound data?

僤鯓⒐⒋嵵緔 提交于 2019-12-12 02:38:07

问题


I'm creating an application that will read a unique format that contains sound "bank" and offsets when the sound must be played.

Imagine something like..

Sound bank: (ID on the left-hand and file name on the right-hand side)

0 kick.wav
1 hit.wav
2 flute.wav

And the offsets: (Time in ms on the left-hand and sound ID on the right-hand side)

1000 0
2000 1
3000 2

And the application will generate a new sound file (ie. wav, for later conversion to other formats) that plays a kick at first sec, a hit at second sec, and flute at third sec.

I completely have no idea on where to begin.

I usually use FMOD for audio playbacks, but never did something like this before.

I'm using C++ and wxWidgets on a MSVC++ Express Edition environment, and LGPL libraries would be fine.


回答1:


If I understand correctly, you want to generate a new wave file by mixing wavs from a soundbank. You may not need a sound API at all for this, especially if all your input wavs are in the same format.

Simply load each wav file into a buffer. For SampleRate*secondsUntilStartTime samples, for each buffer in the ActiveList, add buffer[bufferIdx++] into the output buffer. If bufferIdx == bufferLen, remove this buffer from the ActiveList. At StartTime, add the next buffer the ActiveList, and repeat.

If FMOD supports output to a file instead of the sound hardware, you can do this same thing with the streaming API. Just keep track of elapsed samples in the StreamCallback, and start mixing in new files whenever you reach their start offsets.



来源:https://stackoverflow.com/questions/5938972/rendering-some-sound-data-into-one-new-sound-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!