如何在 C++ 中使用 FMOD?
我正在尝试使用 FMOD 创建一个简单的 mp3 播放器:
#include "inc/fmod.h"
int main()
{
FSOUND_Init(44100, 32, 0);
return 0;
}
尝试编译程序时出现以下错误:
holle@x300:justmp3$ pwd
/media/daten/Entwicklung/C/justmp3
holle@x300:justmp3$ LD_LIBRARY_PATH=$(pwd)/lib
holle@x300:justmp3$ ls $LD_LIBRARY_PATH
libfmodex-4.34.02.so libfmodexL-4.34.02.so
holle@x300:justmp3$ g++ -o mp3 mp3.cpp
mp3.cpp: In function ‘int main()’:
mp3.cpp:8: error: ‘FSOUND_Init’ was not declared in this scope
我的错误是什么?我怎样才能让g++编译程序?
I'm trying to create a simple mp3 player using FMOD:
#include "inc/fmod.h"
int main()
{
FSOUND_Init(44100, 32, 0);
return 0;
}
Trying to compile the program I get the following error:
holle@x300:justmp3$ pwd
/media/daten/Entwicklung/C/justmp3
holle@x300:justmp3$ LD_LIBRARY_PATH=$(pwd)/lib
holle@x300:justmp3$ ls $LD_LIBRARY_PATH
libfmodex-4.34.02.so libfmodexL-4.34.02.so
holle@x300:justmp3$ g++ -o mp3 mp3.cpp
mp3.cpp: In function ‘int main()’:
mp3.cpp:8: error: ‘FSOUND_Init’ was not declared in this scope
What's my mistake? How could I get g++ to compile the program?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
FSOUND_Init 是一个 FMOD 3 API 函数,您正在使用 FMOD Ex,因此该函数不存在。要初始化 FMOD Ex,您应该包含“fmod.hpp”并使用以下函数:
System_Create 创建 FMOD 系统对象,然后
使用 System::init 进行初始化,然后使用
System::createStream 加载 MP3,然后使用
System::playSound 来 初始化 FMOD Ex。玩它。
FMOD 附带了许多有用的示例,您可以将其用作参考,尤其是您想要实现的播放流示例。还有 CHM 格式的完整文档。如果您要从 FMOD 3 移植代码,我建议您阅读 fmodex.chm 文档中的迁移指南。
FSOUND_Init is an FMOD 3 API function, you are using FMOD Ex so that function doesn't exist. To initialize FMOD Ex you should include "fmod.hpp" and use the functions:
System_Create to create the FMOD system object, then
System::init to initialize, followed by
System::createStream to load your MP3, then
System::playSound to play it.
There are a bunch of useful examples that ship with FMOD that you could use as a reference, especially the playstream example for what you want to achieve. Also there is full documentation in CHM format. If you are porting code from FMOD 3 I would recommend reading the migration guide in the fmodex.chm docs.
您还需要包含库的标头,添加
在代码的开头。
You need to include the headers for the library too, add
at the beginning of your code.
您必须前往 FMOD 页面 (https://fmod.com/),然后登录才能下载版本用于自定义图形引擎。
安装后,我们转到保存文件的文件夹中查找 lib 文件夹,该文件夹位于 FMOD Studio API/Windows/api/core 文件夹内。然后我们选择与我们正在使用的平台相对应的文件夹,并将 .dll 文件复制到我们的项目中。
我们还将库(.lib 文件)复制到我们的库(.lib)文件夹中。
然后我们寻找 lib 文件夹,该文件夹位于 FMOD Studio API 文件夹内
Windows/api/工作室。
我们选择与我们使用的系统相对应的文件夹。
我们将库(.lib 文件)复制到库文件夹(.lib)。
然后我们转到 FMOD Studio 文件夹内的 inc 文件夹
API/Windows/apistudio 并将文件复制到其中。
我们返回到项目的includes文件夹并创建FMOD文件夹,
我们放置复制的文件的地方。
同样,我们转到 FMOD Studio 文件夹内的 inc 文件夹
用于复制文件的 Windows\api\studio API。回到我们的项目,在项目的 include 文件夹中我们创建 FMOD 文件夹,
我们放置复制的文件的地方。
通过以上内容,我们现在可以在我们的项目中使用 FMOD 库了。现在在主文件中我们添加 fmod_studio.hpp 库
和 fmod.hpp。
初始化 FMOD 引擎的实例。
如果声音是 3D,我确定声音的速度、距离单位和比例因子
环境声音。
我初始化并准备 FMOD 以进行音频播放。
将声音加载到内存中进行流式传输或设置
我创建一个通道来播放声音。
就这样,不要忘记释放声音引擎、频道并删除您加载的歌曲。
You must go to the FMOD page (https://fmod.com/), and log in to download the version for custom graphics engines.
Once installed, we go to the folder where we saved the file to look for the lib folder, which is inside the FMOD Studio API/Windows/api/core folder. Then we choose the folder that corresponds to the platform we are working with and copy the .dll files to our project.
We also copy the libraries (.lib files) to our libraries (.lib) folder.
Then we look for the lib folder, which is inside the FMOD Studio API folder
Windows/api/studio.
We choose the folder that corresponds to the system we work with.
We copy the libraries (.lib files) to our libraries folder (.lib).
Then we go to the inc folder that is inside the FMOD Studio folder
API/Windows/apistudio and copy the files to it.
We return to the includes folder of our project and create the FMOD folder,
where we put the copied files.
Likewise, we go to the inc folder that is inside the FMOD Studio folder
Windows\api\studio API to copy your files. Returning to our project, Inside the include folder of our project we create the FMOD folder,
where we put the copied files.
With the above we can now use the FMOD library in our project. Now in the main file we add the fmod_studio.hpp libraries
and fmod.hpp.
Initialize an instance of the FMOD engine.
If the sound is 3D I establish the speed of sound, distance unit and scaling factor of the
ambient sound.
I initialize and prepare FMOD for audio playback.
Load sound into memory for streaming or setup
I create a channel to play the sound.
That would be all, don't forget to release the sound engine, channels and delete the songs you loaded.