PDA

View Full Version : Qt and FMOD simple playsound



ctrestain
9th December 2011, 22:04
Hey. I'm still kind of a newbie with this stuff. I got fmod to work with dev c++ just fine, but i'm having trouble with Qt. I just need to be able to play a .wav file and i'll be good to go. Here is the code i'm using so far. It runs fine but makes a beeping sound instead of the sound I want it to play.



#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QPainter.h"
#include "inc/fmod.h"
#include "inc/fmod_dsp.h"
#include "inc/fmod_errors.h"



MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}

void MainWindow::paintEvent(QPaintEvent *)
{
QPainter p(this);
p.setPen(Qt::black);
p.setBrush(Qt::black);

FMOD_SYSTEM *system;
FMOD_SOUND *snare1;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;

result = FMOD_System_Create(&system);
ERRCHECK(result);

result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);

result = FMOD_System_CreateSound(system, "drums/snare1.wav", FMOD_SOFTWARE, 0, &snare1);
ERRCHECK(result);

result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, snare1, 0, &channel);
ERRCHECK(result);


}

guopei296
10th December 2011, 07:09
i am using qt4.7 with fmod ex 4.38.03,but i got a serious problem to link fomd lib:

bool FmodAudio::initMusic()
{
//init
FMOD_RESULT result;
result = FMOD_System_Create(&mSystem);
ERRCHECK(result);

//test version
unsigned version = 0;
result = FMOD_System_GetVersion(mSystem,&version);
ERRCHECK(result);

if( version < FMOD_VERSION )
{
char sz[100];
sprintf(sz,"oldversion FMOD %08x.you need %08x\n",version,FMOD_VERSION);
QMessageBox().warning(NULL,"FMOD version error",QString(QLatin1String(sz)));
return false;
}

// init
result =FMOD_System_Init(mSystem,1,FMOD_INIT_NORMAL,0 );
ERRCHECK(result);

// create stream
result = FMOD_System_CreateStream(mSystem,"shot.wma",FMOD_HARDWARE | FMOD_LOOP_NORMAL | FMOD_2D,0,&mSound );
ERRCHECK(result);
// play
result = FMOD_System_PlaySound(mSystem,FMOD_CHANNEL_FREE,mS ound,false,&mChannel );
ERRCHECK(result);

return true;
}

the error is:
undefined reference to `FMOD_System_Create@4'
undefined reference to `FMOD_System_GetVersion@8'
undefined reference to `FMOD_System_Init@16'
undefined reference to `FMOD_System_CreateStream@20'
undefined reference to `FMOD_System_PlaySound@20'

in the .pro file,i set to link fmod lib:
FMODHOME = E:\Qt\FMOD_Pro_API_Win32\api
INCLUDEPATH += $$FMODHOME\inc
LIBS += -L$$FMODHOME\lib\libfmodexL.a

how to resolve the problem,thanks all!!

Added after 1 45 minutes:

i made a mistake that i write “target” attribute in the pro file。remove it then work ok