问题描述
我使用一个数组来处理无线电信号,并获得原始的PCM音频。我拼命尝试使用FMOD前播放音频。
I use an array to process radio signal and to obtain raw PCM audio. I am desperately trying to play this audio using Fmod Ex.
基本上,才有可能创造相当于我的循环缓冲器的流,我可以在一个线程安全的方式访问?什么方法使用将大大AP preciated的基本信息。
Basically, would it be possible to create a stream corresponding to my circular buffer, that I could access in a thread-safe way ? Any basic information about what methods to use would be greatly appreciated.
如果没有,可以在任何其他Windows 7 API做的伎俩又如何? (ASIO,WASAPI ...)
If no, could any other Windows 7 API do the trick and how ? (ASIO, Wasapi...)
THX° - °
推荐答案
我假设你的数据是连续的(时刻更新),所以你会想要将它流转换FMOD,要做到这一点,你可以覆盖一个文件回调特定的声音。没有与FMOD API usercreatedsound例如这样做的一个很好的例子。如果你只是想打一个静态缓冲区只需填写一个createsoundexinfo结构描述数据,使用FMOD_OPENMEMORY标志,并通过createSound传递一个指针数据name_or_data。下面是更复杂的流情况的示例:
I'm assuming your data is continuous (always updating) so you would want to stream it into FMOD, to do this you could override the file callbacks for a particular sound. There is a good example of doing this with the FMOD API usercreatedsound example. If you just want to play a static buffer simply fill out a createsoundexinfo struct describing the data, use the FMOD_OPENMEMORY flag and pass a pointer to the data through createSound as name_or_data. Below is an example of the more complex stream case:
在创建你可以使用FMOD_CREATESOUNDEXINFO来指定数据的细节声音,那么其传递给createStream。注意,这基本上是你会怎么做静态样本的情况下,除非你正在使用FMOD_OPENUSER,创下德code尺寸并指定回调读取数据,而不是FMOD_OPENMEMORY并通过name_or_data参数传递数据:
When creating the sound you would use FMOD_CREATESOUNDEXINFO to specify the details of your data, then pass that to createStream. Note this is basically how you would do the static sample case except you are using FMOD_OPENUSER, setting decode size and specifying the callbacks to read the data instead of FMOD_OPENMEMORY and passing the data via the name_or_data param:
FMOD_CREATESOUNDEXINFO exinfo;
memset(&createsoundexinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); /* required. */
exinfo.decodebuffersize = 44100; /* Chunk size of stream update in samples. This will be the amount of data passed to the user callback. */
exinfo.length = 44100 * channels * sizeof(signed short) * 5; /* Length of PCM data in bytes of whole song (for Sound::getLength) */
exinfo.numchannels = channels; /* Number of channels in the sound. */
exinfo.defaultfrequency = 44100; /* Default playback rate of sound. */
exinfo.format = FMOD_SOUND_FORMAT_PCM16; /* Data format of sound. */
exinfo.pcmreadcallback = pcmreadcallback; /* User callback for reading. */
exinfo.pcmsetposcallback = pcmsetposcallback; /* User callback for seeking. */
result = system->createStream(NULL, FMOD_OPENUSER, &exinfo, &sound);
ERRCHECK(result);
在这里,你说你会提供PCM16 44kHz的数据,按要求定制,并给出了两个函数回调读取和SETPOSITION这FMOD会打电话问你要么寻求您的缓冲区或读取它的东西:
Here you are saying that you will provide PCM16 44khz data, customize as required, and give two function callbacks for read and setposition which FMOD will call asking you to either seek your buffer or read something from it:
FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, void *data, unsigned int datalen)
{
// Read from your buffer here...
return FMOD_OK;
}
FMOD_RESULT F_CALLBACK pcmsetposcallback(FMOD_SOUND *sound, int subsound, unsigned int position, FMOD_TIMEUNIT postype)
{
// Seek to a location in your data, may not be required for what you want to do
return FMOD_OK;
}
这应该是你需要得到FMOD播放你的缓冲区的一切。
That should be everything you need to get FMOD playing back your buffer.
这篇关于C&放大器; FMOD防爆 - 玩实时一个PCM阵列/缓冲器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!