forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

MP3 Loop, more 'attach-strings' problem

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Miki



Joined: 29 Aug 2008
Posts: 4

PostPosted: Fri Aug 29, 2008 9:08 pm    Post subject: MP3 Loop, more 'attach-strings' problem Reply with quote

Its a stupid question, i guess, but I just can't find the answer :)

Okey, i'm going to make a casino game. The problem here is sound. I want that there are 2 songs playing in a loop.

The problem in my code is where i added :// PROBLEM IS HERE!!!!!

There should be something like this :

MP3_Load("sound" AND ADD THIS VAR songtel AND ADD THIS STRING".mp3");
so the output would be : sound2.mp3, for example, but I don't know how to 'attach' them.


Code:

//Casino!
//By Miklas 'Miki' hoet
//Started on 29 Aug 2008

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspgu.h>
#include <png.h>
#include <stdio.h>
#include "graphics.h"
#include <psppower.h>
#include "mp3player.h"
#include <pspaudio.h>


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

#define printf pspDebugScreenPrintf
#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
#define RGB(r, g, b) ((r)|((g)<<8)|((b)<<16))
 
//  BEGIN BLOCK
/* 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;
}

// MAIN BLOCK

int main(){
   SetupCallbacks();
   scePowerSetClockFrequency(333,333,166);
   initGraphics();
   pspAudioInit();
   SceCtrlData pad;
   MP3_Init(1);
   MP3_Load("sound1.mp3");
   
   MP3_Play();
   int j;
   int i;
   int songs;
   int songtel;
   songtel = 1;
   songs = 2;
   int selComponent = 0;
   char filler[10];
   int bgR = 0;
   int bgG = 0;
   int bgB = 0;
   Color highlightColor = RGB(200,200,200);
   Color dimmedColor = RGB(100,100,100);
   Color shadowColorH = RGB(55,55,55);
   Color shadowColorD = RGB(55,55,55);
   //Begin loop (Button_press)
   while (0){
      // MUZIEK
      sceCtrlReadBufferPositive(&pad, 1);
      if(pad.Buttons & PSP_CTRL_CIRCLE) {
         MP3_Pause();
         for(j=0; j<10; j++) {
            sceDisplayWaitVblankStart();
         }
      }
      if (MP3_EndOfStream() == 1) {
         MP3_Stop();
         songtel++;
         if (songtel > songs){
            songtel = 1;
         }
         // PROBLEM IS HERE!!!!!
         MP3_Play();
      }
      // MUZIEK
      //sceCtrlReadBufferPositive(&pad, 1);  //in commentaar, bij muziek eerder gebruikt
      if(pad.Buttons & PSP_CTRL_UP) {
         if(selComponent > 0) {
            selComponent--;
         }
         for(i=0; i<10; i++) {
            sceDisplayWaitVblankStart();
         }
      } else if(pad.Buttons & PSP_CTRL_DOWN) {
         if(selComponent < 2) {
            selComponent++;
         }
         for(i=0; i<10; i++) {
            sceDisplayWaitVblankStart();
         }
      }
      if(pad.Buttons & PSP_CTRL_RIGHT) {
         switch(selComponent) {
            case 0:
               bgR++;
            break;
            case 1:
               bgG++;
            break;
            case 2:
               bgB++;
            break;
            default:
               //SHOULD NEVER EXECUTE
            break;
         }
      } else if(pad.Buttons & PSP_CTRL_LEFT) {
         switch(selComponent) {
            case 0:
               bgR--;
            break;
            case 1:
               bgG--;
            break;
            case 2:
               bgB--;
            break;
            default:
               //SHOULD NEVER EXECUTE
            break;
         }
      }       
      if(bgR < 0) {
         bgR = 0;
      } else if(bgR > 255) {
         bgR = 255;
      }
      if(bgG < 0) {
         bgG = 0;
      } else if(bgG > 255) {
         bgG = 255;
      }
      if(bgB < 0) {
         bgB = 0;
      } else if(bgB > 255) {
         bgB = 255;
      }
      fillScreenRect(RGB(bgR, bgG, bgB),0,0,SCREEN_WIDTH, SCREEN_HEIGHT);
      sprintf(filler, "RED: %i", bgR);
      if(selComponent == 0) {
         printTextScreen(11, 10, filler, shadowColorH);
         printTextScreen(10, 10, filler, highlightColor);
      } else {
         printTextScreen(11, 10, filler, shadowColorD);
         printTextScreen(10, 10, filler, dimmedColor);
      }               
      sprintf(filler, "GREEN: %i", bgG);
      if(selComponent == 1) {
         printTextScreen(11, 20, filler, shadowColorH);
         printTextScreen(10, 20, filler, highlightColor);
      } else {
         printTextScreen(11, 20, filler, shadowColorD);
         printTextScreen(10, 20, filler, dimmedColor);
      }
      sprintf(filler, "BLUE: %i", bgB);
      if(selComponent == 2) {
         printTextScreen(11, 30, filler, shadowColorH);
         printTextScreen(10, 30, filler, highlightColor);
      } else {
         printTextScreen(11, 30, filler, shadowColorD);
         printTextScreen(10, 30, filler, dimmedColor);
      } 
      flipScreen();
      for(i=0; i<1; i++) {
         sceDisplayWaitVblankStart();
      }
   }
   return 0;
}

// MAIN BLOCK


Thx for help :)
Back to top
View user's profile Send private message
jean



Joined: 05 Jan 2008
Posts: 489

PostPosted: Fri Aug 29, 2008 10:01 pm    Post subject: Reply with quote

not a PSP related question. Go learn basics. As this is your first post, take this as a bonus:
google for strcat, sprintf
Back to top
View user's profile Send private message
Miki



Joined: 29 Aug 2008
Posts: 4

PostPosted: Fri Aug 29, 2008 11:39 pm    Post subject: Reply with quote

I have tried that before, but it doesn't seem to work. Sorry if its in the wrong section ;)

Code:
         char toload[80];
         strcat (toload,"sound");
         strcat (toload,(char)songtel);
         strcat (toload,".mp3");
         MP3_Load(toload);


Then i get the following error :

main.c:96: let op: passing argument 2 of ‘strcat’ makes pointer from integer without a cast

edit : and running the EBOOT.PBP file on my psp results that my PSP keeps blank screen, and then goes out.
Back to top
View user's profile Send private message
kralyk



Joined: 06 Apr 2008
Posts: 114
Location: Czech Republic, central EU

PostPosted: Sat Aug 30, 2008 12:33 am    Post subject: Reply with quote

huh, try this:

Code:

char toload[80];
//or you might as well want to use char * toload = ""; for unlimited string
sprintf(toload, "sound%d.mp3", songtel);
MP3_Load(toload);


for more information:
http://www.cplusplus.com/reference/clibrary/cstdio/sprintf.html

have a look at some c/c++ reference, tutorials or books...
_________________
...sorry for my english...
Back to top
View user's profile Send private message
whistler



Joined: 04 Mar 2008
Posts: 40

PostPosted: Sat Aug 30, 2008 12:39 am    Post subject: Reply with quote

Code:
 //Begin loop (Button_press)
   while (0){
      // MUZIEK
      sceCtrlReadBufferPositive(&pad, 1);
      if(pad.Buttons & PSP_CTRL_CIRCLE) {
         MP3_Pause();
         for(j=0; j<10; j++) {
            sceDisplayWaitVblankStart();
         }
      ....


the code inside that loop will never be executed
Back to top
View user's profile Send private message
Miki



Joined: 29 Aug 2008
Posts: 4

PostPosted: Sat Aug 30, 2008 1:22 am    Post subject: Reply with quote

kralyk wrote:
huh, try this:

Code:

char toload[80];
//or you might as well want to use char * toload = ""; for unlimited string
sprintf(toload, "sound%d.mp3", songtel);
MP3_Load(toload);


for more information:
http://www.cplusplus.com/reference/clibrary/cstdio/sprintf.html

have a look at some c/c++ reference, tutorials or books...


This works, thanks :)

whistler wrote:
Code:
 //Begin loop (Button_press)
   while (0){
      // MUZIEK
      sceCtrlReadBufferPositive(&pad, 1);
      if(pad.Buttons & PSP_CTRL_CIRCLE) {
         MP3_Pause();
         for(j=0; j<10; j++) {
            sceDisplayWaitVblankStart();
         }
      ....


the code inside that loop will never be executed


Why not, and in what loop do you mean. The for loop?

the 'pauze' function works perfectly...
Back to top
View user's profile Send private message
hibbyware



Joined: 28 Mar 2007
Posts: 78

PostPosted: Sat Aug 30, 2008 2:04 am    Post subject: Reply with quote

Miki wrote:


whistler wrote:
Code:
 //Begin loop (Button_press)
   while (0){
      // MUZIEK
      sceCtrlReadBufferPositive(&pad, 1);
      if(pad.Buttons & PSP_CTRL_CIRCLE) {
         MP3_Pause();
         for(j=0; j<10; j++) {
            sceDisplayWaitVblankStart();
         }
      ....


the code inside that loop will never be executed


Why not, and in what loop do you mean. The for loop?

the 'pauze' function works perfectly...


Are you sure?

Have a quick look at http://www.cprogramming.com/reference/while.html and all should become clear,
Back to top
View user's profile Send private message
kralyk



Joined: 06 Apr 2008
Posts: 114
Location: Czech Republic, central EU

PostPosted: Sat Aug 30, 2008 2:37 am    Post subject: Reply with quote

Miki, if you dont mind this advise:
dont just put toghether pieces of code which somehow might or might not work, make sure you understand what it actually means and what it actually does. Well, you dont have to be a c/c++ expert really, but you should know what youre doing at least on a basic level...
_________________
...sorry for my english...
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Sat Aug 30, 2008 2:39 am    Post subject: Reply with quote

kralyk wrote:
huh, try this:

Code:

char toload[80];
//or you might as well want to use char * toload = ""; for unlimited string
sprintf(toload, "sound%d.mp3", songtel);
MP3_Load(toload);


Regarding the comment:
using char* toload = ""; will just make sprintf to it crash eventually.
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
Miki



Joined: 29 Aug 2008
Posts: 4

PostPosted: Sat Aug 30, 2008 2:46 am    Post subject: Reply with quote

About the while loop, you were right, it had to be a while (1) instead of (0),


I'll first go buy some book about C to learn the basics of the language.
Back to top
View user's profile Send private message
hibbyware



Joined: 28 Mar 2007
Posts: 78

PostPosted: Sat Aug 30, 2008 2:51 am    Post subject: Reply with quote

No need to go buy a book as there is plenty of free resources to learn from around the net but saying that you do get what you pay for when buying a book,
Back to top
View user's profile Send private message
kralyk



Joined: 06 Apr 2008
Posts: 114
Location: Czech Republic, central EU

PostPosted: Sat Aug 30, 2008 5:43 am    Post subject: Reply with quote

Raphael wrote:

Regarding the comment:
using char* toload = ""; will just make sprintf to it crash eventually.


Umm ... it didnt crash for me...
What do you recommend?
_________________
...sorry for my english...
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Sat Aug 30, 2008 6:38 am    Post subject: Reply with quote

Then you were just lucky you didn't overwrite important memory.
I just recommend sticking with your first solution and making sure that the string doesn't get longer than 79 chars.
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
kralyk



Joined: 06 Apr 2008
Posts: 114
Location: Czech Republic, central EU

PostPosted: Sat Aug 30, 2008 8:14 am    Post subject: Reply with quote

Ok.
Otherwise I'd have to count the length of the future string and use malloc wouldnt I?
But yes, the static solution is much better for this purpose...
_________________
...sorry for my english...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group