如何在C++中使用FMOD?

问题描述 投票:0回答:3

我正在尝试使用 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++编译程序?

c++ g++ fmod
3个回答
3
投票

FSOUND_Init 是一个 FMOD 3 API 函数,您正在使用 FMOD Ex,因此该函数不存在。要初始化 FMOD Ex,您应该包含“fmod.hpp”并使用以下功能:

System_Create 创建FMOD系统对象,然后

System::init 进行初始化,然后是

System::createStream 加载您的 MP3,然后

System::playSound 来播放它。

FMOD 附带了许多有用的示例,您可以将其用作参考,尤其是您想要实现的播放流示例。还有 CHM 格式的完整文档。如果您要从 FMOD 3 移植代码,我建议您阅读 fmodex.chm 文档中的迁移指南。


0
投票

您还需要包含库的标题,添加

#include <fmod.h>

在代码的开头。


0
投票
You must go to the FMOD page (https://fmod.com/), and log in to download the version for custom graphics engines.
[enter image description here][1]
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.
[enter image description here][2]
We also copy the libraries (.lib files) to our libraries (.lib) folder.
[enter image description here][3]
Then we look for the lib folder, which is inside the FMOD Studio API folder
Windows/api/studio.
[enter image description here][4]
We choose the folder that corresponds to the system we work with.
We copy the libraries (.lib files) to our libraries folder (.lib).
[enter image description here][5]
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.
[enter image description here][6]
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.
[enter image description here][7]
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.
#include <FMOD/fmod_studio.hpp>
#include <FMOD/fmod.hpp>
Initialize an instance of the FMOD engine.
FMOD::System* system;
FMOD_RESULT result=FMOD::System_Create(&system)
If the sound is 3D I establish the speed of sound, distance unit and scaling factor of the
ambient sound.
system->set3DSettings(1.0,1.0f,1.0f);
I initialize and prepare FMOD for audio playback.
result=system->init(512,FMOD_INIT_NORMAL,nullptr);
Load sound into memory for streaming or setup
callback based sounds
FMOD::Sound* sound;
result=system->createSound("name.mp3",FMOD_DEFAULT,nullptr,&sound);
I create a channel to play the sound.
FMOD::Channel*channel;
result=system->playSound(sound,nullptr,false,&channel)
That would be all, don't forget to release the sound engine, channels and delete the songs you loaded.
system->release();
channel->stop();
  [1]: https://i.stack.imgur.com/zq5TE.png
  [2]: https://i.stack.imgur.com/2eDqX.png
  [3]: https://i.stack.imgur.com/iU1pS.png
  [4]: https://i.stack.imgur.com/mNYP4.png
  [5]: https://i.stack.imgur.com/PfOSL.png
  [6]: https://i.stack.imgur.com/xoDd5.png
  [7]: https://i.stack.imgur.com/rWRmJ.png
© www.soinside.com 2019 - 2024. All rights reserved.