Vorbis streaming on ME processor

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

Moderators: cheriff, TyRaNiD

Post Reply
davidgf
Posts: 21
Joined: Mon Aug 31, 2009 10:05 pm

Vorbis streaming on ME processor

Post by davidgf »

Hi everybody!

I'm trying to decode OGG vorbis on the ME processor using the mediaengine.prx that a great coder posted here.

I'm facin some problems because of the malloc / free functions that ogg vorbis uses. I had some crashes at malloc_lock function I guess because malloc wasn't written to be shared across the two processors.

One of the questions I have is sce functions for Writing Back and Invalidating Cache work on the ME processor? How can I write the cache data and invalidate it?

The solution that is working for me now is:

ov_open_callback and ov_read always being called in the ME. The read callback just copies data from the memory (it doesn't access the disk).
All the data is read by one thread on the main processor and written bypassing the cache. Also the decoded data is copied the same way.

But I have some problems with the malloc function. When I turn off my debugging functions (like a printf to a file on ms) the ME just hangs and hungs the psp.

Maybe the solution is to change the ogg_malloc function and write my own malloc which uses the ME 2M memory?

By the way it seems to work well, I just need to make it solid.
And another question, how can I debug on the ME! I cannot open or write files without hanging it! Is it normal or I am doing something weird?

Thanks in advance!
crazyc
Posts: 408
Joined: Fri Jun 17, 2005 10:13 am

Re: Vorbis streaming on ME processor

Post by crazyc »

davidgf wrote:I'm facin some problems because of the malloc / free functions that ogg vorbis uses. I had some crashes at malloc_lock function I guess because malloc wasn't written to be shared across the two processors.
The libc malloc uses OS services and so is only available on the SC. You'll have to write your own malloc for the ME.
davidgf wrote:One of the questions I have is sce functions for Writing Back and Invalidating Cache work on the ME processor? How can I write the cache data and invalidate it?
I wrote cache management code for the ME. It's posted in the ME thread.
davidgf wrote:By the way it seems to work well, I just need to make it solid. And another question, how can I debug on the ME! I cannot open or write files without hanging it! Is it normal or I am doing something weird?!
You cannot access any OS services on the ME (even if you could, the ME lacks access to the memorystick MMIO), so no disk access. You'll have to write debugging output to a memory buffer accessible to the SC.
davidgf
Posts: 21
Joined: Mon Aug 31, 2009 10:05 pm

Post by davidgf »

Thanks!!! This answers all my questions.
I've decided to use stb_vorbis, which is a vorbis decoder implementation that you can choose to use malloc or it's own allocator in a custom buffer.

Now I have a little problem. I have a temp buffer for reading raw files, this buffer is in the main memory and I use uncached pointer. That's ok.
But if I place the buffer (around 32KB) in the ME stack, it fails in memcpy, at writing to this buffer.

As I understand the ME memory is visible and accessible from the main CPU, and it's writeable, isn't it?

Why is it failing?

Thanks again!
davidgf
Posts: 21
Joined: Mon Aug 31, 2009 10:05 pm

Post by davidgf »

Don't know how I solved all my problems. I'll explain a little bit so if someone wants to implement something similar. Also I'll upload the game source when I finish it!

I use stb_vorbis, which allows you to specify a buffer for all temp data.
I allocate a temp buffer on the stack and I use it. The rest of temp data is on the stack too. I need about 500kB of stack, so there's a lot of room for more background jobs. Maybe I'll write a sound mixer for the ME processor too, because there's lot of unused power there. The file read is done to a buffer which is written and read using uncached pointers, the same goes for the decoded buffer. I'll play a little bit with buffer sizes to improve the a little bit the performance.

I assume that internal ME memory is'nt on the same bus that main memory, because the performance of the game has increased when using the internal instead of the main memory.

Thanks!
Post Reply