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 

Libmad and Python, help! :)

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



Joined: 28 Apr 2006
Posts: 190

PostPosted: Mon Sep 25, 2006 6:32 pm    Post subject: Libmad and Python, help! :) Reply with quote

Hi!

I've never coded in C/C++ before, but I'm trying to add mp3 support to psp-python using libmad. :)
Reading this doumentation: http://docs.python.org/ext/ext.html
and this tutorial http://www.psp-programming.com/tutorials/c/lesson06.htm I've made a module that imports corretcly into a python script, but no sound comes from my psp.
The tutorial's mp3 player example works fine.
Can someone help me? What's wrong?
Many thanks for your attention.

Here's my code:
Code:

#include <Python.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include "mp3player.h"

static PyObject *pspmp3Error;

// Init:
static PyObject *
pspmp3_init(PyObject *self, PyObject *args)
{
   int channel;
   if (!PyArg_ParseTuple(args, "i", &channel))
      return NULL;

   pspAudioInit();
   MP3_Init(channel);
   return Py_None;
}


// Load:
static PyObject *
pspmp3_load(PyObject *self, PyObject *args)
{
   char* fileName;
   if (!PyArg_ParseTuple(args, "s", &fileName))
      return NULL;

   FILE *fp;
   fp = fopen(fileName, "r");
   if (fp)
    {
      MP3_Load(fileName);
    }
    else
    {
       return NULL;
    }
   return Py_None;
}

// Play:
static PyObject *
pspmp3_play(PyObject *self, PyObject *args)
{
   MP3_Play();
   return Py_None;
}


// Stop:
static PyObject *
pspmp3_stop(PyObject *self, PyObject *args)
{
   MP3_Stop();
   return Py_None;
}

// Test:
static PyObject *
pspmp3_test(PyObject *self, PyObject *args)
{
   pspAudioInit();
   MP3_Init(1);
   MP3_Load("test.mp3");
   MP3_Play();
   while(1)
   {
      if (MP3_EndOfStream() == 1)
      {
         MP3_Stop();
         MP3_FreeTune();
         return Py_None;
      }
   }
}


// Definizione metodi modulo:
static PyMethodDef pspmp3Methods[] = {
   {"init", pspmp3_init, METH_VARARGS, "Initialize"},
   {"load", pspmp3_load, METH_VARARGS, "Load an mp3 file"},
   {"play", pspmp3_play, METH_VARARGS, "Play the loaded mp3"},
   {"stop", pspmp3_stop, METH_VARARGS, "Stop the mp3 playback"},
   {"test", pspmp3_test, METH_VARARGS, ""},
   {NULL, NULL, 0, NULL}
};   

// Inizializzazione modulo:
PyMODINIT_FUNC initpspmp3(void)
{
   PyObject *mdl;

   pspmp3Error = PyErr_NewException("pspmp3.Error", NULL, NULL);
    mdl = Py_InitModule3("pspmp3", pspmp3Methods, "PSP Mp3");
   if (!mdl)
      return;   
}


If I execute this script the psp dosen't play the mp3:
Code:
import psp2d
import pspmp3
from time import time
from pspos import freemem, getclock, getbus, battery

msg = ""

#Test mp3:
pspmp3.init(1)
pspmp3.load("test.mp3")
pspmp3.play()

#Main:
screen = psp2d.Screen()
font = psp2d.Font('font.png')
background_image = psp2d.Image(480,272)
background_image.clear(psp2d.Color(0,0,0))
oldPad = None
number = 0

while True:
  number += 1
  screen.blit(background_image, 0, 0, background_image.width, background_image.height, 0, 0)
  font.drawText(screen, 20, 140, "TIME: " + str(time()))
  font.drawText(screen, 20, 160, "MESSAGE: " + msg)

  #Image:
  outerImage = psp2d.Image(100, 100)
  outerImage.clear(psp2d.Color(61, 58, 61, 178))

  innerImage = psp2d.Image(80, 80)
  innerImage.clear(psp2d.Color(119, 112, 113, 178))

  msg = "Created " + str(number) + " times"
  screen.blit(outerImage, 0, 0, outerImage.width, outerImage.height, 30, 30)
  screen.blit(innerImage, 0, 0, innerImage.width, innerImage.height, 40, 40)

  newText = "MEM: " + str(freemem() / 1024) + "kb  CPU:" + str(getclock()) + "Mhz  BUS:" + str(getbus()) + "Mhz  BATT:" + str(battery()[3]) + "%"
  font.drawText(screen, 0, 0, newText)
  screen.swap()


If I execute the test function the psp hangs, but still no sound output:
Code:

import psp2d
import pspmp3
from time import time
from pspos import freemem, getclock, getbus, battery

msg = ""

#Test mp3:
pspmp3.test()

#Main:
screen = psp2d.Screen()
font = psp2d.Font('font.png')
background_image = psp2d.Image(480,272)
background_image.clear(psp2d.Color(0,0,0))
oldPad = None
number = 0

while True:
  number += 1
  screen.blit(background_image, 0, 0, background_image.width, background_image.height, 0, 0)
  font.drawText(screen, 20, 140, "TIME: " + str(time()))
  font.drawText(screen, 20, 160, "MESSAGE: " + msg)

  #Image:
  outerImage = psp2d.Image(100, 100)
  outerImage.clear(psp2d.Color(61, 58, 61, 178))

  innerImage = psp2d.Image(80, 80)
  innerImage.clear(psp2d.Color(119, 112, 113, 178))

  msg = "Created " + str(number) + " times"
  screen.blit(outerImage, 0, 0, outerImage.width, outerImage.height, 30, 30)
  screen.blit(innerImage, 0, 0, innerImage.width, innerImage.height, 40, 40)

  newText = "MEM: " + str(freemem() / 1024) + "kb  CPU:" + str(getclock()) + "Mhz  BUS:" + str(getbus()) + "Mhz  BATT:" + str(battery()[3]) + "%"
  font.drawText(screen, 0, 0, newText)
  screen.swap()
Back to top
View user's profile Send private message Visit poster's website
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