Running MP3, OGG on Stackless
I haven’t returned to my book training yet (curse this lethargy! :), but I did take some time today to make a backup of my Stackless Python setup on my PSP, and created duplicates to test the OGG and MP3 playback with my title screen exercise. In my last post, I mentioned that I’d gotten the script to run on Stackless initially, and I then tried to integrate MP3 streaming as per Carlos’ tutorial at themindcaster blog. Not only did I fail to get the MP3 script to run in the title screen script, but when I tried to restore the original, silent title screen script, Stackless would not run the script at all.
The good news is that I managed to get both scripts to run successfully in my script. I got an OGG from the Brian Jonestown Massacre website to run, and I tested four different MP3’s. Strangely, the MP3’s seem to take longer to load & run than the OGG version. The size & bitrate of the MP3 seems to play a role. I found that an MP3 from Soundpool’s Myspace page ran too fast. “On High” was 4.3 MB, with a bit rate of 96 kbps and a sample rate of 22.050 kHz.
Here’s what the adjusted code segment looks like for the MP3 player:
def main():
scr=psp2d.Screen()
img=psp2d.Image('lemonstart.png')
fnt=psp2d.Font('font.png')
fnt.drawText(img,20,50,’LEMONADE STAND’)
fnt.drawText(img,20,102,’Press START’)
scr.blit(img)
scr.swap()
pspmp3.init(1)
pspmp3.load(‘TFIV35.mp3’)
pspmp3.play()
while True:
pad=psp2d.Controller()
if pspmp3.endofstream()==1 or pad.cross:
fnt.drawText(img,220,210,’END OF STREAM’)
pspmp3.end()
scr.blit(img)
scr.swap()
#break
I saved the initialization until after the first screen was blitted, and then moved the endofstream condition after the psp2d.Controller line in the original exercise. I commented out the break so the program wouldn’t end once the song did. When the song ends, it blits an “END OF STREAM” message to the middle of the screen.
I’ll post these scripts here later in the week.