0
0

hi, i have a really noobish problem, and im sure im missing something, but, im having some trouble with the syntax in the basics tutorial, for playing an mp3, heres the code im using:

include <stdio.h>

include <stdlib.h>

include <iostream.h>

include <windows.h>

include <fmod.h>

include <fmod_errors.h>

include “my_song.h”

int main()
{

FSOUND_Init(44100, 32, 0);

FSOUND_STREAM * F_API FSOUND_Stream_Open(
const char *name_or_data,
unsigned int mode,
int offset,
int length
);

int F_API FSOUND_Stream_Play(
int channel,
FSOUND_STREAM *stream
);

return 0;

}

when i replace *name_or_data with *my_song.mp3, it comes up with the error ‘ syntax error before ‘.’ token ‘, when i replace it with *”my_song.mp3″, it has the error ‘ syntax error before string constant ‘, and when i try my_song without the mp3 extension, it comes up with linker and build errors, ive tried including all the directories leading up to my_song.mp3, but it results in the same errors… i think i need help lol, im wondering if i should even replace *name_or_data with anything, or if im using the wrong fmod code to play an mp3 with, any help would be much appreciated

oh yeah, forgot, im using Dev-CPP 4.9.9.1 and FMOD 3.74

  • You must to post comments
0
0

hmm… what do you do if you get no sound?, all the errors are worked out, but its as if the mp3 isnt loading, because theres no pause at all where fmod would normally be initialized, unless there arent supposed to be load times with streaming… hm… lol

//Initialise FMOD with 32 channels
if(!FSOUND_Init(44100, 32, 0))
{
return 1;
}

//Create a new sample
FSOUND_STREAM *m_stream;
m_stream = NULL;

char* m_filename = “my_song.mp3”;

//Load the sample – sound
m_stream = FSOUND_Stream_Open(m_filename, FSOUND_NORMAL | FSOUND_2D, 0, 0);

//Loop the sound
FSOUND_Stream_SetMode(m_stream, FSOUND_LOOP_NORMAL);

//Play the sound
int m_channel = FSOUND_Stream_Play(FSOUND_FREE, m_stream);

FSOUND_Close();

wait… nevermind ๐Ÿ˜€ got it worked out lol

  • You must to post comments
0
0

I dont know ur experience level but have u linked ur project with the libs for fmod? Also your code should look something like this

[code:z2zlbpuj]
int main()
{
//Initialise FMOD with 32 channels
if(!FSOUND_Init(44100, 32, 0))
{
return 1;
}

//Create a new sample
FSOUND_SAMPLE *m_sample;
m_sample = NULL;

char* m_filename = "drumloop.wav";

//Load the sample – sound
m_sample = FSOUND_Sample_Load(FSOUND_UNMANAGED, m_filename, FSOUND_NORMAL | FSOUND_2D, 0, 0);

//Loop the sound
FSOUND_Sample_SetMode(m_sample, FSOUND_LOOP_NORMAL);

//Play the sound
int m_channel = FSOUND_PlaySound(FSOUND_FREE, m_sample);

char key;
do
{
//Display the cpu usage until the escape key is pressed
key = getch();
printf("cpu %5.02f%% \r", FSOUND_GetCPUUsage());

} while (key != 27);

//Close fmod
FSOUND_Close();

return 0;

}[/code:z2zlbpuj]

  • You must to post comments
0
0

thanks :) , only been programming about a week or so lol, i feel like such an idiot ๐Ÿ˜ณ

  • You must to post comments
0
0

Perhaps try something a little easier for your first project. Like a “hello world” app? ๐Ÿ˜€

  • You must to post comments
0
0

i did get it to work though using nstaytes example, but youre right, i guess i just wanted to add some music to an rpg i was making :)

  • You must to post comments
0
0

i really appreciate all the help ive gotten, thanks guys :)

  • You must to post comments
0
0

hmm, did you mean to go from:

include <iostream.h>

include <iomanip.h>

include <math.h>

include <conio.h>

include <stdlib.h>

include <time.h>

include <string.h>

include <windows.h>

include <fstream.h>

include <fmod.h>

using namespace std;

int main()
{
//Initialise FMOD with 32 channels
if(!FSOUND_Init(44100, 32, 0))
{
return 1;
}

//Create a new sample
FSOUND_SAMPLE *m_sample;
m_sample = NULL;

char* m_filename = “drumloop.wav”;

//Load the sample – sound
m_sample = FSOUND_Sample_Load(FSOUND_UNMANAGED, m_filename, FSOUND_NORMAL | FSOUND_2D, 0, 0);

//Loop the sound
FSOUND_Sample_SetMode(m_sample, FSOUND_LOOP_NORMAL);

//Play the sound
int m_channel = FSOUND_PlaySound(FSOUND_FREE, m_sample);

char key;
do
{
//Display the cpu usage until the escape key is pressed
key = getch();
printf(“cpu %5.02f%% \r”, FSOUND_GetCPUUsage());

} while (key != 27);

//Close fmod
FSOUND_Close();

return 0;

}

to:

include <iostream.h>

include <iomanip.h>

include <math.h>

include <conio.h>

include <stdlib.h>

include <time.h>

include <string.h>

include <windows.h>

include <fstream.h>

include <fmod.h>

using namespace std;

int main()
{
//Initialise FMOD with 32 channels
if(!FSOUND_Init(44100, 32, 0))
{
return 1;
}

//Create a new sample
FSOUND_SAMPLE *m_sample;
m_sample = NULL;

char* m_filename = “drumloop.wav”;

//Load the sample – sound
m_sample = FSOUND_Stream_Open(FSOUND_UNMANAGED, m_filename, FSOUND_NORMAL | FSOUND_2D, 0, 0);

//Loop the sound
FSOUND_Sample_SetMode(m_sample, FSOUND_LOOP_NORMAL);

//Play the sound
int m_channel = FSOUND_Stream_PlaySound(FSOUND_FREE, m_sample);

char key;
do
{
//Display the cpu usage until the escape key is pressed
key = getch();
printf(“cpu %5.02f%% \r”, FSOUND_GetCPUUsage());

} while (key != 27);

//Close fmod
FSOUND_Close();

return 0;

}

this? cuz when i do, i get the errors:

Untitled1.cpp In function `int main()’:

Untitled1.cpp invalid conversion from int' toconst char*’

Untitled1.cpp invalid conversion from char*' tounsigned int’

fmod.h too many arguments to function `FSOUND_STREAM* FSOUND_Stream_Open(const char*, unsigned int, int, int)’ at this point in file

Untitled1.cpp cannot convert FSOUND_STREAM*' toFSOUND_SAMPLE*’ in assignment

Untitled1.cpp `FSOUND_Stream_PlaySound’ undeclared (first use this function)

Makefile.win [Build Error] [Untitled1.o] Error 1

๐Ÿ˜• …not entirely sure what to do, ive linked to fmod.h, fmod.dll, and to libfmod.a, and i think ive included all the headers, so im probably making at least one mistake, for sure lol

  • You must to post comments
0
0

I’m not sure you should have the using namespace line at the top. Isn’t that c#?

  • You must to post comments
0
0

i looked on google, i guess its part of both c++ and c#… dont remember why i included it though, hasnt seemed to cause any negative impact on anything… i think i might just remove it

  • You must to post comments
Showing 9 results
Your Answer

Please first to submit.