Thread: FMOD Decides it doesn't want to...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    FMOD Decides it doesn't want to...

    I've decided to use FMOD after deciding I don't like OpenAL (don't ask) and twas all going fine, but sometimes it just decides not to load the sound files.

    This snippet works, but only sometimes:

    Code:
    result = fmod_system->createStream ("\\Condensed.mp3", FMOD_DEFAULT, 0, &sound);
    if (result != FMOD_OK) {
        cout << "\tFAILED\n";
        exit (1);
    }
    It works fine (Condensed.mp3 is in the same directory) but sometimes it just fails. If I change the file I want to load - even when it's in the same place - it sometimes doesn't work. The funny thing is it always works if I place the file in the root directory (C:\\ for example).

    Anyone have a similar problem?
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    does removing the '\\' make a difference?

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Nope I get the same problem.
    EDIT: When it doesn't load it from the same dir, if I move it to C:\\Condensed.mp3 then it loads it, and I re-compile it using "\\Condensed.mp3", it suddenly can see it.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  4. #4
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Then you could get the path to your exe and then strcat \\Condensed.mp3. I had to do that once for something can't quite remember what though.

  5. #5
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Ok I'll try that.
    EDIT: I assume there's a winAPI call to get that - to save me hard coding it?
    Last edited by cboard_member; 02-15-2006 at 04:49 AM.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    This will play MP3's through DirectShow. Most of the source originates from Special Effects Game Programing with DirectX 8. All it needs is a window handle.

    Code:
    #ifndef CDXSHOWWND
    #define CDXSHOWWND
    
    #include <dshow.h>
    
    class CDXShowWnd
    {
      protected:
        IGraphBuilder *m_pGraph;
        IVideoWindow  *m_pVidWnd;
        IMediaControl *m_pMedia;
        IMediaEvent   *m_pEvent;
    
    
        HWND          m_Hwnd;
      public:
        CDXShowWnd(void):m_pGraph(NULL),m_pVidWnd(NULL),m_Hwnd(0) {}
        virtual ~CDXShowWnd(void)
        {
          ShutDown();
        }
    
        void Create(HWND hwnd)
        {
          //Create filter graph
          CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC,IID_IGraphBuilder,
                           (void **)&m_pGraph);
          
          m_pGraph->QueryInterface(IID_IVideoWindow,(void **)&m_pVidWnd);
          m_pGraph->QueryInterface(IID_IMediaControl,(void **)&m_pMedia);
          m_pGraph->QueryInterface(IID_IMediaEvent,(void **)&m_pEvent);
    
          //Set window
          m_pVidWnd->put_Owner((OAHWND)hwnd);
          m_pVidWnd->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);
          RECT grc;
          ::GetClientRect(hwnd,&grc);
          m_pVidWnd->SetWindowPosition(0,0,grc.right,grc.bottom);
        }
    
        void Play(const unsigned short *File)
        {
          m_pGraph->RenderFile(File,NULL);
          m_pMedia->Run();
    
          long lDone=0;
          m_pEvent->WaitForCompletion(0,&lDone);
    
        
        }
    
        void ShutDown(void)
        {
          m_pMedia->Release();
          m_pEvent->Release();
          m_pVidWnd->Release();
          m_pGraph->Release();
          CoUninitialize();
        }
    
    };
    
    #endif
    You will need to link with quartz.lib and strmiids.lib and of course have access to dshow.h.

    To respond to messages consult the DirectShow SDK on how to use IMediaEvent and callbacks.

  7. #7
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Cheers Bubba; I was going to ask about using DirectX for sound if all else failed.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    DirectSound won't natively load MP3's nor will DirectMusic. To get the spec for MP3's you must pay for them. But DirectShow does support them and you can use DirectShow as your sound system for simple apps.

  9. #9
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Or in theory... you are typing \\Condensed.mp3 you could use just Condensed.mp3 to get from the same directory or for say another dir you could sound\\Condensed.mp3. \\Condensed.mp3 may have some strange effects. I don't know why I didn't think of it sooner... but it hit me when I was working on some code...
    Code:
    player->SetImage("art/man.bmp",APAL);
    I know this works although I use / instead of \\
    Maybe this will help you some.

  10. #10
    Registered User
    Join Date
    Jan 2006
    Posts
    7
    Try to use:
    ".\\Condensed.mp3" or "./Condensed.mp3"
    The dot at start tells that Condensed is in the same folder where the executable is running (or debugging). Almost the same way the double dot, tells the file is at the "one folder above" folder. It reminds a little bit of "DOS", Unix, e.t.c.

    I hope this to work..

    Ps. For other folder (examples) you can use: ".\\x\\y\\z.mp3" (or "./x/y/z.mp3"). Or "..\\..\\x\\y\\z.mp3" ("../../x/y/z.mp3") e.t.c. At least I never had such problems using the dots. (I have never try it without the dots).

  11. #11
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Cheers to everyone for your help
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Incorrect results from fmod()?
    By karlthetruth in forum C Programming
    Replies: 4
    Last Post: 04-11-2008, 09:12 AM
  2. FMOD implimentation, how'd you do it?
    By Jeremy G in forum Game Programming
    Replies: 10
    Last Post: 06-12-2004, 12:04 AM
  3. error with fmod() function
    By minesweeper in forum C++ Programming
    Replies: 3
    Last Post: 08-30-2003, 05:24 AM
  4. Fmod and windows programming
    By AtomRiot in forum Windows Programming
    Replies: 1
    Last Post: 01-06-2003, 03:13 PM
  5. fmod problem
    By yusiye in forum C Programming
    Replies: 3
    Last Post: 08-01-2002, 07:28 PM