It is currently Sat Nov 25, 2017 2:38 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 27 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Wed Nov 01, 2017 6:58 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6458
Location: UK (temporarily)
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:
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:
Attachment:
sim.ogg [3.7 KiB]
Downloaded 15 times


Of course, this is roughly the worst possible situation; a sine wave will make this distortion maximally audible.


Top
 Profile  
 
PostPosted: Wed Nov 01, 2017 8:39 pm 
Offline
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3484
Location: Indianapolis
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/2004_version/samps/007.mp3
http://membler-industries.com/squeedo/2004_version/samps/


Top
 Profile  
 
PostPosted: Wed Nov 01, 2017 9:19 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10120
Location: Rio de Janeiro - Brazil
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.


Top
 Profile  
 
PostPosted: Wed Nov 01, 2017 9:35 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6458
Location: UK (temporarily)
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.


Top
 Profile  
 
PostPosted: Wed Nov 01, 2017 9:45 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10120
Location: Rio de Janeiro - Brazil
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.


Top
 Profile  
 
PostPosted: Wed Nov 01, 2017 10:55 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6458
Location: UK (temporarily)
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.


Top
 Profile  
 
PostPosted: Wed Nov 01, 2017 11:16 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10120
Location: Rio de Janeiro - Brazil
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.


Top
 Profile  
 
PostPosted: Thu Nov 02, 2017 1:01 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5843
Location: Canada
Hunh, well that's new to me. I'm going to have to do some tests laster, ha ha. :S


Top
 Profile  
 
PostPosted: Sat Nov 04, 2017 4:42 pm 
Offline
User avatar

Joined: Fri Jan 24, 2014 9:05 am
Posts: 138
Location: Hungary
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 14 times
File comment: No DMA
Warped.nes [520.02 KiB]
Downloaded 10 times
Top
 Profile  
 
PostPosted: Sat Nov 04, 2017 9:04 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1835
Location: DIGDUG
Sounds good. Those file sizes, though. Hmm.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Sat Nov 04, 2017 9:21 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6458
Location: UK (temporarily)
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.


Top
 Profile  
 
PostPosted: Sun Nov 05, 2017 6:44 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19259
Location: NE Indiana, USA (NTSC)
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group