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: 452
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: 52
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
Courage
csabanw
bepp/ΤRIΛD
Magic/Nah-Kolor
Thierry
Codey/Second Dimension
wil
Morpheus/IPC+C64.COM
Airwolf/F4CG
Guests online: 101
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 No Listen  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Crackers
1 Mr. Z  (9.9)
2 Antitrack  (9.8)
3 OTD  (9.8)
4 Fungus  (9.8)
5 S!R  (9.8)

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