Advertisement

FMOD newbie - problems with playing song

Started by March 13, 2003 01:19 PM
3 comments, last by dEpression 21 years, 8 months ago
I'm new to FMOD so I'd appreciate it if anyone a bit more experienced can figure out what's wrong with this code:
  
#include <fmod.h>
#include <iostream.h>

int main (int argc, const char* argv[])
{
	const char* ohjeet = "Usage: faggot filename";
	if (argc > 1) {
	FMUSIC_MODULE *song;
	if (!FSOUND_Init(44100, 32, 0)) { cout<<"Error: Initialization failed"<<endl; return 0; }
	song = FMUSIC_LoadSong(argv[1]);
	if (!song) { cout<<"Error: Bad filename"<<endl; return 0; }
	if (!FMUSIC_PlaySong(song)) {cout<<"Error: Bad karma"<<endl; return 0; }
	FMUSIC_FreeSong(song); }
	else cout<<ohjeet;
	return 0;
}
   
When I compile and run it, it pauses for a while and then just exits. No errors are printed but no song, either. [edited by - dEpression on March 13, 2003 2:21:23 PM]
You should perhaps wait some time after starting playing the song. Otherwise nothing prevent the program from exiting.
Advertisement
Well _that_ was stupid of me. I somehow assumed PlaySong wouldn''t return before the song was over :/

Thanks a lot. I really should have tried that.

With that out of the way, how''s the overall correctness of the code? One thing that I''ve been wondering about: do I need to manually free the memory I allocate for dynamic character arrays, such as const char* ohjeet in the above code?
quote: Original post by dEpression
With that out of the way, how''s the overall correctness of the code?


The code seems correct to me, though badly indented, but I suppose it doesn''t look like this outside of the forum.

quote:
One thing that I''ve been wondering about: do I need to manually free the memory I allocate for dynamic character arrays, such as const char* ohjeet in the above code?


Actually, you didn''t allocate them in your program. When you put constant strings in your code, the linker put them in the data segment of the executable. The OS takes care of the allocation when it executes the program and free them when the program exits. So, you don''t have to do anything for it.
Cool, thanks again. That''s one less thing to worry about.

This topic is closed to new replies.

Advertisement