MP3 Playback is way too fast. What's next?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
^L^
Posts: 19
Joined: Sat Jun 14, 2008 1:11 pm

MP3 Playback is way too fast. What's next?

Post by ^L^ »

My music plays way too fast whenever it's loaded and doesn't stop once it has ended. What do I do?
I isolated my code so I could find out what's been wrong.

Code: Select all

#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include <psppower.h>

#include "mp3player.h"

# ifdef PSPFW3X
PSP_MODULE_INFO&#40;"Program", 0x0, 1, 1&#41;;
PSP_HEAP_SIZE_KB&#40;6*1024&#41;;
# else
PSP_MODULE_INFO&#40;"Program", 0x1000, 1, 1&#41;;
# endif
PSP_MAIN_THREAD_ATTR&#40;0&#41;;
PSP_MAIN_THREAD_STACK_SIZE_KB&#40;32&#41;;

#define printf pspDebugScreenPrintf

int var = 0;
int timer = 0;

int main&#40;&#41; &#123;
//scePowerSetClockFrequency&#40;333, 333, 166&#41;;
SetupCallbacks&#40;&#41;;
pspDebugScreenInit&#40;&#41;;
pspAudioInit&#40;&#41;;
SceCtrlData pad;
while&#40;1&#41; &#123; 
sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
	if&#40;timer>=1&#41; &#123;
		    timer--;
	&#125;
	if&#40;timer<0&#41; &#123;
		    timer=0;
	&#125;
	if&#40;var==0&#41; &#123;
		printf&#40;"X&#58; Sound 1\n&#91;&#93;&#58; Sound 2\n"&#41;;
		var=1;
	&#125;
	if&#40;pad.Buttons & PSP_CTRL_SQUARE && &#40;timer==0&#41;&#41; &#123;
		MP3_End&#40;&#41;;
		MP3_Init&#40;1&#41;;
		MP3_Load&#40;"SQU.mp3"&#41;;
		MP3_Play&#40;&#41;; 
		timer=20;
	&#125;
	if&#40;pad.Buttons & PSP_CTRL_CROSS && &#40;timer==0&#41;&#41; &#123;
		MP3_End&#40;&#41;;
		MP3_Init&#40;1&#41;;
		MP3_Load&#40;"CRO.mp3"&#41;;
		MP3_Play&#40;&#41;; 
		timer=20;
	&#125;

&#125;
MP3_Stop&#40;&#41;;
MP3_FreeTune&#40;&#41;;
sceKernelSleepThread&#40;&#41;;
return 0;
&#125;
I just can't find the reason. I kinda know what I need for stopping the music after it's played once but I'm not exactly sure and cannot get it to work :(
Last edited by ^L^ on Tue Aug 12, 2008 7:56 am, edited 1 time in total.
iceman755
Posts: 30
Joined: Mon Jul 21, 2008 1:12 am

Post by iceman755 »

what I can see is:

-the variable timer is always equal to zero, so it has no efect in your code.

-the loop is lasting forever.

-you need to use a lastbutton check.

I hope this help you to figure out what is wrong.
"Libera eas de ore leonis, ne absorbeat eas tartarus, ne cadant in obscurum"
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

It could be that the frequency of the mp3 you're using is < 44100 hz(the default on the PSP). this would be the care (maybe) if the mp3 is mpeg 2/2.5 (mp3pro if you use yahoo/musicmatch jukebox). Solutions(if this is the problem): re-encode mp3 to 44100 hz or change the PSP audio output frequency to match the mp3.
^L^
Posts: 19
Joined: Sat Jun 14, 2008 1:11 pm

Post by ^L^ »

The MP3 files all have exactly 44kHz whenever I check their properties. Would that make much of a difference? And what would I do to change the PSP's output frequency?

And I felt sooooooo dumb whenever I saw the timer variable thing. I'm such an idiot. I think if I have this in, then I wouldn't need a lastbutton variable or anything. It should also take care of playing it looped.

I'm going to recompile the program and test it out! Thanks for the help! If there's another problem with it regarding the playback, I'll post again.
^L^
Posts: 19
Joined: Sat Jun 14, 2008 1:11 pm

Post by ^L^ »

Yeah, I know, it's a double post... but....
The timer thing had no effect at the stage of the development of the program.
I think right now I should figure out how to change the output frequency or look at other people's source codes to see how they did it.
Post Reply