0
0

This should be an easy one guys. I’m using FMOD to create a VERY VERY simple MP3, OGG player for myself. Actually the ogg will come in later. Anyways I’ve been playing with this for awhile and I can not get it to properly play a mp3… I had before when I included an additional thred and a bunch of other stuff but it was sloppy and didn’t really run right. I’m creating a win32 app and I know that I need some kind of loop or something after FSOUND_Stream_Play() but i’m having no luck…. here is a copy of my source…. please don’t bash me too much on all the random remarks and horrid programming practices.

Thanks in advance for any help guys!!

I’ve omitted a bunch of stuff and only included what pertains…. i think

pragma comment(lib, “fmodvc.lib”)

include <windows.h> // Include to construct a window

include <stdio.h>

include <iostream> // Here we include the standard include file

include <conio.h> // This is used so we can use _kbhit() and getch()

include “resource.h”

include “./inc/fmod.h”

using namespace std;

//DlgMainProc Function Begin
//—————————————————————————————
LRESULT CALLBACK DlgMainProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc=NULL;

switch( message )                                       // Switch on all of the dialogs messages
{
    case WM_INITDIALOG:                                 // If Initilizing the dialog box        
        SetDlgItemText(hWnd, IDC_FILENAME, SONG_NAME);
        FSOUND_Init(44100,32, 0);
        // Do initialization here   (like WM_CREATE)
        return TRUE;

    case WM_COMMAND:                                    // If we clicked on anything in the dialog box

        switch( LOWORD( wParam ) )                      // Check the LOWORD of the wParam (Which holds the ID of what was clicked on)
        {    
            case IDC_PLAY:                                  // Check if the OK button was clicked                                                                                               
                                                        // This gets what the user typed into the password field.
                                                        // It takes the hWnd, the ID of the dialog box control, a string to hold what they typed in,
                                                        // and how many characters you want to retrieve from the field.
                SetDlgItemText(hWnd, IDC_STATUS, "Playing");
                StartSong();
                //threadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) StartSong(*pHWND), NULL, 0, NULL);
                //WaitForSingleObject(threadHandle, INFINITE);
                //StartSong();                                      
                //MessageBox(hWnd, "Incorrect password! (""GameTutorials"")", "Error!", MB_OK);
                return TRUE;                            // Return from the dialog proc

            case IDC_STOP:
                SONG_PLAYING = false;
                SetDlgItemText(hWnd, IDC_STATUS, "Stopped");
                break;

            case ID_HELP_ABOUT:
                return DialogBox(NULL, MAKEINTRESOURCE(IDD_DLGABOUT), NULL, (DLGPROC)DlgAboutProc);

            case IDCANCEL:                              // Check if the cancel button was pressed
                EndDialog( hWnd, FALSE );               // Close the dialog box

                return TRUE;                            // Quit from this function
        }
        break;

    case WM_CLOSE:                                      // If we close the dialog box

        EndDialog( hWnd, FALSE );                       // Close the dialog box

        break;

    case WM_DESTROY:                                    // This message happens when the dialog box closes          

        // If we need to free anything, do it here

        break;                                          // Break from the loop
}

return FALSE;                                           // Return a default false

}

//StartSong Function Begin
//—————————————————————————————
int StartSong()
{
SONG_PLAYING = true;
FSOUND_STREAM *stream = NULL;
stream = FSOUND_Stream_Open(SONG_NAME, FSOUND_HW3D, 0, 0);
while(FSOUND_Stream_Play(FSOUND_FREE, stream))
{
if(SONG_PLAYING == false)
{
return 0;
}
}

    // We not have the Fmod Sound System initialized and we also have the song loaded.
    // All we need to do now is play the song.

    // Now we will play the current song loaded (SONG_NAME)
    //mySong.PlaySong();
    // Now that the song is playing, we want to get some information about it.
    // Below we print out the amount of channels being played and the CPU usage.  
    // The CPU Usage is displayed in a percentage.  The "channels playing" should
    // only say one, since we only have one sound going.  There are more channels
    // when dealing with MOD and MIDI music because it isn't one constant flow of
    // sound data, it is a mixing of data.

    // Loop until we hit the keyboard
    //while (!_kbhit())
    //while (SONG_PLAYING == true)
    //{
    //  Sleep(500);
        // Print out the details of the current song being played.
        // Notice the "\r", it will redraw over itself each time.
        //cout &lt;&lt; " channels playing: " &lt;&lt; FSOUND_GetChannelsPlaying() // This returns the amount of channels being played
        //   &lt;&lt; " cpu usage: "&lt;&lt; FSOUND_GetCPUUsage()   // This returns the CPU usage we are taking up
        //   &lt;&lt; "%     \r";               
    //} 
    //SONG_PLAYING = false;
    // Return a success!
    return 0;

}

  • You must to post comments
0
0

Well that is what I thought so too. I first started with that but then I had noticed with a console (dos) version of the program it had a while !kbhit loop in there and I had inserted an altered version of that and it work… although not properly. I did some debugging tests and check to make sure the function was being called and run and it is… I also removed it an place the code in the main portion of the program and it still won’t play. Does it have something to do maybe with it being a dialog-based application? Here is a cut of my play song function now:

//StartSong Function Begin
//—————————————————————————————
int StartSong(HWND hWnd)
{
//SONG_PLAYING = true;
FSOUND_STREAM *stream = NULL;
stream = FSOUND_Stream_Open(SONG_NAME, FSOUND_HW3D, 0, 0);
FSOUND_Stream_Play(FSOUND_FREE, stream);
return 0;
}
//—————————————————————————————
//StartSong Function End

Does the FSOUND_HW3D have anything to do with it? Do I need to change that maybe?

Thanks for the help.

  • You must to post comments
0
0

Sorry to reply again but I made a break through

//StartSong Function Begin
//—————————————————————————————
int StartSong()
{
SONG_PLAYING = true;
FSOUND_STREAM *stream = NULL;
stream = FSOUND_Stream_Open(SONG_NAME, FSOUND_2D, 0, 0);
FSOUND_Stream_Play(FSOUND_FREE, stream);
//if(SONG_PLAYING == false)
//{
// return 1;
//}
//SONG_PLAYING = false;
//while(1);
Sleep(5000);
return 0;
}
//—————————————————————————————
//StartSong Function End

I checked another post (the one reguarding 1 speaker output) he had a “while(1)” I tried that with FSOUND_2D and it worked!!! However it pretty much locks up the program while and after playing the mp3. I changed it with sleep for five seconds… seeing that the jules.mp3 is 4sec and it worked too. So I guess it has to wait somehow until the song is over to exit the function? How would I work around this? Thank for the help.

-Blackbolt

  • You must to post comments
0
0

Brett,

Thank you for all your help. I figured out what was going wrong. I had placed the FSOUND_Init code in the top section of my program after the includes and declares and such because the documentation stated that it only needed to be initialized once… apparently that cause some type of problem with program/function scope. Anyways here is my code that fixed it..

//StartSong Function Begin
//—————————————————————————————
int StartSong()
{
FSOUND_Init(44100,32, 0);
FSOUND_STREAM *stream = NULL;
stream = FSOUND_Stream_Open(SONG_NAME, FSOUND_2D, 0, 0);
FSOUND_Stream_Play(FSOUND_FREE, stream);
return 0;
}
//—————————————————————————————
//StartSong Function End

just like you said FSOUND_Stream_Open and it goes!! Thanks agian… by the way I really like FMOD I think it is a GREAT API…. very easy to work with as long as you don’t make stupid mistakes in your code like me :) I do have one suggestion… maybe placing code examples/snippits in the fmod.chm file would be nice but other than that it’s really well documented.

-Blackbolt

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.