Finally Got Around To Programming Again....


deadlychicken22

Man is a reasoning rather than a reasonable animal
Joined
Mar 18, 2004
Messages
1,501
Location
MN, USA
Website
Visit site
I finally got some free time and decided to try programming for the gp2x again. I downloaded the official gp2xsdk with devcpp. I loaded up my old game, extraterrestres, and have been trying to get it to run. About a year ago when I made the game, it worked fine on firmware 1.4 (although I was compiling with different libs) but wouldn't work on 2.0. So now I got the official stuff and was hoping I could get it to work on the new firmwares.
It will compile fine, but it freezes on this line when I test it on my gp2x:
Code:
Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 1, 512 );
I admit I'm not much of a coder, so it is probably something stupid. Any idea what I'm doing wrong here? (I'm running on firmware 2.0)
 
You are probably calling it too early or too late or something like that, SDL can be like that.

Get Guyfawkes SDL demo code and look at that, its nice.
 
Make sure you are using the latest libs and statically linking.

The standard dev kit with DEVC++ does dynamic linking as default.

Been there myself with the audio probs.
 
I am statically linking.

I looked at the SDL demo program and couldn't see anything very different from what I'm doing... I'm going to go play around with it a little and see what I can do. For now, here is some of my code, let me know if anything sticks out.

the beginning of main:
Code:
int main(int argc, char* args[] ) 
{
	printf("Testing serial usb cable connection.....");
	//Initialize all SDL sub systems 
	if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { return 1; }
	
	SDL_Init(SDL_INIT_AUDIO);
	//Setup the screen
	screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
	SDL_ShowCursor(SDL_DISABLE);
	SDL_JoystickOpen(0);
	  
	//initialize SDL_ttf
	TTF_Init();
	
	//initialize SDL_mixer
	Mix_OpenAudio(44100, AUDIO_S16, MIX_DEFAULT_CHANNELS, 512);
	
	//load fonts
	evanescent = TTF_OpenFont( "evanescent.ttf", textSize );
	evanescent_large = TTF_OpenFont ("evanescent.ttf", 60);
	evanescent_small = TTF_OpenFont ("evanescent.ttf", 28);

	  
	//load sound effects
	get_item_sound = Mix_LoadWAV( "get_item.wav" );
	use_item_sound = Mix_LoadWAV( "use_item.wav" );
	win_sound = Mix_LoadWAV( "win.wav" );
	death_sound = Mix_LoadWAV( "death.wav" );
includes:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <cmath>
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <SDL_mixer.h>
linker:
Code:
-lSDLmain -lSDL -static -lSDL_mixer -lSDL_ttf -lSDL_image -lvorbisidec -lfreetype -ljpeg -lpng12 -lz -lm -lSDL -lpthread -lmad

EDIT: Where can I get the latest libs?
 
Only diff I can see in my code is

Code:
// to init 
Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, AUDIO_S16, MIX_DEFAULT_CHANNELS, 256);			

// then to play

sound = Mix_LoadWAV("./data/sound.wav");					
// load sound.wav from sdcard
channel = Mix_PlayChannel(-1, sound, 0);						
// Play the sound and capture the channel on which it is played
while(Mix_Playing(channel) != 0);						
// Wait until the sound has stopped playing
	
Mix_FreeChunk(sound);

Latest libs here http://archive.gp2x.de/cgi-bin/cfiles.cgi?0,0,0,0,19,1875
 
Found a topic about the same problem here (it's about a year old...)

Anyways, I'm going to download those libs and try them out. I'll let you know how it goes.

EDIT: I tried it with the new libs and had the exact same result. No problems compiling, but it freezes when it reaches that line of code. If I remove that line, it runs fine, but with no sound.
 
Last edited by a moderator:
Have you tried .ogg or .mp3 files?

Needs a bit of a code change

Code:
music = Mix_LoadMUS("./data/music.ogg");						
// Load music.mp3 from sdcard
Mix_PlayMusic(music, 1);							
// Play the music
 
Have you tried .ogg or .mp3 files?

Needs a bit of a code change

Code:
music = Mix_LoadMUS("./data/music.ogg");						
// Load music.mp3 from sdcard
Mix_PlayMusic(music, 1);							
// Play the music
No I haven't tried .ogg or .mp3 as the loading of the sound file is not the problem. It is the initializing of sdl_mixer that is causing the freezing.
 
Last edited by a moderator:

Well I saw the file was a wav from the code but wav is just a wrapper and it can be lots of different formats that can be in a wav file. I guess if the underlying code supports all of the possible formats you are ok. I ran into wav files that have an older wav header and newer version of wav processing code had an issue with them.
 
Last edited by a moderator:

Well I saw the file was a wav from the code but wav is just a wrapper and it can be lots of different formats that can be in a wav file. I guess if the underlying code supports all of the possible formats you are ok. I ran into wav files that have an older wav header and newer version of wav processing code had an issue with them.
PCM, I believe. However, as I said above, it is the initializing of sdl_mixer and not the loading of the files that is freezing. I have tried commenting the code for the loading of the sound and it still freezes. However, when I comment the code for the initialization of sdl_mixer, it doesn't freeze.
 
Last edited by a moderator:
Are you 100% sure that it is that exact line or is it when you load/play the files?
 
Are you 100% sure that it is that exact line or is it when you load/play the files?
I guess I'm not 100% sure but based on the tests I've done it is that line. Here's what I've done:

Code:
int main(int argc, char* args[] ) 
{
	printf("Testing serial usb cable connection.....");
	//Initialize all SDL sub systems 
	if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { return 1; }
	
	SDL_Init(SDL_INIT_AUDIO);
	//Setup the screen
	screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
	SDL_ShowCursor(SDL_DISABLE);
	SDL_JoystickOpen(0);
	  
	//initialize SDL_ttf
	TTF_Init();
	
	//initialize SDL_mixer
	Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, AUDIO_S16, MIX_DEFAULT_CHANNELS, 512);
	
	//load fonts
	evanescent = TTF_OpenFont( "evanescent.ttf", textSize );
	evanescent_large = TTF_OpenFont ("evanescent.ttf", 60);
	evanescent_small = TTF_OpenFont ("evanescent.ttf", 28);

	
	//load sound effects
	/*
	get_item_sound = Mix_LoadWAV( "get_item.wav" );
	use_item_sound = Mix_LoadWAV( "use_item.wav" );
	win_sound = Mix_LoadWAV( "win.wav" );
	death_sound = Mix_LoadWAV( "death.wav" );
	*/
	//sound is on
	sound_state = 1;
	atexit(SDL_Quit);
	//setup everything here!
	SDL_Event event;
	int buttonPress=0;
	 
	
	//competition screen
	text = TTF_RenderText_Solid(evanescent, "Loading...", textColor);
	story_image = load_image("competition.png");
	  while(buttonPress==0)
	  {
		DrawIMG(story_image, screen, 0, 0);
		SDL_Flip(screen);
	   while(SDL_PollEvent(&event))
	   {
		switch(event.type)
		{
		 case SDL_JOYBUTTONDOWN:
			  DrawIMG(story_image, screen, 0, 0);
			  DrawIMG(text, screen, 90, 90);
			  SDL_Flip(screen);						 
			  buttonPress=1;
			  break;
		 }
		}
	  }
When run, this just comes up with a blank screen. All loading of sound files has been commented out before the first screen, so it should at least reach that screen if the loading of the files is the cause of the problem.

Code:
int main(int argc, char* args[] ) 
{
	printf("Testing serial usb cable connection.....");
	//Initialize all SDL sub systems 
	if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { return 1; }
	
	SDL_Init(SDL_INIT_AUDIO);
	//Setup the screen
	screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
	SDL_ShowCursor(SDL_DISABLE);
	SDL_JoystickOpen(0);
	  
	//initialize SDL_ttf
	TTF_Init();
	
	//initialize SDL_mixer
	//Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, AUDIO_S16, MIX_DEFAULT_CHANNELS, 512);
	
	//load fonts
	evanescent = TTF_OpenFont( "evanescent.ttf", textSize );
	evanescent_large = TTF_OpenFont ("evanescent.ttf", 60);
	evanescent_small = TTF_OpenFont ("evanescent.ttf", 28);

	  
	//load sound effects
	get_item_sound = Mix_LoadWAV( "get_item.wav" );
	use_item_sound = Mix_LoadWAV( "use_item.wav" );
	win_sound = Mix_LoadWAV( "win.wav" );
	death_sound = Mix_LoadWAV( "death.wav" );
	
	//sound is on
	sound_state = 1;
	atexit(SDL_Quit);
	//setup everything here!
	SDL_Event event;
	int buttonPress=0;
	 
	
	//competition screen
	text = TTF_RenderText_Solid(evanescent, "Loading...", textColor);
	story_image = load_image("competition.png");
	  while(buttonPress==0)
	  {
		DrawIMG(story_image, screen, 0, 0);
		SDL_Flip(screen);
	   while(SDL_PollEvent(&event))
	   {
		switch(event.type)
		{
		 case SDL_JOYBUTTONDOWN:
			  DrawIMG(story_image, screen, 0, 0);
			  DrawIMG(text, screen, 90, 90);
			  SDL_Flip(screen);						 
			  buttonPress=1;
			  break;
		 }
		}
	  }
When I run this code, it loads fine but with no sound as I commented out the initialization of sdl_mixer.

Blah: If this is a known issue, what is the solution?
 
Last edited by a moderator:
Back
Top