0
0

Hi I’m new here (and to FMod) and I hope somebody can hep me out. I don’t know what I’m doing wrong but it is really bugging me. Let me explain, when I use the following code in my program it plays the file OK:-

[code:6gv3yjua] FMUSIC_MODULE *m_pModule;
m_pModule = NULL;
m_pModule = FMUSIC_LoadSong(MUSIC_NAME);

//Plays the music
FMUSIC_PlaySong(m_pModule);

[/code:6gv3yjua]

the MUSIC_NAME comes from this defintion at the top of the file

[code:6gv3yjua]#define MUSIC_NAME “ELITET.ROL”[/code:6gv3yjua]

As stated above that code works fine. The problem crops up when I move the “FMUSIC_MODULE *m_pModule;” and put it as a protected or public variable in the header file of my program. The rest of the code then looks like this

[code:6gv3yjua] m_pModule = NULL;
m_pModule = FMUSIC_LoadSong(MUSIC_NAME);

//Plays the music
FMUSIC_PlaySong(m_pModule);[/code:6gv3yjua]

When I run the program I get an assertion error and the program crashes when it gets to the LoadSong line. Checking in the debugger reveals that the program can not find “FMUSIC_MODULE”.

I have checked the header files are loaded correctly and so is the dll. Any help would be appreachiated. Thanks.

I am using WinXP with VC++ 6 and the latest version of FMod (Version on downloads page). Please bare in mind that I have only been programming for a couple of years.

Forgot to mention that “FSOUND_Init(44100, 32, FSOUND_INIT_GLOBALFOCUS” this line is also loaded before “m_pModule = NULL;” in both bits of code. Hope this makes sence. :)

  • You must to post comments
0
0

Thanks for replying. I can not post all of the code in the project as that would be too big. I will post the 2 files that have the FMod stuff in midi.h and midi.cpp

midi.h
[code]

if !defined(AFX_MIDI_H__EFDB70FA_C05C_48A6_B384_DAA5E19985FC__INCLUDED_)

define AFX_MIDI_H__EFDB70FA_C05C_48A6_B384_DAA5E19985FC__INCLUDED_

//Required FMod header files

include”fmod.h”

include “fmod_errors.h”

if _MSC_VER > 1000

pragma once

endif // _MSC_VER > 1000

// midi.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// midi window

class midi : public CWnd
{
// Construction
public:
midi();

// Attributes
public:
void startSoundSystem();
void PlayMidi();
void endMidi();
void pauseMidi();
void DisplayError();
FMUSIC_MODULE *m_pModule; //Get errors

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(midi)
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~midi();

// Generated message map functions

protected:
//{{AFX_MSG(midi)
// NOTE – the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

endif // !defined(AFX_MIDI_H__EFDB70FA_C05C_48A6_B384_DAA5E19985FC__INCLUDED_)

[/code]

midi.cpp
[code]
// midi.cpp : implementation file
//

include “stdafx.h”

include “Assignment 1.h”

include “midi.h”

//This is the fmod library

pragma comment(lib, “fmodvc.lib”)

ifdef _DEBUG

define new DEBUG_NEW

undef THIS_FILE

static char THIS_FILE[] = FILE;

endif

//This is the midi we want to play (Have to specify file name and not a resource name)

define MUSIC_NAME “ELITET.ROL”

/////////////////////////////////////////////////////////////////////////////
// midi

midi::midi()
{
}

midi::~midi()
{
}

BEGIN_MESSAGE_MAP(midi, CWnd)
//{{AFX_MSG_MAP(midi)
// NOTE – the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// midi message handlers

void midi::startSoundSystem()
{
if (FSOUND_GetVersion() < FMOD_VERSION)
{
printf(“Error : You are using the wrong DLL version! You should be using FMOD %.02f\n”, FMOD_VERSION);
//return 1;
}

//Set the quality level of playback
if (!FSOUND_Init(44100, 32, FSOUND_INIT_GLOBALFOCUS))
{
    //Displays error massage if pointer is invalid
    DisplayError();
}

}

void midi::PlayMidi()
{
m_pModule = NULL;
m_pModule = FMUSIC_LoadSong(MUSIC_NAME); //Load music and store in pointer

//if (!m_pModule)
//{
    //Displays error massage if pointer is invalid
//  DisplayError();
//}

//Plays the music. Music should be looped automatically
FMUSIC_PlaySong(m_pModule);
//FSOUND_STREAM *stream;
//stream = FSOUND_Stream_OpenFile(MUSIC_NAME, FSOUND_NORMAL | FSOUND_LOOP_NORMAL, 0);
//FSOUND_Stream_Play(FSOUND_FREE, stream);

}

void midi::pauseMidi()
{
//Pauses the music
// FMUSIC_SetPaused(m_pModule, TRUE); //Commented out as does not work yet
}

void midi::endMidi()
{
//FMUSIC_FreeSong(m_pModule); //Stops playback of music
FSOUND_Close(); //Turns off FMod sound system
}

void midi::DisplayError()
{
CString errorMsg;
errorMsg.Format(“Error: The following error has accured\n\n%i”, FMOD_ErrorString(FSOUND_GetError()));
MessageBox(errorMsg, “Space Invaders”, MB_ICONERROR);
exit(1); //Exit program is error occures
}
[/code]

From with in my main program file I call startSoundSystem and then PlayMidi.
In this example the line “FMUSIC_MODULE *m_pModule;” is in the header file and the program does not work as described in the last post. If I put this line “FMUSIC_MODULE *m_pModule;” into the PlayMidi (cpp file) then the program works fine and the music plays.
I need this line in the header file so that I can call the pauseMidi and the endMidi functions.

I hope this provides you with the information that you need.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.