What's the fastest rate of repeated IRQ possible?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

lidnariq
Posts: 11430
Joined: Sun Apr 13, 2008 11:12 am

Re: What's the fastest rate of repeated IRQ possible?

Post by lidnariq »

Pretty easy to simulate that situation, right?

Say we're aiming for 10kHz audio, 180cy per DAC update. OAMDMA would knock out 2 samples every 16ms.

A little bit of trivial perl:

Code: Select all

use Math::Trig;
for ($cy = $sa = 0; $cy < 297805; $cy += 180, $sa++) {
		$newsample = 63.5*(1+sin($sa*pi/5)); # sine wave at exactly sample rate / 10, so 994Hz
		if ($cy*2 % 59561 >= 1028) {
				$oldsample = $newsample;
		}
		print chr($oldsample);
}
yields this sound:
sim.ogg
(3.7 KiB) Downloaded 195 times
Of course, this is roughly the worst possible situation; a sine wave will make this distortion maximally audible.
User avatar
Memblers
Site Admin
Posts: 4044
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: What's the fastest rate of repeated IRQ possible?

Post by Memblers »

Neat, that does have a familiar ring to it. Thinking about the old samples I had recorded, IIRC, 001.WAV and 002.WAV are the only ones recorded while I purposely turned the OAM DMA off (they are sine waves also). Aliasing seems especially noticeable in 007.mp3 (those detuning glitches were in the music driver, I know it sounds awful).
http://membler-industries.com/squeedo/2 ... ps/007.mp3
http://membler-industries.com/squeedo/2 ... ion/samps/
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: What's the fastest rate of repeated IRQ possible?

Post by tokumaru »

rainwarrior wrote:I thought as long as you set OAMADDR back to 0 before vblank ends things should be fine? (At least, I've used it before and not seen anything wrong...)

Is there some additional corruption you're talking about?
This whole OAM corruption thing confuses me to no end, but I think you're right. Setting OAMADDR back to 0 before sprite evaluation starts should work just fine.

It's just that for years we knew that using $2003/4 was unreliable somehow, but AFAIK it was only recently that the exact behavior was properly analyzed and documented. I guess I just put OAM manipulation through $2003/4 in my "list of things to never do" and it remains there to this day.

Anyway, I understand that the purpose is to be able to have PCM audio during actual gameplay, but 50% of the CPU time, slow ass OAM updates, vblank time being spent on audio... those are pretty severe restrictions, making the technique still prohibitive for most kinds of games.
lidnariq
Posts: 11430
Joined: Sun Apr 13, 2008 11:12 am

Re: What's the fastest rate of repeated IRQ possible?

Post by lidnariq »

I know I've had situations where just writing to $2003 caused corruption, even if we write 0 to $2003 before rendering starts.

The last time this came up, Quietust said that in his tests, it works for some CPU-PPU alignments and not for others.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: What's the fastest rate of repeated IRQ possible?

Post by tokumaru »

Now that you mentioned it, I think I remember someone saying that the only safe way to use $2003/4 is to write all 256 bytes and let OAMADDR wrap back to 0 (which's exactly what an OAM DMA does, only faster). That'll eat nearly your entire vblank time, even if you use unrolled code.
lidnariq
Posts: 11430
Joined: Sun Apr 13, 2008 11:12 am

Re: What's the fastest rate of repeated IRQ possible?

Post by lidnariq »

last time

That was me.

You can also safely write the first 7 bytes by hand, but ... being only able to update sprite 0 and everything but X in sprite 1 isn't very useful.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: What's the fastest rate of repeated IRQ possible?

Post by tokumaru »

Oh, I completely forgot about that topic! Hahaha Yeah, that was certainly the most recent conversation that contributed to my "only fill the OAM using DMAs" stance.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: What's the fastest rate of repeated IRQ possible?

Post by rainwarrior »

Hunh, well that's new to me. I'm going to have to do some tests laster, ha ha. :S
User avatar
za909
Posts: 248
Joined: Fri Jan 24, 2014 9:05 am
Location: Mijn hart woont al in Nederland

Re: What's the fastest rate of repeated IRQ possible?

Post by za909 »

I've tested the effect of the OAM DMA distortion with my FME-7 test ROM before. This exemplifies the worst possible distortion though where the output is delayed, since the sample is fetched from ROM inside the IRQ handler. But this could be solved as well by manually adjusting the vector after each OAM DMA to get the "missed samples" effect instead.
Attachments
Warped with OAM DMA.nes
(520.02 KiB) Downloaded 178 times
Warped.nes
No DMA
(520.02 KiB) Downloaded 176 times
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: What's the fastest rate of repeated IRQ possible?

Post by dougeff »

Sounds good. Those file sizes, though. Hmm.
nesdoug.com -- blog/tutorial on programming for the NES
lidnariq
Posts: 11430
Joined: Sun Apr 13, 2008 11:12 am

Re: What's the fastest rate of repeated IRQ possible?

Post by lidnariq »

11.6kHz audio consumes an awful lot of ROM awfully fast. Sometimes compression helps, but ...

On the other hand, it is pretty valid to say that, right now, the economies of ROMs are such that you may as well use a 512KiB ROM if you have any PRG bankswitching at all.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: What's the fastest rate of repeated IRQ possible?

Post by tepples »

lidnariq wrote:right now, the economies of ROMs are such that you may as well use a 512KiB ROM if you have any PRG bankswitching at all.
Unless you're limited by CPLD macrocells.
Post Reply