ATRAC3 Player Sample

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

Moderators: cheriff, TyRaNiD

moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

User mode cannot load anything from the flash not even signed modules (except if a kernel app like psplink previously did a patch).
Loading from flash is only possible in kernel mode and vsh mode. Well, in vsh mode it would require the vshbridge module to be previously loaded, something that is not done automatically in "game" operative mode, so at the end you are forced to use kernel mode.
subbie
Posts: 122
Joined: Thu May 05, 2005 4:14 am

Post by subbie »

moonlight wrote:User mode cannot load anything from the flash not even signed modules (except if a kernel app like psplink previously did a patch).
Loading from flash is only possible in kernel mode and vsh mode. Well, in vsh mode it would require the vshbridge module to be previously loaded, something that is not done automatically in "game" operative mode, so at the end you are forced to use kernel mode.
Is there any other posible way as making my app kernal mode only would destroy compatibility with many psp units.
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

Post by weltall »

yeah to load the required libraries you need kernel mode
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

weltall wrote:yeah to load the required libraries you need kernel mode
In user mode, they can be loaded from a disc anyways, and all umd usually have those two libraries.

In that way, the atrac3 player sample would work on a normal user mode application... but it wouldn't work on a GTA-exploit application.
subbie
Posts: 122
Joined: Thu May 05, 2005 4:14 am

Post by subbie »

moonlight wrote:
weltall wrote:yeah to load the required libraries you need kernel mode
In user mode, they can be loaded from a disc anyways, and all umd usually have those two libraries.

In that way, the atrac3 player sample would work on a normal user mode application... but it wouldn't work on a GTA-exploit application.
So stuff ran with gta loader wont work but 2.0 via tiff should work.

Hmm. This kind of sucks... Does the GTA-exploit alow wifi or does not as well because of this same issue?

Also if my app is running in kernal. I noticed comments on atrac3 needing user mode. Do I only just need to execute the threads in user vs kernal?
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Re: ATRAC3 Player Sample

Post by sakya »

Hi! :)

Sorry to bother. I'm not an experienced C/C++ coder, sorry for my question.
I'm trying to use the sample code in a "normal" eboot (not in a prx).
I'm always getting the "Cannot play that file." message.
Can someone help me? :)

Many thanks
Sakya
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

sakya wrote:Hi! :)

Sorry to bother. I'm not an experienced C/C++ coder, sorry for my question.
I'm trying to use the sample code in a "normal" eboot (not in a prx).
I'm always getting the "Cannot play that file." message.
Can someone help me? :)

Many thanks
Sakya
I've been trying to achieve the same sakya and have the exact same issue.

I forget what the error code I got back from the function was - I'll post it up when I get back from work.
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Post by sakya »

Hi!
Insert_witty_name wrote:I've been trying to achieve the same sakya and have the exact same issue.
I forget what the error code I got back from the function was - I'll post it up when I get back from work.
The function

Code: Select all

atracID = sceAtracSetDataAndGetID(file_buffer, fsize);	
returns tha value -2147352262

Ciaooo
Sakya
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

Yeah that's the one ... 8002013A ... library not linked yet.

Ran a search on that error code and this post came up:

http://forums.ps2dev.org/viewtopic.php?t=6460
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Post by sakya »

Hi!
Many thanks for your help. :)
I red the post, but I'm loading prx from flash, not umd!
My thread is in user mode. I tested also kernel mode, but i get the same error.

I post my code (99,9% taken from Atrac3 Player Sample).

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspumd.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include <pspaudiocodec.h>
#include <pspatrac3.h>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
//PSP_MODULE_INFO&#40;"AT3PLAYER", 0x1000, 1, 1&#41;;
//PSP_MAIN_THREAD_ATTR&#40;0&#41;;
PSP_MODULE_INFO&#40;"AT3PLAYER", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER|PSP_THREAD_ATTR_VFPU&#41;; 

#define psprintf pspDebugScreenPrintf

#define PBP_SIGNATURE	0x50425000
#define RIFF_SIGNATURE	0x46464952

typedef struct FileEntry
&#123;
	char path&#91;512&#93;;
	//u32  signature;
&#125; FileEntry;

#define MAX_FILES 256

FileEntry at3files&#91;MAX_FILES&#93;;

int listAT3Files&#40;char *path, int i, char *filter&#41;
&#123;
	SceUID dfd;

	if &#40;&#40;dfd = sceIoDopen&#40;path&#41;&#41; > 0&#41;
	&#123;
		SceIoDirent dir;

		memset&#40;&dir, 0, sizeof&#40;SceIoDirent&#41;&#41;;

		while &#40;sceIoDread&#40;dfd, &dir&#41; > 0&#41;
		&#123;
			char f_path&#91;512&#93;;

			if&#40;FIO_S_ISDIR&#40;dir.d_stat.st_mode&#41;&#41;
			&#123;
				if &#40;dir.d_name&#91;0&#93; != '.'&#41;
				&#123;
					sprintf&#40;f_path, "%s%s/", path, dir.d_name&#41;;
					i = listAT3Files&#40;f_path, i, filter&#41;;
				&#125;
			&#125;

			else
			&#123;
				SceUID fd;	
				
				if &#40;filter&#41;
				&#123;
					char *f_temp;
					int found;

					f_temp = filter;
					found = 0;

					while &#40;*f_temp&#41;
					&#123;
						if &#40;strstr&#40;dir.d_name, f_temp&#41; != NULL&#41;
						&#123;
							found = 1;
							break;
						&#125;

						f_temp += strlen&#40;f_temp&#41; + 1;
					&#125;

					if &#40;!found&#41;
						continue;
				&#125;	

				strcpy&#40;f_path, path&#41;;
				strcat&#40;f_path, dir.d_name&#41;;

				fd = sceIoOpen&#40;f_path, PSP_O_RDONLY, 0777&#41;;

				if &#40;fd >= 0&#41;
				&#123;
					u32 signature;

					sceIoRead&#40;fd, &signature, 4&#41;;

					if &#40;signature != RIFF_SIGNATURE&#41;
					&#123;
						u32 offsets&#91;8&#93;;
						u32 at3size;

						if &#40;signature != PBP_SIGNATURE&#41;
						&#123;
							sceIoClose&#40;fd&#41;;
							continue;
						&#125;

						sceIoLseek&#40;fd, 8, PSP_SEEK_SET&#41;;
						sceIoRead&#40;fd, offsets, sizeof&#40;offsets&#41;&#41;;

						at3size = offsets&#91;6&#93; - offsets&#91;5&#93;;

						if &#40;at3size == 0&#41;
						&#123;
							sceIoClose&#40;fd&#41;;
							continue;
						&#125;
					&#125;

					strcpy&#40;at3files&#91;i++&#93;.path, f_path&#41;;
					sceIoClose&#40;fd&#41;;					

					if &#40;i == MAX_FILES&#41;
						break;
				&#125;
			&#125;
		&#125;
	&#125;

	sceIoDclose&#40;dfd&#41;;
	return i;
&#125;


u8 file_buffer&#91;6*1024*1024&#93; __attribute__&#40;&#40;aligned&#40;64&#41;&#41;&#41;;

#define N_BLOCKS 16

u16 blocks&#91;N_BLOCKS&#93;&#91;16384&#93;; // 16384 -> more than necessary

SceUID playth=-1, decodeth=-1;
SceUID nonfull, nonempty, mutex;

int atracID;
int startIndex, endIndex;
int decodeEnd;

void debugMessage&#40;const char *fmt, ...&#41;;

int decode_thread&#40;SceSize args, void *argp&#41;
&#123;
	int res, nsamples, end, rem;

	// Producer
	while&#40;!decodeEnd&#41;
	&#123;
		sceKernelWaitSema&#40;nonfull, 1, NULL&#41;;
		sceKernelWaitSema&#40;mutex, 1, NULL&#41;;

		endIndex = &#40;endIndex+1&#41; % N_BLOCKS;
		
		nsamples = 0;
		end = 0;
		rem = -1;

		res = sceAtracDecodeData&#40;atracID, blocks&#91;endIndex&#93;, &nsamples, &end, &rem&#41;;
		
		if &#40;res < 0 || end&#41;
		&#123;
			decodeEnd = 1;
			//psprintf&#40;"decode end, res=%08X\n", res&#41;;			
		&#125;

		sceKernelSignalSema&#40;mutex, 1&#41;;
		sceKernelSignalSema&#40;nonempty, 1&#41;;
	&#125;

	return 0;
&#125;

int play_thread&#40;SceSize args, void *argp&#41;
&#123;
	SceUID fd;
	int fsize, size;
	int channel, chsize;
	u32 signature;
				
	fd = sceIoOpen&#40;&#40;char *&#41;argp, PSP_O_RDONLY, 0777&#41;;
	
	if &#40;fd < 0&#41;
	&#123;
		psprintf&#40;"Error opening file.\n"&#41;;
		return -1;
	&#125;

	sceIoRead&#40;fd, &signature, 4&#41;;

	if &#40;signature != RIFF_SIGNATURE&#41;
	&#123;
		u32 offsets&#91;8&#93;;

		if &#40;signature != PBP_SIGNATURE&#41;
		&#123;
			debugMessage&#40;"File type not supported.\n"&#41;;
			return -1;
		&#125;

		sceIoLseek&#40;fd, 8, PSP_SEEK_SET&#41;;
		sceIoRead&#40;fd, offsets, sizeof&#40;offsets&#41;&#41;;

		size = offsets&#91;6&#93; - offsets&#91;5&#93;;

		if &#40;size == 0&#41;
		&#123;
			debugMessage&#40;"PBP file does not contain AT3 data.\n"&#41;;
			return -1;
		&#125;

		sceIoLseek&#40;fd, offsets&#91;5&#93;, PSP_SEEK_SET&#41;;
	&#125;

	else
	&#123;
		size = 6 * 1024 * 1024;
		sceIoLseek&#40;fd, 0, PSP_SEEK_SET&#41;;
	&#125;

	fsize = sceIoRead&#40;fd, file_buffer, size&#41;;
	sceIoClose&#40;fd&#41;;	

	atracID = sceAtracSetDataAndGetID&#40;file_buffer, fsize&#41;;	
	if &#40;atracID < 0&#41;
	&#123;
		debugMessage&#40;"Cannot play that file. &#40;0x%08x&#41;\n", atracID&#41;;
		return -1;
	&#125;

	sceAtracGetMaxSample&#40;atracID, &chsize&#41;;	
	sceAtracSetLoopNum&#40;atracID, 0&#41;;

	nonfull = sceKernelCreateSema&#40;"nonfull", 0, N_BLOCKS, N_BLOCKS, NULL&#41;;
	nonempty = sceKernelCreateSema&#40;"nonempty", 0, 0, N_BLOCKS, NULL&#41;;
	mutex = sceKernelCreateSema&#40;"mutex", 0, 1, 1, NULL&#41;;

	if &#40;nonfull < 0 || nonempty < 0 || mutex < 0&#41;
	&#123;
		debugMessage&#40;"Error creating semaphores\n"&#41;;
		return -1;
	&#125;

	channel = sceAudioChReserve&#40;0, chsize, PSP_AUDIO_FORMAT_STEREO&#41;;

	if &#40;channel < 0&#41;
	&#123;
		debugMessage&#40;"Error reserving channel\n"&#41;;
		return -1;
	&#125;

	startIndex = -1;
	endIndex = -1;
	decodeEnd = 0;

	decodeth = sceKernelCreateThread&#40;"decode_thread", decode_thread, 0x12, 0x10000, PSP_THREAD_ATTR_USER, NULL&#41;;

	if &#40;decodeth < 0&#41;
	&#123;
		debugMessage&#40;"Error creating decode_thread.\n"&#41;;
		return -1;
	&#125;

	sceKernelStartThread&#40;decodeth, 0, 0&#41;;

	// Consumer
	while &#40;1&#41;
	&#123;
		sceKernelWaitSema&#40;nonempty, 1, NULL&#41;;
		sceKernelWaitSema&#40;mutex, 1, NULL&#41;;

		startIndex = &#40;startIndex + 1&#41; % N_BLOCKS;
		sceAudioOutputBlocking&#40;channel, 0x8000, blocks&#91;startIndex&#93;&#41;;

		if &#40;decodeEnd && startIndex==endIndex&#41;
			break;		

		sceKernelSignalSema&#40;mutex, 1&#41;;
		sceKernelSignalSema&#40;nonfull, 1&#41;;
	&#125;

	sceKernelDelayThread&#40;50000&#41;;

	sceAtracReleaseAtracID&#40;atracID&#41;;
	sceKernelDeleteSema&#40;nonfull&#41;;
	sceKernelDeleteSema&#40;nonempty&#41;;
	sceKernelDeleteSema&#40;mutex&#41;;
	sceAudioChRelease&#40;channel&#41;;	

	//psprintf&#40;"thread end\n"&#41;;

	return 0;
&#125;

void playAT3File&#40;char *file&#41;
&#123;
	decodeEnd = 1;

	sceKernelWaitThreadEnd&#40;playth, NULL&#41;;
	sceKernelWaitThreadEnd&#40;decodeth, NULL&#41;;
	sceKernelDeleteThread&#40;playth&#41;;
	sceKernelDeleteThread&#40;decodeth&#41;; 

	sceKernelDelayThread&#40;50000&#41;;
	
	// IMPORTANT&#58; libatrac3 needs user mode, it won't work in kernel mode
	playth = sceKernelCreateThread&#40;"play_thread", play_thread, 0x12, 0x10000, PSP_THREAD_ATTR_USER, NULL&#41;;

	if &#40;playth < 0&#41;
	&#123;
		debugMessage&#40;"Error creating play_thread.\n"&#41;;
		return;
	&#125;

	sceKernelStartThread&#40;playth, strlen&#40;file&#41;+1, file&#41;;
&#125;

#define GREEN 0x0000FF00
#define WHITE 0x00FFFFFF
#define RED	  0x000000FF

#define START_Y_POSITION	3
#define HELP_Y_POSITION		28
#define DEBUG_Y_POSITION	30	
#define ROOT_STR_N			4
#define N_PAGE_ITEMS		20

char *root_str&#91;ROOT_STR_N&#93; =
&#123;
	"MUSIC FILES",
	"DISC FILES",
	"HOMEBREW FILES",
	"SAVEDATA FILES"
&#125;;

char *dir_paths&#91;ROOT_STR_N&#93; =
&#123;
	"ms0&#58;/PSP/MUSIC/",
	"disc0&#58;/",
	"ms0&#58;/PSP/GAME/",
	"ms0&#58;/PSP/SAVEDATA/"
&#125;;

void debugMessage&#40;const char *fmt, ...&#41;
&#123;
	va_list list;
	char msg&#91;256&#93;;

	pspDebugScreenSetXY&#40;0, DEBUG_Y_POSITION&#41;;
	pspDebugScreenSetTextColor&#40;RED&#41;;

	va_start&#40;list,fmt&#41;;
	vsprintf&#40;msg,fmt,list&#41;;
	va_end&#40;list&#41;;

	psprintf&#40;"%s", msg&#41;;
&#125;

void clearDebug&#40;&#41;
&#123;
	char msg&#91;68&#93;;

	pspDebugScreenSetXY&#40;0, DEBUG_Y_POSITION&#41;;
	pspDebugScreenSetTextColor&#40;RED&#41;;

	memset&#40;msg, ' ', 67&#41;;

	msg&#91;67&#93; = 0;

	psprintf&#40;"%s", msg&#41;;
	
&#125;

void printHelpMessage&#40;&#41;
&#123;
	pspDebugScreenSetXY&#40;0, HELP_Y_POSITION&#41;;
	pspDebugScreenSetTextColor&#40;GREEN&#41;;
	psprintf&#40;"Press X to select/play, O to go back and HOME to exit."&#41;;
&#125;

int mainScreen&#40;&#41;;

void printPage&#40;int j, int npages, int ntotal, int nthispage&#41;
&#123;
	int i;

	pspDebugScreenClear&#40;&#41;;
	printHelpMessage&#40;&#41;;
	
	pspDebugScreenSetXY&#40;0, START_Y_POSITION&#41;;
	for &#40;i = 0; i < nthispage; i++&#41;
	&#123;
		pspDebugScreenSetTextColor&#40;&#40;i == 0&#41; ? GREEN &#58; WHITE&#41;;
		psprintf&#40;"%s\n", at3files&#91;&#40;j*N_PAGE_ITEMS&#41;+i&#93;.path&#41;;
	&#125;

	if &#40;npages > 1&#41;
	&#123;
		psprintf&#40;"\nShowing page %d of %d.\n", j+1, npages&#41;;
		psprintf&#40;"Press R to move to next page. Press L to move to previous page"&#41;;
	&#125;
&#125;

void selectScreen&#40;int dirindex&#41;
&#123;
	SceCtrlData pad;
	int i, j, npages, ntotal, nthispage;
	char *filter;

	pspDebugScreenClear&#40;&#41;;
	pspDebugScreenSetXY&#40;0, START_Y_POSITION&#41;;
	pspDebugScreenSetTextColor&#40;GREEN&#41;;

	filter = ".at3\0.AT3\0.pbp\0.PBP\0.wav\0.WAV\0.toc\0.TOC\0.a3p\0.A3P\0\0";

	if &#40;dirindex == 1&#41;
	&#123;
		// Mount disc if inserted

		if&#40;sceUmdCheckMedium&#40;0&#41; == 0&#41;
		&#123;
			psprintf&#40;"No disc inserted.\nGoing back\n"&#41;;
			sceKernelDelayThread&#40;1200000&#41;;
			mainScreen&#40;&#41;;
		&#125;

		sceUmdActivate&#40;1, "disc0&#58;"&#41;;
		sceUmdWaitDriveStat&#40;UMD_WAITFORINIT&#41;;		
	&#125;

	psprintf&#40;"Listing files. Wait...%s", &#40;dirindex == 1&#41; ? "&#40;search in disc is slow, be patient&#41;\n" &#58; "\n"&#41;;
	ntotal = listAT3Files&#40;dir_paths&#91;dirindex&#93;, 0, filter&#41;;

	if &#40;ntotal == 0&#41;
	&#123;
		psprintf&#40;"No files found.\nGoing back\n"&#41;;
		sceKernelDelayThread&#40;1200000&#41;;
		mainScreen&#40;&#41;;
	&#125;

	if &#40;ntotal < N_PAGE_ITEMS&#41;
	&#123;
		npages = 1;
		nthispage = ntotal;
	&#125;

	else
	&#123;
		npages = ntotal / N_PAGE_ITEMS;

		if &#40;&#40;ntotal % N_PAGE_ITEMS&#41; != 0&#41;
			npages++;

		nthispage = N_PAGE_ITEMS;
	&#125;

	i = 0;
	j = 0;

	printPage&#40;j, npages, ntotal, nthispage&#41;;

	sceCtrlSetSamplingCycle&#40;0&#41;;
	sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_DIGITAL&#41;;

	while &#40;1&#41;
	&#123;
		int keyprocessed;

		keyprocessed = 0;
		
		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;

		if &#40;pad.Buttons & PSP_CTRL_UP&#41;
		&#123;
			if &#40; &#40;&#40;j != &#40;npages-1&#41;&#41; && &#40;&#40;i % N_PAGE_ITEMS&#41; != 0&#41;&#41;
				|| &#40;&#40;j == &#40;npages-1&#41;&#41; && &#40;&#40;i % N_PAGE_ITEMS&#41; != 0&#41;&#41; &#41;
			&#123;
				i--;

				pspDebugScreenSetXY&#40;0, START_Y_POSITION+&#40;i % N_PAGE_ITEMS&#41;&#41;;
				pspDebugScreenSetTextColor&#40;GREEN&#41;;
				psprintf&#40;"%s\n", at3files&#91;i&#93;.path&#41;;

				pspDebugScreenSetTextColor&#40;WHITE&#41;;
				psprintf&#40;"%s", at3files&#91;i+1&#93;.path&#41;;

				keyprocessed = 1;
			&#125;
		&#125;

		else if &#40;pad.Buttons & PSP_CTRL_DOWN&#41;
		&#123;
			if &#40; &#40;&#40;j != &#40;npages-1&#41;&#41; && &#40;&#40;i % N_PAGE_ITEMS&#41; != &#40;N_PAGE_ITEMS-1&#41;&#41;&#41;
				|| &#40;&#40;j == &#40;npages-1&#41;&#41; && &#40;&#40;i % N_PAGE_ITEMS&#41; != &#40;nthispage-1&#41;&#41;&#41; &#41; 
			&#123;
				i++;
				
				pspDebugScreenSetXY&#40;0, START_Y_POSITION+&#40;i % N_PAGE_ITEMS&#41;-1&#41;;
				pspDebugScreenSetTextColor&#40;WHITE&#41;;
				psprintf&#40;"%s\n", at3files&#91;i-1&#93;.path&#41;;

				pspDebugScreenSetTextColor&#40;GREEN&#41;;
				psprintf&#40;"%s", at3files&#91;i&#93;.path&#41;;				

				keyprocessed = 1;
			&#125;
		&#125;

		else if &#40;pad.Buttons & PSP_CTRL_LTRIGGER&#41;
		&#123;
			if &#40;j != 0&#41;
			&#123;
				j--;
				i = j * N_PAGE_ITEMS;

				nthispage = N_PAGE_ITEMS;
				printPage&#40;j, npages, ntotal, nthispage&#41;;
				
				keyprocessed = 1;
			&#125;
		&#125;

		else if &#40;pad.Buttons & PSP_CTRL_RTRIGGER&#41;
		&#123;
			if &#40;j != &#40;npages-1&#41;&#41;
			&#123;
				j++;
				i = j * N_PAGE_ITEMS;

				if &#40; &#40;j == &#40;npages-1&#41;&#41; && &#40;&#40;ntotal % N_PAGE_ITEMS&#41; != 0&#41; &#41;
					nthispage = ntotal % N_PAGE_ITEMS;	

				printPage&#40;j, npages, ntotal, nthispage&#41;;
				
				keyprocessed = 1;
			&#125;
		&#125;

		else if &#40;pad.Buttons & PSP_CTRL_CROSS&#41;
		&#123;
			clearDebug&#40;&#41;;
			playAT3File&#40;at3files&#91;i&#93;.path&#41;;
			keyprocessed = 1;
		&#125;

		else if &#40;pad.Buttons & PSP_CTRL_CIRCLE&#41;
		&#123;
			sceKernelDelayThread&#40;200000&#41;;
			mainScreen&#40;&#41;;
		&#125;		

		sceKernelDelayThread&#40;&#40;keyprocessed&#41; ? 200000 &#58; 50000&#41;;
	&#125;

	sceKernelExitGame&#40;&#41;;
&#125;

int mainScreen&#40;&#41;
&#123;
	SceCtrlData pad;
	int i;

	pspDebugScreenClear&#40;&#41;;
	printHelpMessage&#40;&#41;;

	pspDebugScreenSetXY&#40;0, START_Y_POSITION&#41;;

	for &#40;i = 0; i < ROOT_STR_N; i++&#41;
	&#123;
		pspDebugScreenSetTextColor&#40;&#40;i == 0&#41; ? GREEN &#58; WHITE&#41;;
		psprintf&#40;"%s\n", root_str&#91;i&#93;&#41;;
	&#125;

	i = 0;

	sceCtrlSetSamplingCycle&#40;0&#41;;
	sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_DIGITAL&#41;;

	while &#40;1&#41;
	&#123;
		int keyprocessed;

		keyprocessed = 0;
		
		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;

		if &#40;pad.Buttons & PSP_CTRL_UP&#41;
		&#123;
			if &#40;i != 0&#41;
			&#123;
				i--;

				pspDebugScreenSetXY&#40;0, START_Y_POSITION+i&#41;;
				pspDebugScreenSetTextColor&#40;GREEN&#41;;
				psprintf&#40;"%s\n", root_str&#91;i&#93;&#41;;

				pspDebugScreenSetTextColor&#40;WHITE&#41;;
				psprintf&#40;"%s", root_str&#91;i+1&#93;&#41;;

				keyprocessed = 1;
				
			&#125;
		&#125;

		else if &#40;pad.Buttons & PSP_CTRL_DOWN&#41;
		&#123;
			if &#40;i != &#40;ROOT_STR_N-1&#41;&#41;
			&#123;
				i++;
				
				pspDebugScreenSetXY&#40;0, START_Y_POSITION+i-1&#41;;
				pspDebugScreenSetTextColor&#40;WHITE&#41;;
				psprintf&#40;"%s\n", root_str&#91;i-1&#93;&#41;;

				pspDebugScreenSetTextColor&#40;GREEN&#41;;
				psprintf&#40;"%s", root_str&#91;i&#93;&#41;;				

				keyprocessed = 1;
			&#125;
		&#125;

		else if &#40;pad.Buttons & PSP_CTRL_CROSS&#41;
		&#123;
			sceKernelDelayThread&#40;200000&#41;;
			selectScreen&#40;i&#41;;
		&#125;
		
		sceKernelDelayThread&#40;&#40;keyprocessed&#41; ? 200000 &#58; 50000&#41;;
	&#125;

	sceKernelExitGame&#40;&#41;;
	return 0;
&#125;

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41;
&#123;
    sceKernelExitGame&#40;&#41;;

	return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41;
&#123;
    int cbid;
    cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
    sceKernelRegisterExitCallback&#40;cbid&#41;;
    sceKernelSleepThreadCB&#40;&#41;;

	return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41;
&#123;
    int thid = 0;
    thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, THREAD_ATTR_USER, 0&#41;;
    if &#40;thid >= 0&#41;
	sceKernelStartThread&#40;thid, 0, 0&#41;;
    return thid;
&#125;

//Load and start prx&#58;
int loadPRX&#40;&#41;
&#123;
    SceUID uidAudio;
	SceUID uidAtrac;
    uidAudio = pspSdkLoadStartModule&#40;"flash0&#58;/kd/audiocodec.prx", PSP_MEMORY_PARTITION_KERNEL&#41;;
	if&#40;uidAudio < 0&#41;
    &#123;
        printf&#40;"Couldn't load audiocodec %08X\n", uidAudio&#41;;
        return -1;
    &#125; 
    uidAtrac = pspSdkLoadStartModule&#40;"flash0&#58;/kd/libatrac3plus.prx", PSP_MEMORY_PARTITION_USER&#41;;
	if&#40;uidAtrac < 0&#41;
    &#123;
        printf&#40;"Couldn't load libatrac3plus %08X\n", uidAtrac&#41;;
        return -1;
    &#125; 
	sceKernelExitThread&#40;0&#41;; 
	return 0;
&#125;


// Main&#58;
int main&#40;&#41; &#123;
    pspDebugScreenInit&#40;&#41;;
    SetupCallbacks&#40;&#41;;

    SceUID loadPRXid = sceKernelCreateThread&#40;"LoadPRX", loadPRX, 0x16,
	               0x00010000, PSP_THREAD_ATTR_USER, NULL&#41;;
	if &#40;loadPRXid < 0&#41;
    &#123;		
	    return -1;
     &#125;

	SceUID thid = sceKernelCreateThread&#40;"Atrac3Player", mainScreen, 0x16,
	              0x00010000, PSP_THREAD_ATTR_USER, NULL&#41;;

    if &#40;thid < 0&#41;
    &#123;		
	    return -1;
     &#125;

    sceKernelStartThread&#40;thid, 0, 0&#41;;
    sceKernelSleepThread&#40;&#41;;

    return 0;
&#125;
Ciaooo
sakya
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

A couple of things I noticed after a quick scan of your code.

You'll need kernel mode to load the modules from flash.

You create the loadPRX thread - but never actually start it.

I tried your code with the errors above corrected but I still receive the libraries not linked error.

Also tried it with loading the PRX off a UMD - same result.
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Post by sakya »

Ciao! :)

Many thanks for your help. I've also tried kernel mode and before adding the thread (ooops I forgot to start it!) I loaded the prx in the main function, with the same error.
I'm very interested in atrac3 playback, I hope to find a solution. :)

Ciaooo
Sakya
fergie4000
Posts: 25
Joined: Fri Jan 19, 2007 3:03 pm

Post by fergie4000 »

is it just me being stupid or can this not play long at3 files like the radio stations in gta for example
JoRDozZzz
Posts: 9
Joined: Thu Apr 05, 2007 6:23 am
Contact:

Post by JoRDozZzz »

hello everybody,
i came via google on this forum and i saw this thread about a Simpel Atrac3 Player. I'm coding in c/c++ for some weeks, so i'm a n00b.

but i've my first homebrew, but i really would like to hear music when in homebrew. If you know the program Flash Agent, made by Hallo007, yoou know what i mean.

Now is my thing, that i would like to know what the easiest way is to put music in your program.

i've downloaded moonlight's atrac3player, but i don't know if this is the easiest way.

Yesterday i tried to make this atrac3player with my own music in my own dir, i thought it was ok, but when i tested it, it doens't work and i didn't saw my own music in the program. and Yes i do have put the at3 file in the correct folder.

Please can someone help me with this atrac3player or maybe an other way to put music in your homebrew.

When I have music on the background in my own homebrew, i do some last codes en then i'll release it.

Yesterday i tried to put an image in my homebrew and that works, so music is the latest thing.

if you can help me please give a reaction here or send me an email:
jordozzzz@gmail.com

Sorry for my English,

Thanks you very very much for help,

JoRDozZzz
C/C++ Noob/Beginner
JoRDozZzz
Posts: 9
Joined: Thu Apr 05, 2007 6:23 am
Contact:

Post by JoRDozZzz »

someone else gave me a tutorial of adding sound
Link

i've done this and now i have music playback on the background in my homebrew.. xD xD

ty,
// JoRDozZzz[/url]
C/C++ Noob/Beginner
VGV
Posts: 3
Joined: Tue Jun 12, 2007 9:43 pm

Post by VGV »

hello from another newbe :)

i have same problem as sakya and found a solution.

1)

Code: Select all

PSP_MODULE_INFO&#40;"SOUND_TEST", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER|PSP_THREAD_ATTR_VFPU&#41;;
2)

Code: Select all

  pspSdkLoadStartModule&#40;"ms0&#58;/audiocodec.prx", PSP_MEMORY_PARTITION_KERNEL&#41;;
	pspSdkLoadStartModule&#40;"ms0&#58;/libatrac3plus.prx", PSP_MEMORY_PARTITION_USER&#41;;
it means u will need to extract our modules from some game.
Vincent_M
Posts: 73
Joined: Tue Apr 03, 2007 4:16 am

Post by Vincent_M »

You could run into legal issues because you are using software only licensed developers can 'have'. It is official software of Sony, and by having it on a personal storage medium not licensed by Sony would result in legal issues from what I've heard. It's been said before anyway, what I've seen others do is just have a UMD disk in the PSP, and load the modules off a legitimate game. I'm not playing good-cop, bad-cop, but I'm just saying that Sony is looking for all the little legal things to stop non-licensed developers. This would be a precaution. Having those raw files sitting on their memorystick could be bad legally.
Post Reply