Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > A little coding puzzle
2014-02-28 07:25
lft

Registered: Jul 2007
Posts: 369
A little coding puzzle

Hi!

All this talk of SID sample playback gave me an idea for an improvement to the SounDemoN 8-bit technique, that would remove the need for jitter correction in the NMI handler.

As it turns out, the solution is of little practical value, because it eats more cycles and puts a limit on the playback frequency (about 6.5 kHz with no sprites and badlines). But the idea is still intriguing, and perhaps if I share it, it might lead somewhere unexpected.

Can you figure out what I'm doing here?

setup:          
                lda     #$ff
                sta     $d40e
                sta     $d40f
                rts

nmi_handler:    
                sta     save_a+1
                stx     save_x+1
                
                lda     #$11
                ldx     #$09
                sta     $d40b
                stx     $d40b
                lda     #$17
                ldx     #$07
                sta     $d404
                stx     $d404
                lda     #$08
                ldx     #$00
                sta     $d412
                stx     $d412

                ; compute/fetch sample into a...
                
                sta     $d401
                sta     $d408
                lda     #$01
                sta     $d40b

save_x          ldx     #0
save_a          lda     #0
                jmp     $dd0c   ; ack + rti
2014-02-28 14:15
Mixer

Registered: Apr 2008
Posts: 422
You're using voice 3 with test bit on/off, it'll restart the osc depending on the delay between writes.

Then voice 1 has sync and ring bit set. sync means that it'll follow the voice 3 osc frequency and retrigs as it does. Ring will mirror the osc value when modulating channel has a msb set. So, if voice 3 has reached downslope, this'll mirror voice 1 triangle. Voice1 and 2 frq are set to the desired sample-value.

Voice 2 does the usual sample and hold, and the result I believe is an avg of voice1 and voice 2 sample values + voice 3 osc level at the time of sample.

if due to jitter voice 3 overshoots, voice 1 mirrored triangle compensates.

I believe something like this to be the idea.

And that is a very clever idea.

There is another idea regarding using the ringmirrored triangle. I wrote a bit about it in my sidwiki a while back.

-> Freeze another oscillator so that it is always on a downward slope when the other osc triangle is upwards. This would make it possible to select either x or $ff-x depending on which voice to sample eachtime. A bit tricky and slow to make a sampleplay on that though.
2014-03-10 21:08
lft

Registered: Jul 2007
Posts: 369
You are on the right track.

The fundamental problem is that we want to start a rising triangle wave, and then sample it (by briefly enabling the waveform) an exact number of cycles later. We want to sample as late as possible in order to maximise the amplitude (and range) of the sample playback, so we want to do it in consecutive interrupt handlers. But then we have the problem of relative jitter between successive interrupts.

But if we can somehow stop the rising triangle an exact number of cycles after starting it, it won't matter if we sample it one or several cycles later. So here's the trick: We start the rising triangle in voice 2, by setting the desired frequency and releasing the test bit. From the same interrupt handler (i.e. a fixed number of cycles later) we restart voice 3 by releasing the test bit. Voice 3 runs at maximum frequency. 129 cycles later, the MSB of the accumulator inside voice 3 will be set. This causes voice 3 to hardsync voice 1, which we incidentally also programmed with the same frequency as voice 2.

In the next interrupt, which occurs just after those 129 cycles plus a few cycles of jitter, we briefly enable triangle output on voice 2, and ring modulated triangle output on voice 1. Because we know that MSB of voice 3 is set by now, the output of voice 1 is inverted -- starting from a high level and going down at exactly the same rate as voice 2 is rising.

Therefore, what we will sample (and thus hear) is the sum of voice 1, which has been rising at a constant rate since time T0, and voice 2, which has been falling at the same rate since time T0 + K, where K is a constant near 129. After the moment of synchronisation, this sum will remain constant at the desired sample amplitude, and we don't need to compensate for jitter.

There it is. Kinda cool, but I don't think it can be of any practical use. Now surprise me! =)
2014-03-10 22:44
Pex Mahoney Tufvesson

Registered: Sep 2003
Posts: 50
Lft: you're obviously thinking too much, and I love it! :-D
---
Have a noise night!
http://livet.se/mahoney
2014-03-10 23:33
Zyron

Registered: Jan 2002
Posts: 2381
lft & mahoney - get a room, and make a demo. :)
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Alakran_64
E$G/hOKUtO fOrcE
megasoftargentina
rexbeng
tomz/TIDE
Oswald/Resource
Guests online: 122
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Bromance  (9.6)
10 Memento Mori  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Webmasters
1 Slaygon  (9.7)
2 Perff  (9.6)
3 Morpheus  (9.5)
4 Sabbi  (9.5)
5 CreaMD  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.036 sec.