ATRAC3 Player Sample

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

Moderators: cheriff, TyRaNiD

patpsp
Posts: 31
Joined: Tue Oct 25, 2005 5:24 pm

Post by patpsp »

Very interesting !!

Do you think, it can be easy to use in the future ? For example, simple functions in the pspsdk like at3_init(), at3_play(char * music), at3_stop() ?

I've tried your sample n°2, it works like a charm :)
Just a little bug, when i browse to the music it has detected, some music are shown in 2 lines, and the selection with up and down, doesn't work properly.

Do you have an idea whether this lib can be less CPU demanding than libmad, or perhaps, whether it uses the ME ?

Is at3 format legal ?
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

it does indeed use 0% zero load on main cpu/allegrex
...why?..because libatrac3 uses the ME to handle the
load so this is by far the best remedy for those looking
for background music to add to their games ...and it
works a treat :)

as for creating your own library of at3_play() etc...
that shouldnt be a problem for you at all ...i mean
i wonder what this does

Code: Select all

void playAT3File(char *file)
;)
10011011 00101010 11010111 10001001 10111010
patpsp
Posts: 31
Joined: Tue Oct 25, 2005 5:24 pm

Post by patpsp »

I'm not sure whether i understand your answer.
My question was about the the possibility to write a library like libmad, using the libatrac3 stuff, integrated to the pspsdk.
When i look at the moonlight's sample 2, I see that it generates a prx module, which is not easy to implement in another project.

From what i understood, this library would consist on :
(i simplify the functions, I just want to understand whether this could work or not)

Code: Select all

- int Init_AT3() : 
  // load necessary modules
  pspSdkLoadStartModule("flash0:/kd/audiocodec.prx", PSP_MEMORY_PARTITION_KERNEL);
  pspSdkLoadStartModule("flash0:/kd/libatrac3plus.prx", PSP_MEMORY_PARTITION_USER);
        return 1;

- int playAT3File(char *file) :
  // generate a thread, and return his id
  int playth = sceKernelCreateThread("play_thread", play_thread, 0x12, 0x10000, PSP_THREAD_ATTR_USER, NULL);

  if (playth >= 0) sceKernelStartThread(playth, strlen(file)+1, file);
  return playth;

- int stopAT3File(int id) :
  sceKernelDeleteThread(id);
patpsp
Posts: 31
Joined: Tue Oct 25, 2005 5:24 pm

Post by patpsp »

Sorry, to post again here, but I really think this libatrac3 can really be a must in homebrew devs.

Do someone currently work on the full pspsdk integration of this lib ?
pspwill
Posts: 51
Joined: Thu Nov 17, 2005 8:07 am

Post by pspwill »

do you think we could use the same method of this to play the video off of umd videos?
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

read the source people!
you can easily integrate this into your
own homebrew! ...its all there and there is
already pspatrac3.h in pspsdk !

pspwill: umd videos do use this format for audio
but the video container still needs to be parsed
and so that is not a possibility right now ...but when
more about pmf is learned no problem ;)
10011011 00101010 11010111 10001001 10111010
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

Post by weltall »

i did some mods to this:
-Added support to write at3 decoded data
to uncompressed wav
-Added selection between play only and
saving decoded data to wav
-Added a playlist mode
-extended buffer to 12mb

http://weltall.consoleworld.org/PSP/AT3PLAYERMOD02.rar
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

nice playlist mod :)
that is what people should be doing
good work
10011011 00101010 11010111 10001001 10111010
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

Some more functions:

Code: Select all

/**
 * Gets the number of samples of the next frame to be decoded.
 *
 * @param atracID - the atrac ID
 * @param outN - pointer to receives the number of samples of the next frame.
 *
 * @returns < 0 on error, otherwise 0
 *
*/
int sceAtracGetNextSample&#40;int atracID, int *outN&#41;;

/**
 * Gets the maximum number of samples of the atrac3 stream.
 *
 * @param atracID - the atrac ID
 * @param outMax  - pointer to a integer that receives the maximum number of samples.
 *
 * @returns < 0 on error, otherwise 0
 *
*/
int sceAtracGetMaxSample&#40;int atracID, int *outMax&#41;;
I hope someone with access to the svn adds them to pspatrac3.h

Rewritten the sample with the use of sceAtracGetMaxSample to find the appropiated channel size.

This ugly code:

Code: Select all

// VERY UGLY way to find an appropiated channel size
	t1024 = 0;
	t2048 = 0;

	for &#40;i = 0; i < 20; i++&#41;
	&#123;
		int nsamples, end, rem;

		sceAtracDecodeData&#40;atracID, blocks&#91;0&#93;, &nsamples, &end, &rem&#41;;

		if &#40;nsamples == 1024&#41; t1024++;
		else if &#40;nsamples == 2048&#41; t2048++;
	&#125;

	sceAtracReleaseAtracID&#40;atracID&#41;;
	atracID = sceAtracSetDataAndGetID&#40;file_buffer, fsize&#41;;

	if &#40;atracID < 0&#41;
	&#123;
		debugMessage&#40;"Unknown error.\n"&#41;;
		return -1;
	&#125;

	if &#40;t1024 > t2048&#41;
		chsize = 1024;
	else
		chsize = 2048;
replaced with a simple line :)

Code: Select all

sceAtracGetMaxSample&#40;atracID, &chsize&#41;;
http://www.megaupload.com/?d=87UL06DC


Next thing is try to find the way of at least playing the sound from pmf files.
Last edited by moonlight on Mon May 01, 2006 8:08 pm, edited 1 time in total.
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

:)
buggy bug report:
when playing a atrac3 file from video umd
located at this location disc0:/UMD_VIDEO/SND0.AT3
it will playback once then again when user selects to
playback only once then it will stop after playback 2x

thought youd like to know
nice big improvement in source :)
Last edited by dot_blank on Mon May 01, 2006 6:51 pm, edited 2 times in total.
10011011 00101010 11010111 10001001 10111010
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Added the new functions to the sdk.
patpsp
Posts: 31
Joined: Tue Oct 25, 2005 5:24 pm

Post by patpsp »

dot_blank wrote:read the source people!
you can easily integrate this into your
own homebrew! ...its all there and there is
already pspatrac3.h in pspsdk !
I've read the source, and my question shows it.
This forum is about "Homebrew PS2 & PSP Development Discussions", so I suppose that I can ask questions, hoping that someone could answer and help. If it is easy for you, why not sharing your knowledge ? Isn't the aim of this forum ?
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

Post by weltall »

after this sceAtracGetMaxSample(atracID, &chsize);
you can find sceAtracSetLoopNum(atracID, 1);
replace with sceAtracSetLoopNum(atracID, 0);

and it replay only one time
thanks to dot_blank
Last edited by weltall on Tue May 02, 2006 5:45 am, edited 2 times in total.
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

weltall wrote:after this sceAtracGetMaxSample(atracID, &chsize);
you can find sceAtracSetLoopNum(atracID, 1);
replace with sceAtracSetLoopNum(atracID, 0);

and it replay only one time
thanks to dot_black
thanks :) updated the link with that fix and using the new definitions in the pspatrac3.h header.
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

patpsp: what is your question exactly?
what is your error, what do you want to accomplish?

if its just playing back an atrac3 file the source has
obvious atrac3 playback function and buffer setup

you need to help me to help you
10011011 00101010 11010111 10001001 10111010
patpsp
Posts: 31
Joined: Tue Oct 25, 2005 5:24 pm

Post by patpsp »

Thanks dot_blank to be more comprehensive. I really appreciate this.

My question was about the possibility to make a library like libmad, which handles all needed for reading atrac3.

The goal is to be able to link any homebrew to this library and use simple functions like libmad offers.

I proposed a prototype some posts ago, and just wanted to know whether it could work.

Code: Select all


- int Init_AT3&#40;&#41; &#58;
  // load necessary modules
  pspSdkLoadStartModule&#40;"flash0&#58;/kd/audiocodec.prx", PSP_MEMORY_PARTITION_KERNEL&#41;;
  pspSdkLoadStartModule&#40;"flash0&#58;/kd/libatrac3plus.prx", PSP_MEMORY_PARTITION_USER&#41;;
        return 1;

- int playAT3File&#40;char *file&#41; &#58;
  // generate a thread, and return his id
  int playth = sceKernelCreateThread&#40;"play_thread", play_thread, 0x12, 0x10000, PSP_THREAD_ATTR_USER, NULL&#41;;

  if &#40;playth >= 0&#41; sceKernelStartThread&#40;playth, strlen&#40;file&#41;+1, file&#41;;
  return playth;

- int stopAT3File&#40;int id&#41; &#58;
  sceKernelDeleteThread&#40;id&#41;;
Thanks for your help.
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

main.c of PRX of atrac3 sample has all the
functions that you should need and creating
your own library is a real snap just create your
own lib with functions in source .c files and the
proper prototypes in a similar named header file
then of course include that header file in your source
.c file and then then include header file in your app
...all functions are there all you have to do is extract
them and alter to your liking ....do not extract the
obvious thread stuff like play_thread as that
should be user specific for whichever app you
are working on

...play around with it and youll see creating your own
library is a snap ...if you dont get it by a weeks end
then maybe someone will provide a easy ready made
library ;)
10011011 00101010 11010111 10001001 10111010
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

About the perfomance... I've set the processor to only 12/6 Mhz and it's playing fine :)) The search of files is slower, but the play is really good :)
__count
Posts: 22
Joined: Thu Mar 23, 2006 8:40 pm

Post by __count »

moonlight wrote:About the perfomance... I've set the processor to only 12/6 Mhz and it's playing fine :)) The search of files is slower, but the play is really good :)
That's awesome :)

Do you think it would be difficult to stream at3's (instead of loading the whole thing in a static buffer)?
patpsp
Posts: 31
Joined: Tue Oct 25, 2005 5:24 pm

Post by patpsp »

dot_blank -> thanks for answer. I'm trying. Do you think i can totally achieve in not using the prx stuff ?

moonlight -> very good news. thanks again for your work.
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

__count wrote:
moonlight wrote:About the perfomance... I've set the processor to only 12/6 Mhz and it's playing fine :)) The search of files is slower, but the play is really good :)
That's awesome :)

Do you think it would be difficult to stream at3's (instead of loading the whole thing in a static buffer)?
It has to be possible. The game that i reversed didn't load the whole file, but only a part, and then add more data to the buffer, i have to do some more reverse on that, there are a lot more of functions in libatrac3plus.
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

streaming would be probably top of my list :)
10011011 00101010 11010111 10001001 10111010
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Hi,

I had a question: Is atrac3 usable for sound effects? i mean doing mp3 for this is not usable due to the late play response, wav however almost executes directly so that would be good (if there were libraries existing...) so is atrac3 faster then mp3?

greets Ghoti
zilt
Posts: 45
Joined: Tue Feb 21, 2006 11:59 pm
Location: Ontario, Canada
Contact:

Post by zilt »

moonlight: Any luck with figuring out atrac3 streaming? I'm adding music/sound support to my 3d world ( www.antimass.org/zilt ) based on your atrac3sample3.zip and the streaming would help free up memory. Thanks,

Zilt
"We are dreamers, shapers, singers, and makers. We study the mysteries of laser and circuit, crystal and scanner, holographic demons and invocations of equations. These are the tools we employ and we know... many things." -- Elric, B5
Kojima
Posts: 275
Joined: Mon Jun 26, 2006 3:49 am

Post by Kojima »

I see that it loads some roms from the flash. Is there any chance of bricking if my program crashes cos of this? (just got my psp so I'm in that 'too scared to run almost anything incase it bricks my psp' phase)
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

Loading modules from the flash won't destroy your psp. It's what the firmware is constantly doing, the modules of the firmware are not loaded by magic.

That's what i call paranoia in its maximum level.
Kojima
Posts: 275
Joined: Mon Jun 26, 2006 3:49 am

Post by Kojima »

I didn't actually know modules were loaded from flash, like I said I just got my psp so it's all new to me.
zilt
Posts: 45
Joined: Tue Feb 21, 2006 11:59 pm
Location: Ontario, Canada
Contact:

Post by zilt »

Nevermind about the streaming - I've worked around it by adding a separate thread that keeps a double buffer filled ( reduced the internal buffer down to 512k for dual atrac3 streams). I've also found that I can blend 2 concurrent atrac3 samples ( on separate channels ) with almost no drop in 3d framerate.

When I try starting a third atrac stream, I get 0x80630003 from sceAtracSetDataAndGetID() which I'm assuming means no more atrac streams left or something.

I also changed the dual producer/consumer thread pattern into a single thread ( though each atrac stream is it's own thread ). Thanks very much again for the atrac3 sample. I'll be releasing all my client code ( and keeping it in a svn repos ) after the next release.
"We are dreamers, shapers, singers, and makers. We study the mysteries of laser and circuit, crystal and scanner, holographic demons and invocations of equations. These are the tools we employ and we know... many things." -- Elric, B5
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

Sorry, I forgot totally to continue researching the atrac3 library since i was busy with other things.

The last thing i remember was looking to a couple of functions, sceAtracAddStreamData and other that i don't remember now.

I remember also that the addstreamdata was not what i expected. I expected a pointer in its parameters, but all of them were integer.

I hope this can help someone wanting to finish the job.
subbie
Posts: 122
Joined: Thu May 05, 2005 4:14 am

Post by subbie »

I have a somewhat stupid question.

Can this...

pspSdkLoadStartModule("flash0:/kd/audiocodec.prx", PSP_MEMORY_PARTITION_KERNEL);
pspSdkLoadStartModule("flash0:/kd/libatrac3plus.prx", PSP_MEMORY_PARTITION_USER);

be executed in an app that is in user mode or must I launch it the same way the demo does?

For some reason my code crashes around thies lines and my app is just in user mode.
Post Reply