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

User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

What's the fastest rate of repeated IRQ possible?

Post by dougeff »

I'm having trouble with the math.

If I did some kind of APU IRQ, what's the fastest rate I could get? And, yes, I know there would be a ton of overhead in the IRQ handler, making this difficult to calculate. Rough estimate? Anyone?

I know MMC3 scan line counters are NOT really useful below 2 scanlines, and that's not fast enough (7000 hz) for what I had in mind (PCM audio).
nesdoug.com -- blog/tutorial on programming for the NES
russellsprouts
Posts: 53
Joined: Sun Jan 31, 2016 9:55 pm

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

Post by russellsprouts »

If I understand correctly, a DMC irq would give you a minimum of 428 cycles between interrupts, which comes out to 4182Hz. You would need to play a sample of 10101010, which would add a slight noise to the playback as well. So DMC irq probably wouldn't work for what you're looking for.
User avatar
Dwedit
Posts: 4921
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

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

Post by Dwedit »

VRC3 is an easy mapper if you need to play back samples, since its timer can reset to a specific value, rather than requiring timed code to restart the timer. Maybe look at other mapper IRQs too, maybe RAMBO.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
Bregalad
Posts: 8055
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

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

Post by Bregalad »

russellsprouts wrote:If I understand correctly, a DMC irq would give you a minimum of 428 cycles between interrupts, which comes out to 4182Hz. You would need to play a sample of 10101010, which would add a slight noise to the playback as well. So DMC irq probably wouldn't work for what you're looking for.
If you're doing that, you might as well allow to play different "samples" for up ramp, down ramp or pseudo-flat, potentially increasing sound quality dramatically.
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 »

Bregalad wrote:If you're doing that, you might as well allow to play different "samples" for up ramp, down ramp or pseudo-flat, potentially increasing sound quality dramatically.
I'm pretty sure someone posted about this technique here in the forums already... Can't find it though.
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 »

I've abandoned this idea. I don't think I could get a fast enough IRQ frequency to do in-game pcm sound.
nesdoug.com -- blog/tutorial on programming for the NES
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 »

My method probably has the highest sample rate possible without mapper IRQs. Depending on what you're going for, it can even do music fairly decently, but your best bet is to play something more orchestral: (This is without OAM DMAs)
https://www.youtube.com/watch?v=mddZUUcu_fU

I would be happy to help tailoring the original player to your game's needs if you see any chance for you to change your mind.
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 »

That was exactly what got me started on making Squeedo (the original 2004 version), wanting the IRQ to do sampling/synthesis. Then I quickly realized the PIC MCU I used could do everything even better, ended up with NES just getting IRQ to write the PIC's generated data to $4011.

Another reason MMC3 wouldn't be useful for this, is that the IRQs stop coming during vblank.
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 »

Memblers wrote:Another reason MMC3 wouldn't be useful for this, is that the IRQs stop coming during vblank.
A related thought: what happens if you get an IRQ during OAMDMA? Can you get a ~500 cycle delay in this case?

i.e. when using the PCM IRQ would it be prudent to use OAMDATA instead of DMA? (Drastically reduces available upload bandwidth, but you could do a reasonable amount of animation maybe?)
lidnariq
Posts: 11429
Joined: Sun Apr 13, 2008 11:12 am

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

Post by lidnariq »

rainwarrior wrote:A related thought: what happens if you get an IRQ during OAMDMA? Can you get a ~500 cycle delay in this case?
Yup.

This is one of the reason I think a "right" solution is to have a synthesizer directly generate DPCM instead of PCM.
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.e. when using the PCM IRQ would it be prudent to use OAMDATA instead of DMA? (Drastically reduces available upload bandwidth, but you could do a reasonable amount of animation maybe?)
And you have to work around the weird OAM corruption that results from using $2003/$2004.
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 »

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?
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 »

I remember being concerned that OAM DMA would ruin the audio, but when I enabled it, it seemed pretty much unnoticeable to me. But that was 10+ years ago on a project where I was excited that it even worked at all (being my first hardware), so it could be a case of rose-tinted glasses (er, earphones?). I'm seriously tempted to revive my old code and find out sometime. I'd expect to hear some kind of combination of a 60hz buzz and aliasing, getting worse as the frequency gets higher.

I wonder how much worse the OAM DMA's effect would be when the NES is doing the synthesis, because those cycles are just gone. In Squeedo's case the PIC runs independently, the NES misses out on a few updates, the audio isn't permanently distorted.
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 »

Memblers wrote:I wonder how much worse the OAM DMA's effect would be when the NES is doing the synthesis, because those cycles are just gone. In Squeedo's case the PIC runs independently, the NES misses out on a few updates, the audio isn't permanently distorted.
A missing sample that's filled in with the previous value is a lot less of a problem than a complete halt/delay of the stream.
Post Reply