Mp3 questions ...

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

Moderators: cheriff, TyRaNiD

Post Reply
TheHorst
Posts: 12
Joined: Thu Apr 13, 2006 10:11 pm

Mp3 questions ...

Post by TheHorst »

why does my mp3s have a clicking sound in the beginning (sometimes they have, sometimes not)

thats my code:

Code: Select all

int Question(void)
{
	Color dimmedColor = RGB(100, 100, 100);
	Color shadowColorD = RGB(55, 55, 55 ); 

	Image* ourImage;
	SceCtrlData pad;

	char music[200];
	char title[200];
	char buffer[200];
	char filler[200];
	
	int ptr_balken = 1;
	int ptr_time = 30;
	int ptr_check = 1;
	int counter = 1;

	quick = 150;
	scann = (question * 3)-3;
	fseek(file, 1L, 0);
	fseek(file, -1L, 1);
	while &#40;count < scann&#41;
	&#123;
		fscanf&#40;file, "%s", &music&#41;;
		count++;
	&#125;
	fscanf&#40;file, "%s", &music&#41;;
	fscanf&#40;file, "%s", &music&#41;;
	fscanf&#40;file, "%d", &truebutton&#41;;

	sprintf&#40;buffer, "gfx/questions/question%04d.png", question&#41;;
	ourImage = loadImage&#40;buffer&#41;;
	blitAlphaImageToScreen&#40;0 ,0 , 480, 272, ourImage, 0, 0&#41;;
	freeImage&#40;ourImage&#41;;

	sprintf&#40;buffer, "gfx/balken/balken00.png"&#41;;
	ourImage = loadImage&#40;buffer&#41;;
	blitAlphaImageToScreen&#40;0 ,0 , 442, 21, ourImage, 19, 100&#41;;
	freeImage&#40;ourImage&#41;;
	
	sprintf&#40;filler, "%d", ptr_time&#41;;            
	printTextScreen&#40;231, 107, filler, shadowColorD&#41;;
	printTextScreen&#40;230, 107, filler, dimmedColor&#41;;	
	flipScreen&#40;&#41;;
	sprintf&#40;buffer, "gfx/questions/question%04d.png", question&#41;;
	ourImage = loadImage&#40;buffer&#41;;
	blitAlphaImageToScreen&#40;0 ,0 , 480, 272, ourImage, 0, 0&#41;;
	freeImage&#40;ourImage&#41;;

	sprintf&#40;buffer, "gfx/balken/balken00.png"&#41;;
	ourImage = loadImage&#40;buffer&#41;;
	blitAlphaImageToScreen&#40;0 ,0 , 442, 21, ourImage, 19, 100&#41;;
	freeImage&#40;ourImage&#41;;
	
	sprintf&#40;filler, "%d", ptr_time&#41;;            
	printTextScreen&#40;231, 107, filler, shadowColorD&#41;;
	printTextScreen&#40;230, 107, filler, dimmedColor&#41;;	
	flipScreen&#40;&#41;;
	ptr_time = ptr_time -1;

	sprintf&#40;title, "music/%s.mp3", music&#41;;
	MP3_Init&#40;1&#41;;
                MP3_Load&#40;title&#41;;
                MP3_Play&#40;&#41;;
	CheckButtons&#40;&#41;;

	while &#40;counter < 31&#41;
	&#123;
		sprintf&#40;buffer, "gfx/balken/balken%02d.png", ptr_balken&#41;;
		ourImage = loadImage&#40;buffer&#41;;
		blitAlphaImageToScreen&#40;0 ,0 , 442, 21, ourImage, 19, 100&#41;;
	
		sprintf&#40;filler, "%d", ptr_time&#41;;            
		printTextScreen&#40;231, 107, filler, shadowColorD&#41;;
		printTextScreen&#40;230, 107, filler, dimmedColor&#41;;
		flipScreen&#40;&#41;;
		freeImage&#40;ourImage&#41;;
		CheckButtons&#40;&#41;;
		ptr_time = ptr_time -1;
		if &#40;ptr_check == 2&#41;
		&#123;
			quick = quick - 10;
			if &#40;ptr_balken < 13&#41;
			&#123;ptr_balken++;&#125;
			ptr_check = 1;
		&#125;
		else if &#40;ptr_check == 1&#41;
		&#123;ptr_check++;&#125;
		counter++;
	&#125;

	MP3_Stop&#40;&#41;;
	MP3_FreeTune&#40;&#41;;

	sprintf&#40;buffer, "gfx/questions/question%04d_w.png", question&#41;;
	ourImage = loadImage&#40;buffer&#41;;
	blitAlphaImageToScreen&#40;0 ,0 , 480, 272, ourImage, 0, 0&#41;;
	freeImage&#40;ourImage&#41;;
			
	sprintf&#40;buffer, "gfx/points/slow.png"&#41;;
	ourImage = loadImage&#40;buffer&#41;;
	blitAlphaImageToScreen&#40;0 ,0 , 362, 30, ourImage, 59, 90&#41;;
	freeImage&#40;ourImage&#41;;
	flipScreen&#40;&#41;;

	while&#40;1&#41;
	&#123;
		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		if&#40;pad.Buttons & PSP_CTRL_CROSS&#41; 
		&#123;
			sceKernelDelayThread&#40;250000&#41;;
			break;
		&#125;
	&#125;

	count = 0;
	ScoreBoardOne&#40;&#41;;
	return 1;
&#125;
on button input, mp3 is stopped an unloaded

Code: Select all

int CheckButtons&#40;void&#41;
&#123;
	int starttime;
	Image* ourImage; 

	SceCtrlData pad;

	char buffer&#91;200&#93;;

	starttime = clock&#40;&#41;;
	while&#40;clock&#40;&#41; - starttime < 1000000&#41;
	&#123;
		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		if&#40;pad.Buttons & PSP_CTRL_CROSS&#41; 
		&#123;
			pressed = 1;
			MP3_Stop&#40;&#41;;
			MP3_FreeTune&#40;&#41;;

			if &#40;truebutton == 1&#41;
			&#123;
				sprintf&#40;buffer, "gfx/questions/question%04d_r.png", question&#41;;
				ourImage = loadImage&#40;buffer&#41;;
				blitAlphaImageToScreen&#40;0 ,0 , 480, 272, ourImage, 0, 0&#41;;
				freeImage&#40;ourImage&#41;;
				sprintf&#40;buffer, "gfx/points/points%03d.png", quick&#41;;
				ourImage = loadImage&#40;buffer&#41;;
				blitAlphaImageToScreen&#40;0 ,0 , 362, 30, ourImage, 59, 90&#41;;
				freeImage&#40;ourImage&#41;;
			&#125;
			else
			&#123;
				sprintf&#40;buffer, "gfx/questions/question%04d_w.png", question&#41;;
				ourImage = loadImage&#40;buffer&#41;;
				blitAlphaImageToScreen&#40;0 ,0 , 480, 272, ourImage, 0, 0&#41;;
				freeImage&#40;ourImage&#41;;
				sprintf&#40;buffer, "gfx/points/wrong.png"&#41;;
				ourImage = loadImage&#40;buffer&#41;;
				blitAlphaImageToScreen&#40;0 ,0 , 362, 30, ourImage, 59, 90&#41;;
				freeImage&#40;ourImage&#41;;
				quick = 0;
			&#125;
			flipScreen&#40;&#41;;
			break;
		&#125;

			&#125;

	count = 0;
	if &#40;pressed == 1&#41;
	&#123;
		pressed = 0;
		while&#40;1&#41;
		&#123;
			sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
			if&#40;pad.Buttons & PSP_CTRL_CROSS&#41; 
			&#123;
				sceKernelDelayThread&#40;250000&#41;;
				break;
			&#125;
		&#125;
		ScoreBoardOne&#40;&#41;;
	&#125;
	return 1;		
&#125;
loop restarts with new values ...

as i said, sometimes the mp3s starting with noise, sometimes they workking properly ...
(besides ive noticed , that small mp3s will be repeated, even if u terminate them imideatly, anyone knows why?)[/code]
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

Audio signals click because either the first or the last sample isn't 0 (or at the same level the last sample finished at). The click is the sharp transition from the old level to the new one.
Also, lots of mpg encoders I've used manage to add a click to a wav file that didn't exist in the first place!
Jim
Post Reply