sceAudiocodec anyone ?

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

Moderators: cheriff, TyRaNiD

hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

sceAudiocodec anyone ?

Post by hitchhikr »

I noticed that this driver (which purpose is to decode atrac3 datas into PCM, which could prove to be most useful as it operates on the media engine) is available within gta via the atrac3plus library but as the library itself is loaded in user space (0x8E65500 on 2.6) it may be overwritten so i thought about using the driver directly, the relevant syscalls used by gta are (+ some others for streaming from the umd):

sceAudiocodec_9d3f790c located at: 0x08E68CE4 (8 bytes)
sceAudiocodecInit located at: 0x08E68CEC (8 bytes)
sceAudiocodecDecode located at: 0x08E68CF4 (8 bytes)
sceAudiocodecGetEDRAM located at: 0x08E68CFC (8 bytes)
sceAudiocodecReleaseEDRAM located at: 0x08E68D04 (8 bytes)

I've started to disassemble both the library and the driver and found out a way to use sceAudiocodec_9d3f790c, sceAudiocodecGetEDRAM & sceAudiocodecInit by using them with like that:

Code: Select all

	// These two first ones are called during sceAtracStartEntry
	ret = sceAudiocodec_9d3f790c(At3_Buffer, 0x1001);
	ret = sceAudiocodecGetEDRAM(At3_Buffer, 0x1001);
	ret = sceAudiocodecInit(At3_Buffer, 0x1001);
At3_Buffer is a 328 bytes buffer (probably a structure).
0x1001 is the type of stream to decode (0x1001 = AT3 / 0x1000 = AT3+).
Everything goes fine until and each function return a 0 value (maybe they shouldn't ?) but sceAudiocodecDecode doesn't work and returns 0x807f0002 error value), i looked in the memory dump to see how the atrac3 library initialized that At3_Buffer but no matter what i tried it still doesn't work.

The first thing i can't figure out yet is where to pass the addresses of the at3 block to decode and where it'll be decoded.

From what i've seen, there is 4 blocks used by the attrac3 grouped by 2 depending on the passed ID (prolly 2 for the atrac3 & 2 for the atrac3plus which seem to be different formats).

Most probably At3_Buffer must be filled by hand with some values but i don't know which ones yet.

The functions themselves write datas to the buffer:

sceAudiocodec_9d3f790c:
05012801 at offset 0
00003de0 at offset 0x10

sceAudiocodecGetEDRAM:
001dfbc0 at offset 0xc
001dfb94 at offset 0x68

sceAudiocodecInit:
0000ac44 at offset 0x2c
00001000 at offset 0x30

Anyone have some experience with this one or is interested to work on it too ?
weak
Posts: 114
Joined: Thu Jan 13, 2005 8:31 pm
Location: Vienna, Austria

Post by weak »

maybe you want to take a look at this topic ?
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

I'm well aware of this thread but i'm talking about playing atrac3 file in USER mode which isn't what moonlight's example is doing afaik (it doesn't work on my 2.6 at least).

You see, i plan to release stuff for that little black box and leaving it's second processor sitting there and doing nothing is totally unacceptable to me and as a bottom condition it must be compatible with 2.01+ & 1.5 otherwise there's no point in releasing anything.
weak
Posts: 114
Joined: Thu Jan 13, 2005 8:31 pm
Location: Vienna, Austria

Post by weak »

actually i already have some code (thx tyr) that should load the modules and fix the imports in usermode.

just haven't found the time and a volunteer (with fw 2.x and gta) to test it. wanna volunteer? ;)
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

Sure.
weak
Posts: 114
Joined: Thu Jan 13, 2005 8:31 pm
Location: Vienna, Austria

Post by weak »

thx, you got pm.
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

Nothing reached the box yet.
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

weak wrote:actually i already have some code (thx tyr) that should load the modules and fix the imports in usermode.

just haven't found the time and a volunteer (with fw 2.x and gta) to test it. wanna volunteer? ;)
GTA should have the to have the atrac3 library loaded like all games do (you know, in user mode you can load almost everything from a disc). So there must be a way without using the sceAudioCodec, although it would be educational to find how to use it.

EDIT: ok i didn't read all the first message. You say that the library could be overwritten. But maybe it can be loaded twice like it's possible with some modules.
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

I didn't try to use the atrac3 which is in memory because this lib uses Kernel_Library which is loaded in user space and is apparently overwritten.

Also i don't know how to load and start modules files from the umd (the method used in your atrac3 example doesn't work even when i tried to load them from the umd),
i'm not even sure that gta does load these two prx because libatrac3plus & audiocodec are already present in the firmware so they may just be loaded at startup by the vsh or something (it may load sc_sascore.prx tho as it doesn't seem to be included in the fw).

+ libatrac3 eats memory.
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

No, the atrac3 libraries and the rest of prx's in a game are always loaded from the disc. I don't know if they use the SceKernelLMOption structure, but for sure that you can load those modules from a disc in user mode.
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

Ok here we go, this is the way the prx are loaded in GTA:

Code: Select all

	SceKernelLMOption Load_Option;
	SceKernelSMOption Start_Option;
	SceUID hModule_ID;
	SceUID hModule;
	SceUID hFile;
	int Status;

	// Located at 0x229980
	memset(&Load_Option, 0, sizeof(SceKernelLMOption));
	Load_Option.size = sizeof(SceKernelLMOption);
	Load_Option.mpidtext = PSP_MEMORY_PARTITION_USER;
	Load_Option.mpiddata = PSP_MEMORY_PARTITION_USER;
	Load_Option.access = 1;   // ???

	// Located at 0x229BCC
	memset(&Start_Option, 0, sizeof(SceKernelSMOption));
	Start_Option.size = sizeof(SceKernelSMOption);
	Start_Option.stacksize = 16 * 1024;
	Start_Option.priority = 32;

	hModule_ID = sceIoOpen("disc0:/PSP_GAME/USRDIR/PRX2_0_0/MOD/LIBATRAC3PLUS.PRX", PSP_O_RDONLY, 0);
	hModule = sceKernelLoadModuleByID(hModule_ID, 0, &Load_Option);
	int ret = sceKernelStartModule(hModule, 0, NULL, &Status, &Start_Option);
And this doesn't work, sceKernelLoadModuleByID returns error 80020139 (the only reference to this error i could find on the web is: 80020139 - exclusive load).
I guess the modules can't be opened twice but apparently i can't stop / unload them anyway so this bring me back to the start of this topic.
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

Oki, i found out how to replay atrac3 files on 2.6, so never mind, thanks for the help.
weak
Posts: 114
Joined: Thu Jan 13, 2005 8:31 pm
Location: Vienna, Austria

Post by weak »

hitchhikr wrote:Oki, i found out how to replay atrac3 files on 2.6, so never mind, thanks for the help.
would be nice if you could tell us how exactly :)
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

There you have it:

http://perso.orange.fr/franck.charlet/t ... Replay.zip

I reproduce here the content of the readme.txt in extenso:

ATRAC3 files replay preview for firwmware 1.5 & GTA
Written by hitchhikr/Neural.

It's only a preview (so DON'T use it yet !),
I don't know if it works on 1.5 yet (tell me if it does or not).

It does some dirty hacks to obtain sceAudioCodec NIDs that should be fixed in fanjita's eloader.

Notice that this won't work if run from the menu, the emenu--.pbp need to be replaced with our file
as it erases the atrac3 library before we could retrieve the syscalls of the sceAudioCodec.

So:

- pspAudioCodec_Lib/libpspAudioCodec.a should be copied in your \pspdev\psp\sdk\lib.

- When running under GTA \AT3_Replay\AT3_Replay\EBOOT.PBP should replace the emenu--.pbp (or whatever it is called).
located on the memory stick in \PSP\eloader.

- "Makke - Artura.at3" must copied in ms0:/

It must be used like this:
--------------------------------------------
#include "AT3.h"
#include "AT3.c"

#define FILENAME "ms0:/Makke - Artura.at3"
#define FILENAME_LENGTH 2288712
unsigned char Tune[FILENAME_LENGTH] __attribute__((aligned(16)));

// Load the file & init the replay
SceUID handle = sceIoOpen(FILENAME, PSP_O_RDONLY, 0);
sceIoRead(handle, Tune, FILENAME_LENGTH);
sceIoClose(handle);
AT3_Init(Tune, FILENAME_LENGTH, 1);

// Start replaying
AT3_Play(1);

// Free the resources
AT3_Stop();

--------------------------------------------

Makke - Artura.at3 (atrac3 132 kbps).
Copyright (c) 2005 Marcus Nilsson (http://makke.c64.org/).

I'd like to know if this is working on 1.5 and with GTA too, of course (if it doesn't within your GTA, things should be resolved as soon as the nids are implemented in the eloader, i think).
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

hey thanx very much that is very cool how you
can play at3 in usermode ....very good indeed
just tested on 1.5 ...and no it dont work ...simply
the sceAudioCodec NIDs are not the same for 1.5

this can be easily fixed ...but you do not include main.c
source file so please do post that soon :)
and Makefile ....libpspAudioCodec you provide is excellent
10011011 00101010 11010111 10001001 10111010
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

Yeah i noticed there's trouble on 1.5, what do you mean the nids are differents ? Shouldn't the vsh fix the syscalls from the nids when loading the pbp or does it need the driver to be loadded & started manually ?

I think the problem may come from somewhere else.

Actually, you can easily recreate a main.c.
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

Uploaded a new version, hopefully this one will work a little bit better. (also i added the main.c)
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

Good job!! Very educative :)
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

indeed
great :)
10011011 00101010 11010111 10001001 10111010
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Re: sceAudiocodec anyone ?

Post by moonlight »

hitchhikr wrote: At3_Buffer is a 328 bytes buffer (probably a structure).
0x1001 is the type of stream to decode (0x1001 = AT3 / 0x1000 = AT3+).
0x1002 = MP3

It seems that it may be possible to decode MP3 through hardware :)
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

That would be kick-ass :)
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

0x1002 = MP3

It seems that it may be possible to decode MP3 through hardware :)
There seem to be some handling for a 0x1004 type too, so assuming the xmb is using the audiocodec.prx to decode all audio files when replaying them that type may be for WMA, the structure passed to the driver is surely different, tho.

Notice that GTA loads videocodec.prx, mpegbase.prx & mpeg.prx (the later one isn't present in the firmware and i don't know how to access the first two but gta probably accesses to them via mpeg.prx (sceMpeg)).

I released a new version of the replay available here:
http://perso.orange.fr/franck.charlet/AT3_Replay.zip

I modified the datas passed to the audiocodec driver to match those produced by the libatrac3plus, hopefully it'll be more compatible now.

I'd like to know if this one work on other psp than mine (2.6),
thanks.
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

hitchhikr wrote: I released a new version of the replay available here:
http://perso.orange.fr/franck.charlet/AT3_Replay.zip

I modified the datas passed to the audiocodec driver to match those produced by the libatrac3plus, hopefully it'll be more compatible now.

I'd like to know if this one work on other psp than mine (2.6),
thanks.
Still no go on 1.5 for me.

I'd really like to see the ability to play back at3 on all firmwares.
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

It would help to know what's going on with the 1.5, like is there something displayed or moving on the screen ?

What are the return values of sceAudiocodec_9d3f790c, sceAudiocodecGetEDRAM, sceAudiocodecInit & sceAudiocodecDecode ?

Also it would be good to know if audiocodec.prx is really loaded as excepted.
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

Never mind, i think i figured out the problem.
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

Ok, i've uploaded a new version (same url: http://perso.orange.fr/franck.charlet/AT3_Replay.zip) this one should work (crossing fingers).
Gizmo
Posts: 14
Joined: Sat Feb 05, 2005 1:54 am

Post by Gizmo »

Tryed this on 1.5 (copied the eboot folders into GAME and the at3 in the MS root). All I get is a black screen, no sound - no reaction to any button. Doesn't shut down automatically so I have to hold the power button for a while.

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

Post by moonlight »

IMPORT_FUNC "sceAudioCodec",0xDEADBEEF,sceAudiocodec_9d3f790c
?
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

moonlight wrote:
IMPORT_FUNC "sceAudioCodec",0xDEADBEEF,sceAudiocodec_9d3f790c
?
It's just used as a place holder to avoid confusing the search routine. The stategy is to load the audiocodec.prx first then libatrac3plus.prx, let the kernel to fix the syscalls then search for them in the atrac3 library loaded in user mode & retrieve them (they're already loaded in gta). While it works perfectly on 2.6, it doesn't on 1.5 because apparently i need kernel access to load the prx but i can't use them in such mode and need an user app to do so, i think moving the replay code into an user mode prx will work fine, i didn't know that & that's wicked shit IMHO.
hitchhikr
Posts: 83
Joined: Sat Feb 04, 2006 3:33 pm

Post by hitchhikr »

http://perso.orange.fr/franck.charlet/AT3_Replay.zip

Both the .at3 and the prx must be copied in ms0:/

If it doesn't work on 1.5 i'd really really really like someone skilled enough to tell me what's happening with this bloody firmware.
Post Reply