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 

Error compiling OGG Sample

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



Joined: 24 Feb 2008
Posts: 31

PostPosted: Sat May 03, 2008 8:59 am    Post subject: Error compiling OGG Sample Reply with quote

I have done a program based on the LiGht MP3 that simply reproduces OGG, but it gives some mistakes to compile. Here the code of the MAIN is:

Code:

#include <pspkernel.h>
#include <pspctrl.h>
#include <psphprm.h>
#include <pspdebug.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include <psppower.h>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <pspsdk.h>

#include "opendir.h"
#include "id3.h"
#include "oggplayer.h"
#include "pspaudiolib.h"
#include "player.h"

//Colori:
#define RGB(r, g, b) ((b << 16) | (g << 8) | r)
#define YELLOW RGB(255, 2550, 0)
#define BLACK RGB(0, 0, 0)
#define WHITE RGB(255, 255, 255)
#define RED RGB(255, 0, 0)
#define DEEPSKYBLUE RGB(0, 178, 238)

;
PSP_MODULE_INFO("OGG Sample", 0, 1, 0);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
PSP_HEAP_SIZE_KB(21000);

#define mp3_directory_1 "ms0:/MUSIC"
#define mp3_directory_2 "ms0:/PSP/MUSIC"

/*void sceDisplay_driver_9E3C6DC6(int a0,int a1);//a0 0-100,a1 = 0/1 (set to 0)
#define sceDisplaySetBrightness sceDisplay_driver_9E3C6DC6
void sceDisplay_driver_31C4BAA8(int *a0,int *a1);
#define sceDisplayGetBrightness sceDisplay_driver_31C4BAA8*/

char version[10] = "1.0.0";
int oldBrightness = 0;

// TWILIGHT ZONE!
/* 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;
}
// END OF TWILIGHT ZONE!

//Memoria libera totale:
typedef struct
{
      void *buffer;
      void *next;
} _LINK;

int freemem()
{
   int size = 4096, total = 0;
    _LINK *first = NULL, *current = NULL, *lnk;

    while (1)
    {
       lnk = (_LINK*)malloc(sizeof(_LINK));
       if (!lnk)
          break;

       total += sizeof(_LINK);

       lnk->buffer = malloc(size);
       if (!lnk->buffer)
       {
          free(lnk);
          break;
       }

       total += size;
       lnk->next = NULL;

       if (current)
       {
          current->next = (void*)lnk;
          current = lnk;
       }
       else
       {
          current = first = lnk;
       }
    }

    lnk = first;
    while (lnk)
    {
       free(lnk->buffer);
       current = lnk->next;
       free(lnk);
       lnk = current;
    }

    return total;
}

//Ordinamento dei file di una directory:
void sortDirectory(struct opendir_struct directory)
{
   int n = directory.number_of_directory_entries;
   int i = 0;
   
   while (i < n) {
      if (i == 0 || strcmp(directory.directory_entry[i-1].d_name, directory.directory_entry[i].d_name) <= 0) i++;
      else {SceIoDirent tmp = directory.directory_entry[i]; directory.directory_entry[i] = directory.directory_entry[i-1]; directory.directory_entry[--i] = tmp;}
   }
}

//Prendo solo il nome del file:
void getFileName(char *fileName, char *onlyName){
   int slash = -1;
   int retCount;

   strcpy(onlyName, fileName);
   //Cerco l'ultimo slash:
   int i = 0;
   for (i = strlen(fileName) - 1; i >= 0; i--){
      if ((fileName[i] == '/') & (i != strlen(fileName))){
         slash = i;
         break;
      }
   }
   if (slash){
      retCount = 0;
      for (i = slash + 1; i < strlen(fileName); i++){
         onlyName[retCount] = fileName[i];
         retCount++;
      }
      onlyName[retCount] = '\0';
   }
}

//Calcolo livello superiore:
void directoryUp(char *dirName)
{
   if (dirName != "ms0:/"){
      //Cerco l'ultimo slash:
      int i = 0;
      for (i = strlen(dirName) - 1; i >= 0; i--){
         if ((dirName[i] == '/') & (i != strlen(dirName))){
            if (i > 4){
               dirName[i] = '\0';
            }else{
               dirName[i+1] = '\0';
            }
            break;
         }
      }
   }
   return;
}

//Spezzo autore e titolo nel nome di una directory:
void rtrim(char *toTrim)
{
   int i = 0;
   for (i = strlen(toTrim) - 1; i >= 0; i--){
      if (isspace(toTrim[i])){
         toTrim[i] = '\0';
      }else{
         break;
      }
   }
}

int splitAuthorTitle(char *dirName, char *author, char *title)
{
   if (strstr(dirName, "-") != 0){
      int i = 0;
      int posSep = -1;
      int countAuthor = 0;
      int countTitle = 0;

      for (i = 0; i < strlen(dirName); i++){
         if (dirName[i] == '-'){
            posSep = i;
         }
         else if (posSep == -1){
            if ((countAuthor != 0) | (dirName[i] != ' ')){
               author[countAuthor] = dirName[i];
               countAuthor++;
            }
         }else{
            if ((countTitle != 0) | (dirName[i] != ' ')){
               title[countTitle] = dirName[i];
               countTitle++;
            }
         }
         author[countAuthor] = '\0';
         title[countTitle] = '\0';
      }
      rtrim(author);
      rtrim(title);
      return(1);
   }
   return(0);
}

//Costruisco la barra della percentuale:
void buildProgressBar(char *pBar, int percentage){
   int i;

   pBar[0] = '[';
   for (i = 1; i < 22; i++){
      if (percentage >= (i-1) * 5){
         pBar[i] = '*';
      }else{
         pBar[i] = ' ';
      }
   }
   pBar[21] = ']';
   pBar[22] = '\0';
}

// Inizializzazione schermo:
void screen_sysinfo()
{
pspDebugScreenSetTextColor(0xeeff00);
   printf("¡OGG SAMPLE");
   
   if (scePowerIsBatteryExist()) {
      int batteryLifeTime = scePowerGetBatteryLifeTime();
      printf("\n   Battery: %d%%  (%02dh%02dm)", scePowerGetBatteryLifePercent(), batteryLifeTime/60, batteryLifeTime-(batteryLifeTime/60*60));
}
}

void screen_init()
   {
   
      
   if (scePowerIsBatteryExist()) {
      int batteryLifeTime = scePowerGetBatteryLifeTime();
      printf("\n   Battery: %d%%  (%02dh%02dm)", scePowerGetBatteryLifePercent(), batteryLifeTime/60, batteryLifeTime-(batteryLifeTime/60*60));

   pspDebugScreenSetTextColor(WHITE);
   pspDebugScreenSetBackColor(BLACK);
   pspDebugScreenInit();
   pspDebugScreenSetTextColor(WHITE);
   pspDebugScreenSetBackColor(BLACK);
   pspDebugScreenSetXY(0, 1);
   pspDebugScreenPrintf("OGG SAMPLE");
   pspDebugScreenSetXY(0, 33);
}
}


//Schermo per menu
void screen_menu_init()
{
   pspDebugScreenSetTextColor(WHITE);
   pspDebugScreenSetXY(0, 27);
   pspDebugScreenPrintf("Press X to enter directory/play file");
   pspDebugScreenPrintf("\n");
   pspDebugScreenPrintf("Press SQUARE to play directory");
   pspDebugScreenPrintf("\n");
   pspDebugScreenPrintf("Press O to go up one level");
   pspDebugScreenPrintf("\n");
   pspDebugScreenPrintf("Press TRIANGLE to exit");
}

//Schermo per player
void screen_player_init(char *filename, struct ID3Tag ID3, int nextPrevious, char *numbers)
{
   char file[256];
   pspDebugScreenSetTextColor(WHITE);
   pspDebugScreenSetBackColor(BLACK);
   if (nextPrevious == 1){
       pspDebugScreenSetXY(0, 7);
      pspDebugScreenPrintf("File Number: %s", numbers);
   }
    pspDebugScreenSetXY(0, 8);
   getFileName(filename, file);
   pspDebugScreenPrintf("File Name  : %s", file);
   pspDebugScreenPrintf("\n");
   pspDebugScreenPrintf("Time       :");
   pspDebugScreenSetTextColor(YELLOW);
    pspDebugScreenSetXY(0, 11);
    pspDebugScreenPrintf("Album      : %s", ID3.ID3Album);
   pspDebugScreenPrintf("\n");
   pspDebugScreenPrintf("Title      : %s", ID3.ID3Title);
   pspDebugScreenPrintf("\n");
    pspDebugScreenPrintf("Artist     : %s", ID3.ID3Artist);
   pspDebugScreenPrintf("\n");
    pspDebugScreenPrintf("Year       : %s", ID3.ID3Year);
   pspDebugScreenPrintf("\n");
   pspDebugScreenPrintf("Genre      : %s", ID3.ID3GenreText);

   pspDebugScreenSetTextColor(DEEPSKYBLUE);
   pspDebugScreenSetXY(0, 16);
    pspDebugScreenPrintf("Layer      :");
   pspDebugScreenPrintf("\n");
    pspDebugScreenPrintf("Bitrate    :");
   pspDebugScreenPrintf("\n");
    pspDebugScreenPrintf("Sample rate:");
   pspDebugScreenPrintf("\n");
    pspDebugScreenPrintf("Mode       :");
   pspDebugScreenPrintf("\n");
    pspDebugScreenPrintf("Emphasis   :");

   pspDebugScreenSetTextColor(WHITE);
   pspDebugScreenSetXY(0, 27);
   pspDebugScreenPrintf("Press X to pause");
   pspDebugScreenPrintf("\n");
   pspDebugScreenPrintf("Press O to stop");
   if (nextPrevious == 1)
   {
      pspDebugScreenPrintf("\n");
      pspDebugScreenPrintf("Press L/R to change song");
   }
   pspDebugScreenPrintf("\n");
   pspDebugScreenPrintf("Press UP/DOWN to change cpu clock");
   pspDebugScreenPrintf("\n");
   pspDebugScreenPrintf("Press LEFT/RIGHT to change bus clock");
   pspDebugScreenPrintf("\n");
   pspDebugScreenPrintf("Press SELECT toggle mute");
}

void screen_fileinfo(struct fileInfo info){
    pspDebugScreenSetXY(0, 16);
   pspDebugScreenSetTextColor(DEEPSKYBLUE);
    pspDebugScreenPrintf("Layer      : %s", info.layer);
   pspDebugScreenPrintf("\n");
    pspDebugScreenPrintf("Bitrate    : %i [%3.3i] kbit", info.kbit, info.kbit);
   pspDebugScreenPrintf("\n");
    pspDebugScreenPrintf("Sample rate: %li Hz", info.hz);
   pspDebugScreenPrintf("\n");
    pspDebugScreenPrintf("Mode       : %s", info.mode);
   pspDebugScreenPrintf("\n");
    pspDebugScreenPrintf("Emphasis   : %s", info.emphasis);
}

   

//Play OGG file:
int play(char *filename, int nextPrevious, char *numbers)

 {
 
     /* Play a single file.
       Returns 1 if user pressed NEXT
             0 if song ended
            -1 if user pressed PREVIOUS
             2 if user pressed STOP
     */
     u32 remoteButtons;
     int retVal = 0;
     SceCtrlData pad;
     int clock;
     int bus;
     struct fileInfo info;
     int action = 0; //-1=pause 0=stop 1=playing
     char timestring[20];
     int updateInfo = 0;
     struct ID3Tag ID3;
    
     int brightness = 0;
     char pBar[22];
     int muted = 0;

info.kbit = 0;
     info.hz = 0;
    
      
     clock = scePowerGetCpuClockFrequency();
     bus = scePowerGetBusClockFrequency();
     //Leggo le informazioni ID3:
     ID3 = ParseID3(filename);

     screen_init();
     screen_player_init(filename, ID3, nextPrevious, numbers);

      OGG_Init(1);
        
     pspAudioSetVolume(1, 0x8000, 0x8000);
     pspDebugScreenSetXY(0, 21);
     pspDebugScreenPrintf("Opening...");
     //Apro il file:
     OGG_Load(filename);
     screen_fileinfo(info);
         
      OGG_Play();
    
     action = 1;

     while(1){
          //Aggiorno info a video:
         if (updateInfo == 0){
            screen_sysinfo();
            OGG_GetTimeString(timestring);
            pspDebugScreenSetTextColor(WHITE);
            pspDebugScreenSetBackColor(BLACK);
            pspDebugScreenSetXY(0, 9);
                        pspDebugScreenPrintf("Time       : %s / %s", timestring, info.strLength);
            buildProgressBar(pBar, OGG_GetPercentace());
            pspDebugScreenSetXY(13, 10);
            pspDebugScreenPrintf(pBar);
            //Testo dell'azione corrente:
            pspDebugScreenSetXY(0, 21);
            if (action == 1){
               pspDebugScreenPrintf("Playing...");
            }else if (action == -1){
               pspDebugScreenPrintf("Paused    ");
            }
            //Testo mute:
            pspDebugScreenSetXY(0, 22);
            if (muted == 1){
               pspDebugScreenSetTextColor(RED);
               pspDebugScreenPrintf("Mute ON");
            } else {
               pspDebugScreenPrintf("       ");
            }
         }
         updateInfo++;
         if (updateInfo == 10){
            updateInfo = 0;
         }
         sceCtrlReadBufferPositive(&pad, 1);
         sceHprmPeekCurrentKey(&remoteButtons);

         if(pad.Buttons & PSP_CTRL_CIRCLE) {
                 OGG_End();
                
                 action = 0;
                 retVal = 2;
                 break;
         } else if((pad.Buttons & PSP_CTRL_CROSS) | (remoteButtons & PSP_HPRM_PLAYPAUSE)) {
                 OGG_Pause();
                
                 if (action != -1){
                  action = -1;
                 }else{
                  action = 1;
                 }
                 updateInfo = 0;
                 sceKernelDelayThread(400000);
         } else if((pad.Buttons & PSP_CTRL_DOWN) | (pad.Ly > 158)) {
            if (clock > 33){
               clock--;
               scePowerSetCpuClockFrequency(clock);
               screen_sysinfo();
               sceKernelDelayThread(100000);
            }
         } else if((pad.Buttons & PSP_CTRL_UP) | (pad.Ly < 98)) {
            if (clock < 333){
               clock++;
               scePowerSetCpuClockFrequency(clock);
               screen_sysinfo();
               sceKernelDelayThread(100000);
            }
         } else if((pad.Buttons & PSP_CTRL_LEFT) | (pad.Lx < 98)) {
            if (bus > 54){
               bus--;
               scePowerSetBusClockFrequency(bus);
               screen_sysinfo();
               sceKernelDelayThread(100000);
            }
         } else if((pad.Buttons & PSP_CTRL_RIGHT) | (pad.Lx > 158)) {
            if (clock < 166){
               bus++;
               scePowerSetBusClockFrequency(bus);
               screen_sysinfo();
               sceKernelDelayThread(100000);
            }
         } else if(pad.Buttons & PSP_CTRL_LTRIGGER || remoteButtons & PSP_HPRM_BACK) {
            if (nextPrevious == 1){
               OGG_End();
               retVal = -1;
               break;
            }
      
            
         } else if(pad.Buttons & PSP_CTRL_RTRIGGER || remoteButtons & PSP_HPRM_FORWARD) {
            if (nextPrevious == 1){
               OGG_End();
               retVal = 1;
               break;

            
         } else if(pad.Buttons & PSP_CTRL_START) {
            //sceDisplayGetBrightness(&brightness, 0);
            if (brightness != 0){
               //Spengo il display:
               oldBrightness = brightness;
               //sceDisplaySetBrightness(0, 0);
            } else {
               //Accendo il display:   
               //sceDisplaySetBrightness(oldBrightness, 0);
            }
            sceKernelDelayThread(100000);
         } else if(pad.Buttons & PSP_CTRL_SELECT) {
            //Mute solo se sono in play:
            if (action == 1){
               if (muted == 0){
                  pspAudioSetVolume(1, 0x1600, 0x1600);
                  muted = 1;
               }else{
                  pspAudioSetVolume(1, 0x8000, 0x8000);
                  muted = 0;
               }
               updateInfo = 0;
               sceKernelDelayThread(400000);
            }
         }

         //Controllo se l'mp3 è finito:
         if (OGG_EndOfStream() == 1) {
            OGG_End();
            retVal = 0;
            break;
         }

     }
     return(retVal);
}
}

//Play directory:
void playDirectory(char *dirName){   
   struct opendir_struct dirToPlay;
   char *result = opendir_open(&dirToPlay, dirName);
   sortDirectory(dirToPlay);
   char testo[10];
   char fileToPlay[256];

   if (result == 0){
      int playerReturn = 0;
      int i = 0;

      while (1){
         snprintf(testo, sizeof(testo), "%i/%i", i + 1, dirToPlay.number_of_directory_entries);
         strcpy(fileToPlay, dirName);
         if (dirName[strlen(dirName)-1] != '/'){
            strcat(fileToPlay, "/");
         }
         strcat(fileToPlay, dirToPlay.directory_entry[i].d_name);
         playerReturn = play(fileToPlay, 1, testo);
         if (playerReturn == 2){
            break;
         }else if ((playerReturn == 1) | (playerReturn == 0)){
            //Controllo se è finita la directory:
            if ((playerReturn == 0) & (i == dirToPlay.number_of_directory_entries - 1)){
               break;
            }
            //Altrimenti passo al file successivo:
            i++;
            if (i > dirToPlay.number_of_directory_entries - 1){
               i = 0;
            }
         }else if (playerReturn == -1){
            i--;
            if (i < 0){
               i = dirToPlay.number_of_directory_entries - 1;
            }
         }
      }
   }
   opendir_close(&dirToPlay);
   return;
}

//Menu:
void main_menu()
   {
   struct opendir_struct directory;
   char curDir[256];
   char dirToPlay[256];
   char fileToPlay[256];

   //Provo prima directory:
   strcpy(curDir, mp3_directory_1);
   char *result = opendir_open(&directory, curDir);
   if (result != 0){
      //Provo seconda directory:
      strcpy(curDir, mp3_directory_2);
      result = opendir_open(&directory, curDir);
      if (result != 0){
         pspDebugScreenSetXY(0, 4);
         pspDebugScreenPrintf("\"%s\" not found or empty", curDir);
         pspDebugScreenSetXY(0, 8);
         return;
      }
   }
   sortDirectory(directory);

   int selected_entry         = 0;
   int top_entry              = 0;
   int maximum_number_of_rows = 20;
   int starting_row           = 4;
   int updateInfo = 10;
   char author[50];
   char title[100];
   while (1)
      {
        SceCtrlData controller;
      screen_init();
      screen_menu_init();
      pspDebugScreenSetXY(0, 3);
      pspDebugScreenPrintf(curDir);

      while (1)
         {
         if (updateInfo >= 10)
         {
            screen_sysinfo();
            updateInfo = 0;
         }
         updateInfo++;

         sceCtrlReadBufferPositive(&controller, 1);
         if ((controller.Buttons & PSP_CTRL_DOWN) | (controller.Ly > 158)){
            if (selected_entry + 1 < directory.number_of_directory_entries){
               selected_entry++;

               if (selected_entry == top_entry + maximum_number_of_rows){
                  top_entry++;
                  }
               }
         } else if ((controller.Buttons & PSP_CTRL_UP) | (controller.Ly < 98)){
            if (selected_entry != 0){
               selected_entry--;

               if (selected_entry == top_entry - 1){
                  top_entry--;
               }
            }
         } else if ((controller.Buttons & PSP_CTRL_RIGHT) | (controller.Lx > 158)){
            //Pagina giù:
            if (top_entry + maximum_number_of_rows < directory.number_of_directory_entries){
               top_entry = top_entry + maximum_number_of_rows;
               selected_entry += maximum_number_of_rows;
               if (selected_entry > directory.number_of_directory_entries - 1){
                  selected_entry = directory.number_of_directory_entries - 1;
               }
            } else {
               selected_entry = directory.number_of_directory_entries - 1;
            }
            sceKernelDelayThread(100000);
         } else if ((controller.Buttons & PSP_CTRL_LEFT) | (controller.Lx < 98)){
            //Pagina su:
            if (top_entry - maximum_number_of_rows >= 0){
               top_entry = top_entry - maximum_number_of_rows;
               selected_entry -= maximum_number_of_rows;
            } else {
               top_entry = 0;
               selected_entry = 0;
            }
            sceKernelDelayThread(100000);
         }
         pspDebugScreenSetXY(1, starting_row);
         pspDebugScreenSetTextColor(WHITE);
         pspDebugScreenSetBackColor(0xaa4400);

         //Segno precedente:
         if (top_entry > 0){
            pspDebugScreenPrintf("%-66.66s", "...");
         } else{
            pspDebugScreenPrintf("%-66.66s", "");
         }
         int i = 0;
         for (; i < maximum_number_of_rows; i++){
            int current_entry = top_entry + i;

            pspDebugScreenSetXY(1, starting_row + i + 1);

            if (current_entry < directory.number_of_directory_entries){
               if (current_entry == selected_entry){
                  pspDebugScreenSetBackColor(0x882200);
               } else {
                  pspDebugScreenSetBackColor(0xcc6600);
               }
               //Controllo se è una directory o un file:
               if (directory.directory_entry[current_entry].d_stat.st_attr == 32){
                  pspDebugScreenSetTextColor(YELLOW);
                  pspDebugScreenPrintf("%-66.66s", directory.directory_entry[current_entry].d_name);
               } else {
                  //Spezzo autore e titolo:
                  if (splitAuthorTitle(directory.directory_entry[current_entry].d_name, author, title) != 0){
                     char format[10];
                     pspDebugScreenSetTextColor(YELLOW);
                     pspDebugScreenPrintf("%s", author);
                     pspDebugScreenPrintf(" ");
                     pspDebugScreenSetTextColor(WHITE);
                     snprintf(format, sizeof(format), "%%-%i.%is", 66 - strlen(author) - 1, 66 - strlen(author) - 1);
                     pspDebugScreenPrintf(format, title);
                  } else {
                     pspDebugScreenSetTextColor(0xcccccc);
                     pspDebugScreenPrintf("%-66.66s", directory.directory_entry[current_entry].d_name);
                  }
               }
            } else {
               pspDebugScreenSetTextColor(WHITE);
               pspDebugScreenSetBackColor(0xaa4400);
               pspDebugScreenPrintf("%-66.66s", "");
            }
         }
         pspDebugScreenSetXY(1, starting_row + maximum_number_of_rows + 1);
         pspDebugScreenSetTextColor(WHITE);
         pspDebugScreenSetBackColor(0xaa4400);
         //Segno successivo:
         if (top_entry + maximum_number_of_rows < directory.number_of_directory_entries){
            pspDebugScreenPrintf("%-66.66s", "...");
         }
         else{
            pspDebugScreenPrintf("%-66.66s", "");
         }


         if (controller.Buttons & PSP_CTRL_CROSS || controller.Buttons & PSP_CTRL_CIRCLE || controller.Buttons & PSP_CTRL_TRIANGLE || controller.Buttons & PSP_CTRL_SQUARE)
            {
            break;
            }
         sceKernelDelayThread(100000);
         }

      if (controller.Buttons & PSP_CTRL_TRIANGLE)
      {
         break;
      } else if (controller.Buttons & PSP_CTRL_CROSS)
      {
         //Controllo se è un file o una directory:
         if (directory.directory_entry[selected_entry].d_stat.st_attr == 32)
         {
            if (strstr(directory.directory_entry[selected_entry].d_name, ".ogg") != 0 || strstr(directory.directory_entry[selected_entry].d_name, ".OGG") != 0){
               strcpy(fileToPlay, curDir);


               if (curDir[strlen(curDir)-1] != '/'){
                  strcat(fileToPlay, "/");
               }
               strcat(fileToPlay, directory.directory_entry[selected_entry].d_name);
               play(fileToPlay, 0, "");
               sceKernelDelayThread(200000);
            }
         } else if (directory.directory_entry[selected_entry].d_stat.st_attr == 16)
         {   
            if (curDir[strlen(curDir)-1] != '/'){
               strcat(curDir, "/");
            }
            strcat(curDir, directory.directory_entry[selected_entry].d_name);
            opendir_close(&directory);
            selected_entry = 0;
            top_entry = 0;
            result = opendir_open(&directory, curDir);
            sortDirectory(directory);
            sceKernelDelayThread(200000);
         }
      } else if (controller.Buttons & PSP_CTRL_CIRCLE)
      {
            opendir_close(&directory);
            directoryUp(curDir);
            selected_entry = 0;
            top_entry = 0;
            result = opendir_open(&directory, curDir);
            sortDirectory(directory);
            sceKernelDelayThread(200000);
      } else if (controller.Buttons & PSP_CTRL_SQUARE)
      {
            //Controllo se è una directory:
            if (directory.directory_entry[selected_entry].d_stat.st_attr == 16){
               strcpy(dirToPlay, curDir);
               if (dirToPlay[strlen(dirToPlay)-1] != '/'){
                  strcat(dirToPlay, "/");
               }
               strcat(dirToPlay, directory.directory_entry[selected_entry].d_name);
               playDirectory(dirToPlay);
               sceKernelDelayThread(200000);
            }
      }
      }
   opendir_close(&directory);
   }

//Main
int main() {
        scePowerSetClockFrequency(222, 222, 111);
        scePowerSetCpuClockFrequency(80);
        scePowerSetBusClockFrequency(60);
        sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
          SetupCallbacks();
        tzset();

          pspAudioInit();      
        pspAudioSetVolume(1, 0x8000, 0x8000);
        main_menu();
        pspAudioEnd();
        sceKernelExitGame();
        return(0);
}


The code of oggplayer.h:

Code:

extern int OGG_defaultCPUClock;

//private functions
void OGG_Init(int channel);
int OGG_Play();
void OGG_Pause();
int OGG_Stop();
void OGG_End();
void OGG_FreeTune();
int OGG_Load(char *filename);
void OGG_GetTimeString(char *dest);
int OGG_EndOfStream();
struct fileInfo OGG_GetInfo();
struct fileInfo OGG_GetTagInfoOnly(char *filename);
int OGG_GetStatus();
int OGG_GetPercentage();
void OGG_setVolumeBoostType(char *boostType);
void OGG_setVolumeBoost(int boost);
int OGG_getVolumeBoost();
int OGG_getPlayingSpeed();
int OGG_setPlayingSpeed(int playingSpeed);
int OGG_setMute(int onOff);
void OGG_fadeOut(float seconds);

//Functions for filter (equalizer):   
int OGG_setFilter(double tFilter[32], int copyFilter);
void OGG_enableFilter();
void OGG_disableFilter();
int OGG_isFilterEnabled();
int OGG_isFilterSupported();

//Manage suspend:
int OGG_suspend();
int OGG_resume();



This is the makefile:

Code:
TARGET = ogg
OBJS = log.o id3.o main.o mem64.o opendir.o
#To build for custom firmware:
BUILD_PRX = 1
#PSP_LARGE_MEMORY = 1
PSP_FW_VERSION=371

CFLAGS = -O3 -fomit-frame-pointer -ffast-math -frename-registers -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =

LIBS =  -lmad -lvorbisidec -lm \
       -lpspgu -lpspgum -lpsppower \
       -lpsphprm -lpspusb -lpspusbstor -lpspaudio -lpspaudiocodec  -lpspaudiolib -logg
LDFLAGS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = OGG Sample
PSP_EBOOT_ICON = ICON0.PNG
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak


And here the mistakes on having compiled:

Code:

                             
psp-gcc -I. -IC:/PSPDev/psp/sdk/include -O3 -fomit-frame-pointer -ffast-math -fr
ename-registers -G0 -Wall -D_PSP_FW_VERSION=371   -c -o main.o main.c
main.c: In function 'play':
main.c:446: warning: implicit declaration of function 'OGG_GetPercentace'
main.c:567: warning: control reaches end of non-void function
psp-gcc -I. -IC:/PSPDev/psp/sdk/include -O3 -fomit-frame-pointer -ffast-math -fr
ename-registers -G0 -Wall -D_PSP_FW_VERSION=371   -c -o mem64.o mem64.c
psp-gcc -I. -IC:/PSPDev/psp/sdk/include -O3 -fomit-frame-pointer -ffast-math -fr
ename-registers -G0 -Wall -D_PSP_FW_VERSION=371   -c -o opendir.o opendir.c
psp-gcc -I. -IC:/PSPDev/psp/sdk/include -O3 -fomit-frame-pointer -ffast-math -fr
ename-registers -G0 -Wall -D_PSP_FW_VERSION=371  -L. -LC:/PSPDev/psp/sdk/lib -sp
ecs=C:/PSPDev/psp/sdk/lib/prxspecs -Wl,-q,-TC:/PSPDev/psp/sdk/lib/linkfile.prx
 log.o id3.o main.o mem64.o opendir.o C:/PSPDev/psp/sdk/lib/prxexports.o -lmad -
lvorbisidec -lm -lpspgu -lpspgum -lpsppower -lpsphprm -lpspusb -lpspusbstor -lps
paudio -lpspaudiocodec  -lpspaudiolib -logg -lpspdebug -lpspdisplay -lpspge -lps
pctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsp
utility -lpspuser -lpspkernel -o mp3.elf
main.o: In function `play':
main.c:(.text+0xe4c): undefined reference to `OGG_Init'
main.c:(.text+0xe7c): undefined reference to `OGG_Load'
main.c:(.text+0xe90): undefined reference to `OGG_Play'
main.c:(.text+0xea0): undefined reference to `OGG_GetTimeString'
main.c:(.text+0xedc): undefined reference to `OGG_GetPercentace'
main.c:(.text+0x1000): undefined reference to `OGG_Pause'
main.c:(.text+0x108c): undefined reference to `OGG_EndOfStream'
main.c:(.text+0x10a0): undefined reference to `OGG_End'
main.c:(.text+0x116c): undefined reference to `OGG_End'
C:/PSPDev/psp/sdk/lib\libpspaudiolib.a(pspaudiolib.o): In function `pspAudioEnd'
:
: undefined reference to `sceAudioChRelease'
C:/PSPDev/psp/sdk/lib\libpspaudiolib.a(pspaudiolib.o): In function `pspAudioInit
':
: undefined reference to `sceAudioChReserve'
C:/PSPDev/psp/sdk/lib\libpspaudiolib.a(pspaudiolib.o): In function `pspAudioInit
':
: undefined reference to `sceAudioChRelease'
C:/PSPDev/psp/sdk/lib\libpspaudiolib.a(pspaudiolib.o): In function `pspAudioOutB
locking':
: undefined reference to `sceAudioOutputPannedBlocking'
collect2: ld returned 1 exit status
make: *** [mp3.elf] Error 1

                                   


Is there some solution?
Back to top
View user's profile Send private message
jsharrad



Joined: 20 Oct 2005
Posts: 102

PostPosted: Sat May 03, 2008 9:28 am    Post subject: Reply with quote

Looks like you need to link the oggplayer object that you compile with oggplayer.c and switch your ordering of your libs some, like -lpspaudio should come after -lpspaudiolib.
Back to top
View user's profile Send private message
Pirata Nervo



Joined: 09 Oct 2007
Posts: 409

PostPosted: Sat May 03, 2008 5:15 pm    Post subject: Reply with quote

added this to your OBJS:
oggplayer.o

and -lpspaudio to your LIBS
of course you must have the oggplayer.c and .h in the same directory as the source code
_________________

Upgrade your PSP
Back to top
View user's profile Send private message
jsharrad



Joined: 20 Oct 2005
Posts: 102

PostPosted: Sat May 03, 2008 5:30 pm    Post subject: Reply with quote

and if after all that it still doesn't compile, you may want to spell percentage correctly on line 446 ;)
Back to top
View user's profile Send private message
nikocronaldo



Joined: 24 Feb 2008
Posts: 31

PostPosted: Sat May 03, 2008 11:07 pm    Post subject: Reply with quote

I have solved the majority of errors, but now it has given me these:

Code:

                           
psp-gcc -I. -IC:/PSPDev/psp/sdk/include -O3 -fomit-frame-pointer -ffast-math -fr
ename-registers -G0 -Wall -D_PSP_FW_VERSION=371  -L. -LC:/PSPDev/psp/sdk/lib -sp
ecs=C:/PSPDev/psp/sdk/lib/prxspecs -Wl,-q,-TC:/PSPDev/psp/sdk/lib/linkfile.prx
 log.o id3.o main.o mem64.o opendir.o oggplayer.o player.o pspaudiolib.o C:/PSPD
ev/psp/sdk/lib/prxexports.o -lmad -lvorbisidec -lm -lpspgu -lpspgum -lpsppower -
lpsphprm -lpspusb -lpspusbstor -lpspaudiolib -logg -lpspaudio -lpspaudiocodec -l
pspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lps
pnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o ogg.elf
pspaudiolib.o: In function `pspReleaseAudio':
pspaudiolib.c:(.text+0x90): undefined reference to `sceAudioOutput2GetRestSample
'
pspaudiolib.o: In function `pspAudioSetFrequency':
pspaudiolib.c:(.text+0x2ec): undefined reference to `sceAudioOutput2GetRestSampl
e'
pspaudiolib.o: In function `pspAudioEnd':
pspaudiolib.c:(.text+0x3e4): undefined reference to `sceAudioOutput2GetRestSampl
e'
pspaudiolib.o: In function `pspAudioInit':
pspaudiolib.c:(.text+0x4e8): undefined reference to `sceAudioOutput2GetRestSampl
e'
pspaudiolib.c:(.text+0x768): undefined reference to `sceAudioOutput2GetRestSampl
e'
collect2: ld returned 1 exit status
make: *** [ogg.elf] Error 1



The makefile:

Code:

TARGET = ogg
OBJS = log.o id3.o main.o mem64.o opendir.o oggplayer.o player.o pspaudiolib.o
#To build for custom firmware:
BUILD_PRX = 1
#PSP_LARGE_MEMORY = 1
PSP_FW_VERSION=371

CFLAGS = -O3 -fomit-frame-pointer -ffast-math -frename-registers -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =

LIBS =  -lmad -lvorbisidec -lm \
       -lpspgu -lpspgum -lpsppower \
       -lpsphprm -lpspusb -lpspusbstor -lpspaudiolib -logg -lpspaudio -lpspaudiocodec
LDFLAGS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = OGG Sample
PSP_EBOOT_ICON = ICON0.PNG
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
Back to top
View user's profile Send private message
nikocronaldo



Joined: 24 Feb 2008
Posts: 31

PostPosted: Sun May 04, 2008 1:59 am    Post subject: Reply with quote

Excuse me this post,I solved the error,but it doesn't work in FAT or in SLIM.

I put you a link with all the files that I have used: the main, libraries, makefile : http://d01.megashares.com/?d01=f6292f9
It's rare :( . Very thanks to all ;)
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sun May 04, 2008 4:53 am    Post subject: Reply with quote

You might want to check out a more simple player first. It seems you really don't understand the code, so you don't understand what to cut and what to leave. Just do a search on flac as I added flac playing to the simple ogg example posted here. That should help you find the proper thread.
Back to top
View user's profile Send private message AIM Address
nikocronaldo



Joined: 24 Feb 2008
Posts: 31

PostPosted: Sun May 04, 2008 6:50 am    Post subject: Reply with quote

Thanks ;) I saw your ogg player,but i don't have libFLAC,libvorbis and libvorbisfile, because I have a Pack of Marce82.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sun May 04, 2008 7:22 am    Post subject: Reply with quote

If you're using Windows, someone here built a recent toolchain and made an installer for it and a bunch of the libs. You'll find all that here:

http://sourceforge.net/project/showfiles.php?group_id=223830
Back to top
View user's profile Send private message AIM Address
nikocronaldo



Joined: 24 Feb 2008
Posts: 31

PostPosted: Sun May 04, 2008 9:11 am    Post subject: Reply with quote

J.F. wrote:
If you're using Windows, someone here built a recent toolchain and made an installer for it and a bunch of the libs. You'll find all that here:

http://sourceforge.net/project/showfiles.php?group_id=223830


Oh,great! Thanks you,I search it ;).

I have other error:

Code:

                             
psp-gcc -I. -IC:/PSPDev/psp/sdk/include -O3 -G0 -Wall -D_PSP_FW_VERSION=371   -c
 -o main.o main.c
main.c:55: warning: data definition has no type or storage class
main.c:55: warning: type defaults to 'int' in declaration of 'PSP_HEAP_SIZE_MAX'

psp-gcc -I. -IC:/PSPDev/psp/sdk/include -O3 -G0 -Wall -D_PSP_FW_VERSION=371   -c
 -o pspaudiolib.o pspaudiolib.c
psp-gcc -I. -IC:/PSPDev/psp/sdk/include -O3 -G0 -Wall -D_PSP_FW_VERSION=371  -L.
 -LC:/PSPDev/psp/sdk/lib -specs=C:/PSPDev/psp/sdk/lib/prxspecs -Wl,-q,-TC:/PSPDe
v/psp/sdk/lib/linkfile.prx   log.o id3.o mp3player.o main.o mem64.o opendir.o pl
ayer.o oggplayer.o pspaudiolib.o C:/PSPDev/psp/sdk/lib/prxexports.o -lmad -lpspa
udiolib -lpspaudio -lpsppower -lpsphprm -lpspaudiocodec -lFLAC -lvorbisfile -lvo
rbis -logg -lpspaudiolib -lpspaudio -lpsppower -lm -lpspdebug -lpspdisplay -lpsp
ge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolve
r -lpsputility -lpspuser -lpspkernel -o mp3.elf
pspaudiolib.o: In function `pspReleaseAudio':
pspaudiolib.c:(.text+0x90): undefined reference to `sceAudioOutput2GetRestSample
'
pspaudiolib.o: In function `pspAudioSetFrequency':
pspaudiolib.c:(.text+0x2ec): undefined reference to `sceAudioOutput2GetRestSampl
e'
pspaudiolib.o: In function `pspAudioEnd':
pspaudiolib.c:(.text+0x3e4): undefined reference to `sceAudioOutput2GetRestSampl
e'
pspaudiolib.o: In function `pspAudioInit':
pspaudiolib.c:(.text+0x4e8): undefined reference to `sceAudioOutput2GetRestSampl
e'
pspaudiolib.c:(.text+0x770): undefined reference to `sceAudioOutput2GetRestSampl
e'
collect2: ld returned 1 exit status
make: *** [mp3.elf] Error 1

                                     


This is my makefile:

Code:


TARGET = mp3
OBJS = log.o id3.o mp3player.o main.o mem64.o opendir.o player.o oggplayer.o pspaudiolib.o

BUILD_PRX = 1
PSP_FW_VERSION = 371

CFLAGS = -O3 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =



LIBS = -lmad -lpspaudiolib -lpspaudio -lpsppower -lpsphprm -lpspaudiocodec -lFLAC -lvorbisfile -lvorbis -logg -lpspaudiolib -lpspaudio -lpsppower -lm
#-lpspdisplay_driver
LDFLAGS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = OGG Player
PSP_EBOOT_ICON = ICON0.PNG
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak


Do I need the lib libpspaudio_driver? I din't find it.
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Sun May 04, 2008 10:00 am    Post subject: Reply with quote

Update your SDK.

Just for you I updated the audio part of the SDK today ;)
Back to top
View user's profile Send private message
nikocronaldo



Joined: 24 Feb 2008
Posts: 31

PostPosted: Sun May 04, 2008 10:04 am    Post subject: Reply with quote

Insert_witty_name wrote:
Update your SDK.

Just for you I updated the audio part of the SDK today ;)


I have Win32.

pd:If you don't mind to upload libpspaudio_driver...:)
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Sun May 04, 2008 10:12 am    Post subject: Reply with quote

You don't need the driver part of the library.

This update gives you the perfect opportunity to install the SDK as it was meant to be and not use one of those pre-compiled toolchains.
Back to top
View user's profile Send private message
nikocronaldo



Joined: 24 Feb 2008
Posts: 31

PostPosted: Sun May 04, 2008 10:18 am    Post subject: Reply with quote

Insert_witty_name wrote:
You don't need the driver part of the library.

This update gives you the perfect opportunity to install the SDK as it was meant to be and not use one of those pre-compiled toolchains.


I'll install it...but Cygwin can be late to install xD,thanks you.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sun May 04, 2008 12:15 pm    Post subject: Reply with quote

If you look in LightMP3, sakya used the "new" stereo sound routines directly in his code in place of the pspaudio lib. You find those undefined functions in his source in src/players/pspaudiolib.c and the corresponding h file.
Back to top
View user's profile Send private message AIM Address
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