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: Select all
#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;
}
Code: Select all
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()
Code: Select all
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()