QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

Problem with Program

This is a discussion on Problem with Program within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Hi, I am making a program called Guitar PSP, which, over time, will having various tools that guitarists will find ...

Reply
 
LinkBack Thread Tools
Old 05-28-2006, 03:46 AM   #1
mEo

Developer
 
mEo's Avatar
 
Join Date: Feb 2006
Posts: 486
Trader Feedback: 0
Default Problem with Program

Hi,

I am making a program called Guitar PSP, which, over time, will having various tools that guitarists will find useful, such as a tuner (just sounds, untill we get access to a mic), tab viewer and player, mp3 player and a chord bank.

The first make will just have the tuner, cause i am new to c programming.

I am stuck however, my code doesn't work.

The code below basically plays 6 mp3s, well, it's meant to. When I run it on my 2.5, it doesn't play.

Here is my main function.
Code:
int main() {
	pspDebugScreenInit();
	SetupCallbacks();
	pspAudioInit();
	SceCtrlData pad;
	int i;
	int num = 0;
	int prevNum = 0;
	char note[10];
	printf("Welcome to Guitar PSP!\n\n");
	printf("Press [X] to tune the next note\n");
	printf("Press [O] to tune the previous note\n!");
	while(1) {
		sceCtrlReadBufferPositive(&pad, 1);
		if(pad.Buttons & PSP_CTRL_CROSS) {
			num++;
		} else if(pad.Buttons & PSP_CTRL_CIRCLE) {
			num--;
		}

		if(num<1) {
			num = 0;
		} else if(num>6) {
			num = 6;
		}
		if(prevNum!=num) {
			prevNum=num;
			MP3_Stop();
			MP3_FreeTune();
			MP3_Init(1);
			switch(num) {
				case 1:
					MP3_Load("be.mp3");
				case 2:
					MP3_Load("a.mp3");
				case 3:
					MP3_Load("d.mp3");
				case 4:
					MP3_Load("g.mp3");
				case 5:
					MP3_Load("b.mp3");
				case 6:
					MP3_Load("b.mp3");
			}
			MP3_Play();
		}
		for(i=0; i<10; i++) {
			sceDisplayWaitVblankStart();
		}
	}
	sceKernelSleepThread();
	return 0;
}
Can anyone see something I've done wrong?
__________________
[mEo!]
My Apps: Slider PSP | Slime Volleyball PSP | PSP TV Setup Helper
Guides: Stream TV to your PSP
Firmware: 2.5 - 1.5 :D - 1.5 Casual 3 - 2.0 (Thank god for recovery mode) - 1.5 - 1.5 Casual 3 - 2.71 SE-A (Wooohooo!) - 3.03 OE - 3.10 OE - 3.30 OE - 3.40 OE-A - 3.51 M33
UMD Games: GTA: Liberty City Stories, SSX On Tour, FIFA World Cup 2006, GTA: Vice City Stories
UMD Movies: Speed
Looking Forward To: Full Speed Daedalus, FF Tactics PSP
mEo is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2006, 03:56 AM   #2

Developer
 
kozine's Avatar
 
Join Date: Mar 2006
Location: Isle of Wight
Posts: 491
Trader Feedback: 0
Default

Just wondering but have you read this lesson?

http://www.psp-programming.com/tutorials/c/lesson06.htm

Thats about adding/playing sound.
__________________


PM me for a sig like this!

http://dspspforums.com/forums/index.php SIGN UP NOW!
kozine is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2006, 04:01 AM   #3
mEo

Developer
 
mEo's Avatar
 
Join Date: Feb 2006
Posts: 486
Trader Feedback: 0
Default

Yes, that is where I have been learning from. I don't see anything I missed in that tutorial
__________________
[mEo!]
My Apps: Slider PSP | Slime Volleyball PSP | PSP TV Setup Helper
Guides: Stream TV to your PSP
Firmware: 2.5 - 1.5 :D - 1.5 Casual 3 - 2.0 (Thank god for recovery mode) - 1.5 - 1.5 Casual 3 - 2.71 SE-A (Wooohooo!) - 3.03 OE - 3.10 OE - 3.30 OE - 3.40 OE-A - 3.51 M33
UMD Games: GTA: Liberty City Stories, SSX On Tour, FIFA World Cup 2006, GTA: Vice City Stories
UMD Movies: Speed
Looking Forward To: Full Speed Daedalus, FF Tactics PSP
mEo is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2006, 04:18 AM   #4

PSP Coder
 
Join Date: Jul 2005
Location: Scotland
Posts: 13
Trader Feedback: 0
Default

Code:
if(prevNum!=num) {
			prevNum=num;
			MP3_Stop();
			MP3_FreeTune();
			MP3_Init(1);
			switch(num) {
				case 1:
					MP3_Load("be.mp3");
				case 2:
					MP3_Load("a.mp3");
				case 3:
					MP3_Load("d.mp3");
				case 4:
					MP3_Load("g.mp3");
				case 5:
					MP3_Load("b.mp3");
				case 6:
					MP3_Load("b.mp3");
			}
			MP3_Play();
		}
Inside the 'if' loop you are setting prevnum=num, so the next time it loops round the condition 'if prevnum!=num' is going to be false, hence it will not enter the section of code again.

Also with switch / case selection, you normally need a break; statement inside the 'cases'. ie:

Code:
switch (num)
{
     case 1:
      {
            MP3_Load("be.mp3");
            break;
      }
      case 2:
      .
      .
      .
} //end switch
antiroC is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2006, 04:32 AM   #5
mEo

Developer
 
mEo's Avatar
 
Join Date: Feb 2006
Posts: 486
Trader Feedback: 0
Default

I agree about the switch statement, thanks i'll add that and see what happens.

but the if statement, if you look above that, when [X] or [O] are pressed, num changes. prevnum is the previous number, number always is re-assigned. if the new number does not equal the old one, then a button must have been pressed. load the appropriate mp3.... etc. etc.
__________________
[mEo!]
My Apps: Slider PSP | Slime Volleyball PSP | PSP TV Setup Helper
Guides: Stream TV to your PSP
Firmware: 2.5 - 1.5 :D - 1.5 Casual 3 - 2.0 (Thank god for recovery mode) - 1.5 - 1.5 Casual 3 - 2.71 SE-A (Wooohooo!) - 3.03 OE - 3.10 OE - 3.30 OE - 3.40 OE-A - 3.51 M33
UMD Games: GTA: Liberty City Stories, SSX On Tour, FIFA World Cup 2006, GTA: Vice City Stories
UMD Movies: Speed
Looking Forward To: Full Speed Daedalus, FF Tactics PSP
mEo is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2006, 05:53 AM   #6

Developer
 
Join Date: Mar 2006
Posts: 1,026
Trader Feedback: 0
Default

Just a small thing before I look at it properly:

case 6:
MP3_Load("b.mp3");

Should be:

case 6:
MP3_Load("e.mp3");
Insert_Witty_Name is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2006, 06:33 AM   #7

Developer
 
Join Date: Mar 2006
Posts: 1,026
Trader Feedback: 0
Default

Here you go mate, this has some issues, but I'll post what I have now as I have to leave for a while.

Code:
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include <psppower.h>
#include "mp3player.h"

#define printf pspDebugScreenPrintf

PSP_MODULE_INFO("GuitarPSP", 0, 1, 1);

/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
          sceKernelExitGame();
          return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
          int cbid;

          cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
          sceKernelRegisterExitCallback(cbid);

          sceKernelSleepThreadCB();

          return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
          int thid = 0;

          thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
          if(thid >= 0) {
                    sceKernelStartThread(thid, 0, 0);
          }

          return thid;
}

int i;
int num = 0;
int prevNum = 0;
char note[10];

void PlayMP3()
{
 if(num < 1) {
	num = 0;
	} else if(num > 6) {
	num = 6;
	}
	if(prevNum!=num) {
	prevNum=num;
	MP3_Stop();
	MP3_FreeTune();

	switch(num) {
	case 1:
	MP3_Load("be.mp3");
	case 2:
	MP3_Load("a.mp3");
	case 3:
	MP3_Load("d.mp3");
	case 4:
	MP3_Load("g.mp3");
	case 5:
	MP3_Load("b.mp3");
	case 6:
	MP3_Load("e.mp3");
	}
	MP3_Play();
	}
}

int main() {
	pspDebugScreenInit();
	SetupCallbacks();
	pspAudioInit();
        MP3_Init(1);
	SceCtrlData pad, lastpad;
	printf("Welcome to Guitar PSP!\n\n");
	printf("Press [X] to tune the next note\n");
	printf("Press [O] to tune the previous note\n!");
	sceCtrlReadBufferPositive(&lastpad, 1);

        while(1) {
		sceCtrlReadBufferPositive  (&pad, 1);
	        if(pad.Buttons != lastpad.Buttons) {
                         lastpad = pad;
		if(pad.Buttons & PSP_CTRL_CROSS) {
			num++;
			PlayMP3();
		} else if(pad.Buttons & PSP_CTRL_CIRCLE) {
			num--;
			PlayMP3();
		}
		}
		}

	sceKernelSleepThread();
	return 0;
}
Watch out for the forum spacing on some of the words!

Hope this helps get you started.

Last edited by Insomniac197; 05-28-2006 at 06:36 AM..
Insert_Witty_Name is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2006, 04:03 PM   #8
mEo

Developer
 
mEo's Avatar
 
Join Date: Feb 2006
Posts: 486
Trader Feedback: 0
Default

I will try this in the afternoon, thanks a lot for your help
__________________
[mEo!]
My Apps: Slider PSP | Slime Volleyball PSP | PSP TV Setup Helper
Guides: Stream TV to your PSP
Firmware: 2.5 - 1.5 :D - 1.5 Casual 3 - 2.0 (Thank god for recovery mode) - 1.5 - 1.5 Casual 3 - 2.71 SE-A (Wooohooo!) - 3.03 OE - 3.10 OE - 3.30 OE - 3.40 OE-A - 3.51 M33
UMD Games: GTA: Liberty City Stories, SSX On Tour, FIFA World Cup 2006, GTA: Vice City Stories
UMD Movies: Speed
Looking Forward To: Full Speed Daedalus, FF Tactics PSP
mEo is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-28-2006, 05:39 PM   #9

Developer
 
Join Date: Mar 2006
Posts: 1,026
Trader Feedback: 0
Default

Like I said, this still has issues - I must admit I'm not up on using MP3 in C.

If I get chance later on I'll look through it if you can't correct the remaining issues yourself.
Insert_Witty_Name is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-29-2006, 02:09 AM   #10
mEo

Developer
 
mEo's Avatar
 
Join Date: Feb 2006
Posts: 486
Trader Feedback: 0
Default

i tried a direct example from that site (www.psp-programming.com), i literally cut and paste. it doesn't work, crashes if i let it go to long. anyone konw why?
__________________
[mEo!]
My Apps: Slider PSP | Slime Volleyball PSP | PSP TV Setup Helper
Guides: Stream TV to your PSP
Firmware: 2.5 - 1.5 :D - 1.5 Casual 3 - 2.0 (Thank god for recovery mode) - 1.5 - 1.5 Casual 3 - 2.71 SE-A (Wooohooo!) - 3.03 OE - 3.10 OE - 3.30 OE - 3.40 OE-A - 3.51 M33
UMD Games: GTA: Liberty City Stories, SSX On Tour, FIFA World Cup 2006, GTA: Vice City Stories
UMD Movies: Speed
Looking Forward To: Full Speed Daedalus, FF Tactics PSP
mEo is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
problem , program

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 10:45 PM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us