Sound synthesizer using $4011, 2a03 only

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

User avatar
rainwarrior
Posts: 7893
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Sound synthesizer using $4011, 2a03 only

Post by rainwarrior » Sun Aug 21, 2016 10:50 pm

Yeah, but that's just a phase accumulator again, just you've replaced the saw wave with a wavetable lookup, so it could be any wave. (With the saw, the "wavetable index" is your wavetable already.)

Though, if you did 4-bit waves, you'd only need a 16 x 16 table to do sample * volume * output level in a single lookup. That's probably a better way to do volume.

I was just coming at it trying to think if the "subtract 2 waves" idea could apply to anything else. Maybe not.

tepples
Posts: 22160
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Sound synthesizer using $4011, 2a03 only

Post by tepples » Mon Aug 22, 2016 6:59 am

Subtracting two saws gives you a variable duty cycle pulse wave, for some SID or VRC6 style sound.

Rahsennor
Posts: 476
Joined: Thu Aug 20, 2015 3:09 am

Re: Sound synthesizer using $4011, 2a03 only

Post by Rahsennor » Mon Aug 22, 2016 6:52 pm

I have the same communication difficulties as tepples, so let me clarify. I was replying to this:
rainwarrior wrote:It operates at a much higher frequency than you could do in software, of course, so tuning might be an issue if you did something similar in software (i.e. ~150x lower samplerate).
I believe this to be incorrect, and that the code I posted implements the described behaviour: a software implementation of a clock divisor running at the same samplerate as the VRC6, with the caveat that it is limited to periods greater than approximately 172 cycles. The benefit of such an algorithm being that it eliminates audible aliasing.

If any of that is not the case, please point out the error in my logic.

User avatar
rainwarrior
Posts: 7893
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Sound synthesizer using $4011, 2a03 only

Post by rainwarrior » Mon Aug 22, 2016 7:13 pm

Oh, sorry, I misunderstood what you were implying with the sample. So the "clockslide" is really a variable entry point that determines the length of the sample loop?

So... that lets you adjust the samplerate directly to control the pitch of your generator, instead of having a fixed samplerate. Makes sense. I guess the pitch resolution would then be half the CPU rate. The high end of the pitch range might be a bit limited, though probably fine.

Limited to one channel, though, as you said. Hmm. Interesting approach though.

Rahsennor
Posts: 476
Joined: Thu Aug 20, 2015 3:09 am

Re: Sound synthesizer using $4011, 2a03 only

Post by Rahsennor » Mon Aug 22, 2016 7:36 pm

A clockslide produces a single cycle of delay per byte, down to a minimum of two cycles, so the pitch resolution is the full CPU rate.

EDIT: that site seems to be unstable, and I can't find another good explanation, so here's the general idea:

Code: Select all

; C9 C9 C9 C5 EA
cmp #$C9 ; 2 cycles 
cmp #$C5 ; 2 cycles
nop      ; 2 cycles

; C9 C9 C5 EA
cmp #$C9 ; 2 cycles 
cmp $EA  ; 3 cycles

; C9 C5 EA
cmp #$C5 ; 2 cycles
nop      ; 2 cycles

; C5 EA
cmp $EA  ; 3 cycles

; EA
nop      ; 2 cycles
A jmp (indirect) or self-modifying jmp absolute into any point in a sequence of {C9} C5 EA will delay one cycle for every byte of clockslide executed, plus a constant (the cost of the jump plus the final nop, 5 or 7 cycles).

User avatar
rainwarrior
Posts: 7893
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Sound synthesizer using $4011, 2a03 only

Post by rainwarrior » Mon Aug 22, 2016 8:18 pm

Ah, I understand. I was just thinking of a line of NOPs.

Hmm, noticed this technique is actually described on the Wiki, but in an inappropriate article for it. Ha ha. Weird.

User avatar
Bregalad
Posts: 7990
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Re: Sound synthesizer using $4011, 2a03 only

Post by Bregalad » Mon Aug 22, 2016 11:51 pm

Blargg got working saw and square waves with DMC channel long ago, combiniing $4011 writes and DPCM it doesn't even require a mapper with a CPU-cycle timer IRQ, and can be done on NROM, and uses much less CPU.

The whole point I had making it on a fixed sample rate was to mix 2 or more channels.

I do not see how substracting saw waves get a saw wave with controllable volume. Anyhow, I fear aliasing might be awful with saw waves, and with general-purpose-4-bit waves as well.

User avatar
Myask
Posts: 965
Joined: Sat Jul 12, 2014 3:04 pm

Re: Sound synthesizer using $4011, 2a03 only

Post by Myask » Mon Aug 22, 2016 11:53 pm

Rahsennor wrote: the Deflemask trick
What, polling $4015 for frame counter with interrupts masked?

Rahsennor
Posts: 476
Joined: Thu Aug 20, 2015 3:09 am

Re: Sound synthesizer using $4011, 2a03 only

Post by Rahsennor » Tue Aug 23, 2016 6:21 pm

Yes, that. The code I gave uses 100% CPU but runs at a variable rate, so it can't time notes and envelopes by itself. Interrupts would cause audible distortions, but polling can be synchronized with the PCM.

User avatar
B00daW
Posts: 586
Joined: Thu Jan 03, 2008 1:48 pm

Re: Sound synthesizer using $4011, 2a03 only

Post by B00daW » Fri Aug 26, 2016 5:17 pm

(Move to "NES Music" please. :) )

User avatar
rainwarrior
Posts: 7893
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Sound synthesizer using $4011, 2a03 only

Post by rainwarrior » Fri Aug 26, 2016 5:19 pm

Why? This thread is about programming, not music. (More thorough reponse here)

The only piece of music in this thread is the CV3 test I posted a ways in.
Last edited by rainwarrior on Fri Aug 26, 2016 5:22 pm, edited 1 time in total.

User avatar
B00daW
Posts: 586
Joined: Thu Jan 03, 2008 1:48 pm

Re: Sound synthesizer using $4011, 2a03 only

Post by B00daW » Fri Aug 26, 2016 5:21 pm

rainwarrior wrote:Why? This thread is about programming, not music.

The only piece of music in this thread is the CV3 test I posted a ways in.
"Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music."

User avatar
Anders_A
Posts: 88
Joined: Mon Nov 27, 2006 11:56 pm
Location: Sollentuna, Sweden

Re: Sound synthesizer using $4011, 2a03 only

Post by Anders_A » Sun Aug 28, 2016 5:20 am

"Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems."

This is very much a thread about a technichal issue related to programming the NES imho.

Much more so than related to NES music.

User avatar
za909
Posts: 216
Joined: Fri Jan 24, 2014 9:05 am
Location: Hungary

Re: Sound synthesizer using $4011, 2a03 only

Post by za909 » Wed Aug 31, 2016 3:46 am

If sampling rate is an issue, you could try the method I used to get double the normally achievable rate with DMC interrupts (8 272Hz) by sitting in the IRQ handler enough to pump out another sample right in-between two consecutive IRQ-s. It takes more CPU, but you can also spend the time after the first sample to do your calculations and it requires no IRQ source to be in the cartridge.

User avatar
rainwarrior
Posts: 7893
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Sound synthesizer using $4011, 2a03 only

Post by rainwarrior » Wed Aug 31, 2016 3:07 pm

Interesting idea, though the DPCM sample would be interfering with the samples we're trying to play (unless you're playing PCM on another channel, somehow).

Post Reply