Results 1 to 2 of 2

Thread: Qt and FMOD simple playsound

  1. #1
    Join Date
    Dec 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Qt and FMOD simple playsound

    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.

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include "QPainter.h"
    4. #include "inc/fmod.h"
    5. #include "inc/fmod_dsp.h"
    6. #include "inc/fmod_errors.h"
    7.  
    8.  
    9.  
    10. MainWindow::MainWindow(QWidget *parent) :
    11. QMainWindow(parent),
    12. ui(new Ui::MainWindow)
    13. {
    14. ui->setupUi(this);
    15. }
    16.  
    17. MainWindow::~MainWindow()
    18. {
    19. delete ui;
    20. }
    21.  
    22. void ERRCHECK(FMOD_RESULT result)
    23. {
    24. if (result != FMOD_OK)
    25. {
    26. printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
    27. exit(-1);
    28. }
    29. }
    30.  
    31. void MainWindow::paintEvent(QPaintEvent *)
    32. {
    33. QPainter p(this);
    34. p.setPen(Qt::black);
    35. p.setBrush(Qt::black);
    36.  
    37. FMOD_SYSTEM *system;
    38. FMOD_SOUND *snare1;
    39. FMOD_CHANNEL *channel = 0;
    40. FMOD_RESULT result;
    41.  
    42. result = FMOD_System_Create(&system);
    43. ERRCHECK(result);
    44.  
    45. result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
    46. ERRCHECK(result);
    47.  
    48. result = FMOD_System_CreateSound(system, "drums/snare1.wav", FMOD_SOFTWARE, 0, &snare1);
    49. ERRCHECK(result);
    50.  
    51. result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, snare1, 0, &channel);
    52. ERRCHECK(result);
    53.  
    54.  
    55. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt and FMOD simple playsound

    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_H ARDWARE | 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
    Last edited by guopei296; 10th December 2011 at 07:09.

Similar Threads

  1. audio editor and fmod
    By vijay_kansal in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2011, 21:55
  2. a simple calculator in C++
    By thehindutimes in forum General Programming
    Replies: 4
    Last Post: 4th May 2011, 20:31
  3. Packaging Mac OSX Dynamic Library (FMOD)
    By My3rdGradeShirt in forum Newbie
    Replies: 0
    Last Post: 27th November 2010, 17:03
  4. Qt and fmod
    By Alex63 in forum Qt Programming
    Replies: 4
    Last Post: 30th June 2006, 17:10
  5. math.h included, but fmod not available
    By jamadagni in forum General Programming
    Replies: 1
    Last Post: 8th January 2006, 06:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.