PDA

View Full Version : Strmnnrmn talks Audio Support in Daedalus R9 - N64 Emulator for PSP



Baboon
February 14th, 2007, 22:05
More details released about the up and coming N64 emulator for psp... and its sounding good! :thumbup:

http://strmnnrmn.blogspot.com/

Audio Support in Daedalus R9

Last week I said that I'd talk a bit about the audio support I've been working on. I want to describe how it was implemented, and continue with what to expect from it in R9 and how it affects performance.

I'd been putting off implementing audio support for a number of reasons. Firstly, I just didn't think that the emulator was running fast enough to spare any extra time doing other work. Secondly, because it wasn't running fast enough, I knew the resulting audio would sound horrible and choppy. Finally, I knew that writing an audio list processor from scratch was going to be very time consuming and error prone.

Maybe it's worth going into a little more detail about that last point.

Most audio and graphics processing on the N64 is handled through audio lists and display lists (very similar to an OpenGL display list). These lists are sequences of simple instructions which are usually constructed by the CPU as the game is running. I used the word 'usually', because it's possible to generate the lists offline, and just execute them at runtime as required.

One way of thinking about the audio and display lists is as a very simple scripting language. Each instruction in the list performs a trivial operation, like copying a block of sample data to another region of memory, interpolating samples from two buffers and storing the result in another and so on. The format of the instructions in the lists has been very carefully designed so that they can be efficiently operated on by the N64's coprocessor, the RSP. The RSP is a very fast processor with SIMD instructions (i.e. instructions which operate on multiple pieces of data - much like SSE on x86 based processors), and it's ideally suited to performing the kind of jobs required in processing audio data or transforming and lighting geometry. The code which executes on the RSP is often called 'microcode'.

The nice thing about audio and display lists is that they can be executed asynchronously by the RSP while the CPU is off doing other work. The CPU just needs to copy a small block of data (describing the task at hand) to the RSP's local memory, and then kick it off. The CPU then goes off doing some other work (updating the game logic for instance.) At some point, the RSP finishes processing the audio or display list, and signals the CPU that it's finished its work through an interrupt. The CPU can then queue up the next available job to the RSP for processing.

There are two ways in which an emulator can handle audio or display lists. The first method is to emulate the RSP at a very low level. This means emulating the RSP as a separate processor, emulating the microcode which has been written to decode and process the audio and display lists. This is what's known as LLE (low-level emulation). The other approach is HLE (high-level emulation). This involves interpreting and processing the audio and display lists manually, ignoring the emulation of the RSP and the microcode entirely.

The HLE approach is typically much, much faster than emulating the task at a low level. This speed comes as a price though, as rather than 'just' writing code to emulate the RSP core, a separate implementation must be written for every task that you want to emulate. This would be fairly simple if there was a single format for audio lists, and a single format for display lists. Unfortunately though, over the years Nintendo released a number of different versions of the microcode controlling these tasks, and many of these changes resulted in different formats for the audio lists and display lists.

Last time I checked, there were 3 major audio list formats, and 5 (6?) major display list formats. Some features of the list formats are similar between versions, but typically they're all very different, and large portions must be reverse engineered from scratch.

So, back to audio support in Daedalus. I had come to the point with implementing various dynarec improvements that I felt it was worth looking into audio to get an idea how how well it would work, and how much of a performance hit there was. As I was saying, one of the reasons I'd been putting off implementing audio support was that I knew that taking a high-level approach was going to be time consuming and error prone. The alternative, low level emulation, just wasn't practical from a performance point of view.

In the end, I decided to see if I could find the source for a PC audio plugin, and adapt this for use with Daedalus. I was fortunate enough to discover that Azimer had made the source for v0.55 of his audio plugin available (Azimer - if you're reading this, please drop me a line to say hello :) My reasoning was that if I could get something up and running in a couple of evenings then I could figure out how much work would be involved in getting it polished. If it looked like it was going to be too much work then I could revert all my changes and at most I'd have wasted just a few hours.

In the end it all went incredibly well. Azimer's source was very self-contained, with just a couple of hooks to implement to get it working. There were a few small issues to solve like having to upsample the output to 44.1KHz (as the PSP output is fixed at this frequency), but nothing that took more than a couple of hours.

So, how does it sound? Well, it's pretty variable. It sounds great in places where there's a high enough framerate to keep the audio buffer full. Mario 64 is pretty good for this - it seems 25fps is a minimum to avoid any choppiness in the output. When the framerate drops lower than this the audio quality does start to suffer significantly. On the plus side, it seems to be decoding everything correctly in all the roms I've tested so for, which means that the quality is only going to improve as I make further improvements to the performance of the emulator.

Which brings me to my next point - how does enabling audio support affect the performance of the emulator? I've not had chance to measure this empirically, but it probably slows things down by about 10-20%. Given that R9 is running about 40-100% faster than R8, you should be able to run R9 with audio and still see a small speedup. In any case, I've added an option to enable or disable the audio in the front-end (this is also accessible from the pause menu while the rom is running).

So, that's just about the story so far with audio support in Daedalus. There's clearly a lot more work to do, but the good news is that audio support is in, and working, and is only going to improve with time. Later this week I'll talk a bit about future improvements, including methods for reducing the impact that audio processing has on performance.

-StrmnNrmn

xg917
February 14th, 2007, 22:26
godam i was about to just post it! lmaoo

nice find, cant waitt!!!!!

ICE
February 14th, 2007, 22:40
man i cant wait until its released!!!!!!!!1

blackrave
February 14th, 2007, 22:45
Wow, long post and good news. Super Mario 64 runs with good sound at certain places, that's good to hear. Really, I can't wait for R9 to be released!

The first games I'm gonna try are Super Mario 64 and Super Smash Bros.

By the way, it's really great that StrmnNrmn updates his blog quite often. It lessens the waiting time (or does it?). :)

brainpan
February 14th, 2007, 22:47
I am really enjoyig these posts info posts by StrmnNrmn. Keeg up the good work!

Balthasar00
February 14th, 2007, 22:51
Sweet !

Veskgar
February 14th, 2007, 22:53
Its very good to see lots of news regarding the next release. I'm very excited about audio support. I feel audio is necessary when playing games on emulators.

It was really encouraging to see that Strmnnrmn expects audio to only get better over time. I'm not sure if he is yet using the "ME" in such a way that Snes9xTYL 0.4.2. ME does to take some of the load off but if something like that can be implemented in the future it would be pretty cool.

Jpdeathblade
February 14th, 2007, 23:18
I cant wait =P
I only want to play Super Mario 64, Super Smash Bros, and Pokemon Snap.

O hey, do you think it would be possable to take the .sav file from pokemon red and load it for Pokemon Stadium? It be awsome to use my Mew =P

acn010
February 14th, 2007, 23:26
dammit!!! cant wait for it!!!!!!!!1
aaahhhh?
when you guys think this will come out?

Shrygue
February 14th, 2007, 23:37
This is good news to hear, having audio support would be ace!

joshisposer
February 14th, 2007, 23:38
BTW that strmnnrmn is talking, geez, within a week. He originally said before the 25th, which is like 11 days. I expect sooner. My guess is five days but i wont be disappointed if later. He has really tried this release.

Mc_Logical
February 14th, 2007, 23:40
i enjoyed reading that and its made me want the damn thing now lol i cant wait to try it and its good to know he will be doing future updates etc R10?

idapimp
February 14th, 2007, 23:41
it is going to come out before feb 25th, and hell is going to freeze over when it does. i actually think this release is one of the signs of the apocalypse. the second this is released, riots will break out all over the world and people will be killing each other. and then all the turmoil and confusion will cause a rift to open up in space and time creating a black hole that we all get sucked into and die. it will be awesome.

aries2k4
February 15th, 2007, 00:14
This is great. Iīve been holding off playing Mario64 until the emu had sound. Heck I might have sound and still a small increase in fps? Canīt wait for this one. Plus the sound can only get better in future releases.
All in all, sounds like this emu is coming along great.

V3N0M
February 15th, 2007, 00:24
it is going to come out before feb 25th, and hell is going to freeze over when it does. i actually think this release is one of the signs of the apocalypse. the second this is released, riots will break out all over the world and people will be killing each other. and then all the turmoil and confusion will cause a rift to open up in space and time creating a black hole that we all get sucked into and die. it will be awesome.

That's one hell of an imagination... :rofl:

BrooksyX
February 15th, 2007, 00:25
I hope that by r10 Strmn can move the audio to the media engine so the sound wont affect the speed at all.

pkmaximum
February 15th, 2007, 00:26
Strmmmn is definently the coder to look forward too at the moment. All I can say is great work, and that I'm a bit surprised he did not talk about the ME at all, but then again he mentioned that a little bit in a past comment response to someones question. As far as the ME goes, he said before he will definently look into it when he gets the time one day, because right now he is really not sure how the PSP ME works. So I guess we are going to have to wait on the edge of our seats till that one.

The clock is ticking down February 25 is almost here, but not to mention he said he will release the emulator before that, so I'm really looking forward excited on the next release. I can't wait to play some Super Mario 64, Mario Kart 64, Diddy Kong Racing, Glover, and Quest 64. Obviously I think we all want Zelda 64 but the fps on that game is still only touching 13fps at the moment, sometimes I wonder if that will ever touch 25fps one day w/sound, I guess Strmmmmn and results are the only way we will ever find out that question. But once again great work Strmmmn and sry for the long post.

carlitx
February 15th, 2007, 00:31
I WAAAAAAANNNNNNNNNNNNNNNNNNTTTTTTTTTTTTTT IIIIIIIIIIIIIIIIIIIIIIIIIIIITTTTTT:P:P:Plol

mike03$$$
February 15th, 2007, 01:04
i hope a wrestling game will work this time and to hear about audio support thats cool

Bobby Lemain
February 15th, 2007, 01:43
yee boyee! Well anyways, keep up the souperduperfly work with your emulator and good luck with the coding.

baracki96
February 15th, 2007, 02:30
ALways nice to see a coder doing what he enjoys doing, while benefiting a community at the same time. Does anyone know if he has kept a technical log of his work? I'm trying to learn how to do this stuff since I've got heavy experiance in some coding languages ( especially C++) and it would be gold to be able to help out someone likestrnmm or any other psp-homebrew-dev for that matter.

dj2005
February 15th, 2007, 02:53
Ahh, it's so nice to have StrmnNrmn back. :)

Lumir
February 15th, 2007, 03:56
There is a way to help this emu out. Since we all know how having the ME process the sound will allow no slow down due to actually emulating the sound, someone with some experience should learn about the ME and how it works. Then submit thier findings to StrmnNrmn.

Or better yet someone who was involved with the snes emu with ME support, contact StrmnNrmn and share ideas and give support.

pibs
February 15th, 2007, 04:25
I wonder what wally's spiff up of R9 will be

Sterist
February 15th, 2007, 06:20
hey man, wuts yur ****ing paypal? :)

Buddy4point0
February 15th, 2007, 07:39
im gonna die if this isnt relised soon! o btw is there gonna be frame skipping cause if it skips 1 frame its unoticable but will double speed

lordnibbla
February 15th, 2007, 09:08
"I've not had chance to measure this empirically, but it probably slows things down by about 10-20%. Given that R9 is running about 40-100% faster than R8, you should be able to run R9 with audio and still see a small speedup. In any case, I've added an option to enable or disable the audio in the front-end (this is also accessible from the pause menu while the rom is running)."

There we go. That is MUCH better than I had initially expected to hear. This should be great :D

razorak
February 15th, 2007, 09:13
woahz...that's wordy...looking forward to release, just got myself a 4GB mem stick recently =)

Shadowblind
February 15th, 2007, 12:38
woahz...that's wordy...looking forward to release, just got myself a 4GB mem stick recently =)

Same here, (velcroed my 1 GIG to the back) what with all these 2.1GB PSX games and 32mb N64 games. :D

ssnake
February 15th, 2007, 15:25
Woa! Very instructive :)
It is very nice to be able to read stuff like that, very interesting.

Good progress on R9!! :thumbup:

guardiansnowman
February 15th, 2007, 17:20
this sounds like it going to be the SH*T!!! lol. i really cant wait for this. i have always supported this since the first realese and i always will love Strmnnrmn... he's one of the main ppl who kept me on my psp since ther start :)

kharaboudjan
February 15th, 2007, 18:07
well, he really didnt code for the psp from the start from what i know.. but i understand what u mean.. we all wants a playable N64 emulator :)

jurkevicz
February 15th, 2007, 18:14
I hope he releases it tomorrow!

pkmaximum
February 15th, 2007, 19:31
Lets all hold our breath =D

LOL j/p but the release will definently be soon, 10 more days tops right =P

CaptainMorgan4
February 15th, 2007, 23:18
Well since his trip is on the 25th I'm sure he would release it on the 24th to avoid messing up his trip plans. So since today is the 15th then that means we have 9 more days but this day is winding down so almost 8 (almost a week away!). I'm excited and can't wait to try this emulator out I know it's going to be something realyl special.

baracki96
February 15th, 2007, 23:30
There is a way to help this emu out. Since we all know how having the ME process the sound will allow no slow down due to actually emulating the sound, someone with some experience should learn about the ME and how it works. Then submit thier findings to StrmnNrmn.

Or better yet someone who was involved with the snes emu with ME support, contact StrmnNrmn and share ideas and give support.
I'll start looking into the ME now. Really wish there was documentation on how it communicates with the CPU/Memorystick. Oh well, I believe the snes tyl source was released so I'l just peruse that. Hope it helps StrmnNrmn in making daedulus.