How to set up the FMOD audio library in Qt Creator for Android
-
I tried FMOD, Bass, QMediaPlayer and OpenAL. For me, OpenAL is the best. I have made my choice. That's all for the audio library.
Now I will focus on translating my demos from pure WebGL 1.0 (Box2D-WASM/Ammo.js) to OpenGL ES 2.0 (Box2D/Bullet Physics) to run on Android and Desktop:
Pong game using WebGL 1.0, Web Audio API, glMatrix, FreeTexturePacker and JavaScript: https://8observer8.github.io/webgl10-js/2d-games/pong-2d-noobtuts-port-box2dcore-webgl-js/
Multiplayer demo with Jill. This demo uses free hosting from Render.com. You must wait 15-20 seconds to start the server for the first time. The Node.js server on a free hosting falls asleep 30 minutes after the last activity.: https://8observer8.github.io/webgl10-js/room-webgl-js/
You can select "first person" and "third person" camera:
Jill with lighthouse: https://8observer8.github.io/webgl10-js/simple-lighthouse-oimophysics-webgl-js/
I extracted models, textures and animations from the original Resident Evil game. I imported them to Blender, exported to DAE (COLLADA), and import them to pure WebGL 1.0:
- Jill animations: https://8observer8.github.io/webgl10-js/re1/jill-animations-without-skinning-webgl-js/
- Barry animations: https://8observer8.github.io/webgl10-js/re1/barry-animations-without-skinning-webgl-js/
Super Mario (box2d-core) and Bomberman (Box2D-WASM):
Mario: https://8observer8.github.io/webgl10-js/mario-2d-jumps-box2dcore-webgl-js/
Output of English, Russian and Chinese fonts with stroke and Distance Field (the text is not pixelated when the camera zooms in) on JS and Rollup. Fonts converted to Distance Field using Hiero. Shadows was baked in Blender. Demo in the browser: https://8observer8.github.io/webgl10-js/shapes-with-text-webgl-js/
Click detection with color ID. Font in English and Russian. Dynamic shadow: https://8observer8.github.io/webgl10-js/door-with-ortho-shadow-map-webgl-js/
Another demos I will be published here: https://8observer8.github.io/
-
To set up the FMOD audio library in Qt Creator for Android, follow these general steps:
Download FMOD Studio:
Go to the FMOD website and download the FMOD Studio API package.
Install FMOD Studio:
Install FMOD Studio on your development machine.
Create a Qt Android Project:Start a new Qt Creator project for Android or open an existing one.
Include FMOD Libraries:
Add the FMOD library to your Qt project. You can do this by adding the FMOD header files and libraries to your project's .pro file:
INCLUDEPATH += /path/to/fmod/api/lowlevel/inc
LIBS += -L/path/to/fmod/api/lowlevel/lib -lfmodAndroid Permissions:
If your app requires audio permissions, add the necessary permissions to your AndroidManifest.xml file.
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>Initialize FMOD:
In your Qt code, initialize FMOD as early as possible in your application. You'll typically do this in your main function or at the beginning of your Qt application.
#include "fmod.h"
FMOD_SYSTEM* system;
FMOD_RESULT result = FMOD_System_Create(&system);
if (result != FMOD_OK) {
// Handle initialization error
}
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0);
if (result != FMOD_OK) {
// Handle initialization error
}Use FMOD in Your Application:
You can now use FMOD functions to manage and play audio within your Qt Creator project.
Build and Deploy:
Build your Qt project and deploy it to an Android device or emulator.
Please note that the specific paths, project configurations, and setup may vary depending on your Qt Creator project and the version of FMOD you are using. Make sure to refer to the FMOD documentation and your Qt Creator documentation for more details and any version-specific information.
-
@Robert-A-Navarro thank you for your answer. I want to try to run FMOD on Android again but before it I want to try to run it on Windows 10 with Qt6 MinGW 64-bit but I have the problem:
undefined reference to `FMOD_System_Create'
. My steps are below.I downloaded "FMOD Engine" instead of "FMOD Studio" because I need "include" and "libs" only:
This is the contains of the "lib/x64" folder:
There are no the
fmod.a
file here. I tried to include "fmod.dll" like this:INCLUDEPATH += "E:/Libs/fmod-2.2.21-mingw-64-bit/include" LIBS += -L"E:/Libs/fmod-2.2.21-mingw-64-bit/lib/x64/fmod.dll"
But I have this error:
undefined reference to `FMOD_System_Create'
I tried to use FMOD with SFML in makefile. It works without the problem:
CC = g++ INC = -I"E:\Libs\SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit\include" \ -I"E:\Libs\box2d-2.4.1-mingw-64-bit\include" \ -I"E:\Libs\fmod-2.2.21-mingw-64-bit\include" LIB = -L"E:\Libs\SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit\lib" \ -L"E:\Libs\box2d-2.4.1-mingw-64-bit\lib" FLAGS = -c -DSFML_STATIC all: main.o $(CC) main.o $(LIB) -static \ "E:\Libs\fmod-2.2.21-mingw-64-bit\lib\x64\fmod.dll" \ -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lfreetype \ -lopengl32 -lwinmm -lgdi32 -lbox2d -o app main.o: main.cpp $(CC) $(FLAGS) $(INC) main.cpp
-
@8Observer8 said in How to set up the FMOD audio library in Qt Creator for Android:
LIBS += -L"E:/Libs/fmod-2.2.21-mingw-64-bit/lib/x64/fmod.dll"
This is wrong. DLL files are used at runtime. To link your application you need LIB files. In this case it should be:
LIBS += -L"E:/Libs/fmod-2.2.21-mingw-64-bit/lib/x64/fmod.lib"
-
This is a solution for the absolute path:
INCLUDEPATH += "E:/libs/fmod-2.2.21-mingw-64-bit/include" LIBS += -L"E:/libs/fmod-2.2.21-mingw-64-bit/lib/x64/" LIBS += -lfmod
Andrew helped me here:
Looks like you need to add the library path like so: -L"E:\Libs\fmod-2.2.21-mingw-64-bit\lib\x64" And instead of specifying the full path to fmod.dll on your command line (“E:\Libs\fmod-2.2.21-mingw-64-bit\lib\x64\fmod.dll”) you should use -lfmod instead.
But I need a relative path and I try it:
INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include LIBS += $$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64 LIBS += -lfmod
But I have this error:
It can be solved by copying
fmod.dll
to the Debug folder:@jsulm said in How to set up the FMOD audio library in Qt Creator for Android:
This is wrong. DLL files are used at runtime. To link your application you need LIB files.
But where will I find
fmod.lib
? There is no such file in thelib/x64
folder:I tried to use
fmod_vc.lib
instead offmod.lib
:INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include LIBS += $$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64/fmod_vc.lib
But I have this error:
I try to use fmod with relative paths. I created thelibs
folder in my project folder. I don't want to copyfmod.dll
to the Debug folder: -
@8Observer8 said in How to set up the FMOD audio library in Qt Creator for Android:
But where I will find fmod.lib. There is no such file in the lib folder
I guess what you have is pre-build release. You need a development package, don't know where you can get it from. Maybe https://www.fmod.com/docs/2.00/api/platforms-win.html helps.
-
@jsulm said in How to set up the FMOD audio library in Qt Creator for Android:
Maybe https://www.fmod.com/docs/2.00/api/platforms-win.html helps.
Unfortunately, there is no new information for me here:
The C API of the supplied libraries are compatible with MinGW (C++ ABI not supported). The 64 bit dll can be linked directly. You will need to use the import library libfmod.a and libfmodstudio.a in order to link the 32 bit dlls.
Yes, I see it. There is libfmod.a in the x86 folder and there is no it in the x64 folder. This information that The 64 bit dll can be linked directly works for a relative path (even without copyingfmod.dll
to the Debug folder)INCLUDEPATH += "E:/libs/fmod-2.2.21-mingw-64-bit/include" LIBS += -L"E:/libs/fmod-2.2.21-mingw-64-bit/lib/x64/" LIBS += -lfmod
But when I try to change the absolute set up path to the relative path:
INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include LIBS += $$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64 LIBS += -lfmod
I have this error:
It requires to copy 'fmod.dll' to the Debug folder.
FMOD Core Engine library
- /api/core/lib/$ARCH/fmod_vc.lib - Release binary for production code (requires fmod.dll at runtime).
- /api/core/lib/$ARCH/fmodL_vc.lib - Release binary with logging enabled for development (requires fmodL.dll at runtime).
Yes, it is true. It is really
requires fmod.dll at runtime
I tried to usefmod_vc.lib
:INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include LIBS += $$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64/fmod_vc.lib
It works after copying fmod.dll to the Debug folder:
It seams like I cannot use the relative set up path without manual copying of
fmod.dll
to the Debug folder:INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include LIBS += $$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64 LIBS += -lfmod
But why I don't need to copy
fmod.dll
to the Debug folder when I set up FMOD using the absolute set up path:INCLUDEPATH += "E:/libs/fmod-2.2.21-mingw-64-bit/include" LIBS += -L"E:/libs/fmod-2.2.21-mingw-64-bit/lib/x64/" LIBS += -lfmod
-
This is my simple project for Qt6 MinGW 64-bit that plays the OGG audio file on Windows: play-audio-from-resources-fmod-qt6-cpp.zip (2.77 MB) You can download it and experiment with the relative set up file. There is the
libs
folder with FMOD 2.2.21 inside of the project folder. I want to run it without manual copying offmod.dll
to the Debug folder. You can create thelibs
folder on your hard drive and copy my contains of 'libs' folder to it to check that absolute set up path doesn't require manual copying offmod.dll
to the Debug folder. You should to uncomment the absolute set up path and comment the relative path (don't forget to change a name of hard drive):play-audio-from-resources-fmod-qt6-cpp.pro:
QT += core gui widgets CONFIG += c++17 # The absolute set up FMOD path # Works without manual copying of fmod.dll to the Debug folder # INCLUDEPATH += "E:/libs/fmod-2.2.21-mingw-64-bit/include" # LIBS += -L"E:/libs/fmod-2.2.21-mingw-64-bit/lib/x64/" # LIBS += -lfmod # The relative set up FMOD path # Requires manual copying of fmod.dll to the Debug folder INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include LIBS += $$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64 LIBS += -lfmod # Using fmod_vc.lib # Requires manual copying of fmod.dll to the Debug folder # INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include # LIBS += $$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64/fmod_vc.lib # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # Disables all the APIs deprecated before Qt 6.0.0 DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 SOURCES += \ main.cpp \ widget.cpp HEADERS += \ widget.h RESOURCES += \ assets.qrc
widget.h
#ifndef WIDGET_H #define WIDGET_H #include <QtWidgets/QWidget> #include <fmod.h> class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = nullptr); ~Widget(); private: FMOD_SYSTEM *m_system; FMOD_SOUND *m_sound; }; #endif // WIDGET_H
widget.cpp
#include "widget.h" #include <QtCore/QByteArray> #include <QtCore/QFile> #include <QtCore/QString> Widget::Widget(QWidget *parent) : QWidget(parent) { FMOD_System_Create(&m_system, FMOD_VERSION); FMOD_System_Init(m_system, 32, FMOD_INIT_NORMAL, 0); QString soundPath(":/assets/audio/overworld.ogg"); QFile f(soundPath); if (!f.open(QIODevice::OpenModeFlag::ReadOnly)) { qDebug() << "Faild to open the file: " << soundPath; return; } QByteArray soundData = f.readAll(); f.close(); FMOD_CREATESOUNDEXINFO* exinfo = new FMOD_CREATESOUNDEXINFO(); exinfo->length = static_cast<unsigned int>(soundData.length()); exinfo->cbsize = sizeof(FMOD_CREATESOUNDEXINFO); FMOD_System_CreateSound(m_system, soundData.data(), FMOD_OPENMEMORY, exinfo, &m_sound); FMOD_Sound_SetMode(m_sound, FMOD_LOOP_OFF); FMOD_System_PlaySound(m_system, m_sound, 0, false, 0); } Widget::~Widget() { }
main.cpp
#include "widget.h" #include <QtWidgets/QApplication> int main(int argc, char *argv[]) { QApplication app(argc, argv); Widget w; w.show(); return app.exec(); }
assets.qrc
<RCC> <qresource prefix="/"> <file>assets/audio/overworld.ogg</file> </qresource> </RCC>
-
@8Observer8 If you want to run your app outside of QtCreator you first have to deploy it, so it contains all needed libraries.
-
@jsulm I want to run my app inside of Qt Creator with relative set up path (with using
$$PWD
instead of"E:/
) because I want to distribute my examples with included libs. For example, I can post my examples (ZIPs) on the forums and people can download it and run without set up of FMOD and so on. And without manual copying offmod.dlll
to the Debug folder. For a while the"E:/
method (absolute path) works without manual copying offmod.dll
but the$$PWD
method (relative path) requires to copyfmod.dll
to the Debug folder. The distribution of EXE is very clear for me. Yes, of course I should distributefmod.dll
,Qt6Core.dll
and so on with EXE. My question about distribution of Qt project with libs to run it very quickly in Qt Creator on another computer.The
$$PWD
method (relative path) allows to include all libs to a project. I should works like this - everyone can download the project and run it without downloading requires libs and without manual copying offmod.dll
to the Debug folder: -
@8Observer8 It looks like the library is part of your project. You could use https://wiki.qt.io/SUBDIRS_-_handling_dependencies project and make your main project depend on the library sub-project. In that case the libs should be copied during the build.
-
@jsulm said in How to set up the FMOD audio library in Qt Creator for Android:
It looks like the library is part of your project.
I don't have a source code of the proprietary FMOD library. I have only two folders for this library in my project folder:
include
:
andlibs
:I think SUBDIRS cannot copy
fmod.dll
from thelibs/fmod-2.2.21-mingw-64-bit/lib/x64
folder to the Debug folder or can it? -
I solved the problem with the relative paths to the library! I just added
-L
before$$PWD
like this:INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include LIBS += -L$$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64 LIBS += -lfmod
Now you can download the next example and run it in Qt Creator (with MinGW 64) without necessary to set up FMOD or changing the paths in pro-file: play-audio-from-resources-fmod-qt6-cpp.zip (2.51 MB)