Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user maak ! (Registered 2024-04-18) You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > SID Sound Effects
2015-05-16 22:42
TWW

Registered: Jul 2009
Posts: 541
SID Sound Effects

First of all, I've never coded anything with the SID besides pounding $d418 to create digi-playback so the inquirey here is completely noob-level.

I wanted to create a very simple sound effect routine (no music playing but using oscilator #3 to created random numbers)

It is used for a mimi-game-project I am messing around with to teach low-level programming principles to my step-son (in a desperate attempt to make it interesting).

So what I did was to make a subroutine where X is loaded with the FX and that would be that. New FX will interupt the one being played.

Here's the code (FX sound parameter = placeholders):

SoundFX:
    lda #%10110110
    sta $d404

    // Crank up volume
    lda #$08
    sta $d418
    // ADSR Envelope Channel #1
    lda FX_AD,x
    sta $d405
    lda FX_SR,x
    sta $d406
    // Frequency Channel #1
    lda FX_HI,x
    sta $d401
    lda FX_LO,x
    sta $d400
    // Control Register Channel #1
    lda FX_WF,x
    sta $d404
    rts

FX_AD:
    .byte $40, $81, $95, $21
FX_SR:
    .byte $08, $00, $03, $01
FX_HI:
    .byte $19, $10, $30, $30
FX_LO:
    .byte $b1, $00, $00, $00
FX_WF:
    .byte $81, $21, $17, $21


It works but 'sometimes' one effect stops working (footstep by using noise waveform (sound #0)). From the little I have read about the SID, I'm assuming it's related to the ADSR bug and there is need for a harder reset of the envelope generator.

For musicplayers etc, I understand there is need for this to be done the correct way but for a simple FX player like this is there any shortcut or have I overlooked something in this simplistic FX player?
2015-05-17 02:28
Agemixer

Registered: Dec 2002
Posts: 38
The first lines your code probably locks up noise waveform:
lda #%10110110
sta $d404

Just remove those lines. Use only waveforms $00..$8f, higher values would kill the noise waveform.

To reset SID voice status, everything you need is to
lda #$08
sta $d404
this resets oscillator (with test bit on: bit3=1) and sets GATE bit=off (bit0=0)

Think it like gate bit=on means that you pressing a piano key and gate bit=0 as you take finger off the keyboard. Simple as that.

"hard restart" is more advanced concept for how f.e. music players should handle SID chip, You can forget it here (but if you want it anyway, wait for 2 frames (=0.04s) with gate=off before changing a gate=1 once again.)

to key off, you can just touch the gate bit to 0:
and #%11111110
sta $d404

One method to wait x frames (*0.02s):
f0 bit $d011
bpl f0 ; wait for rasterline $100
f1 bit $d011
bmi f1 ; wait for rasterline $000
dex
bne f0
2015-05-17 02:30
ChristopherJam

Registered: Aug 2004
Posts: 1370
Yes, you've been caught by the ADSR bug.

Repeating effect #0 means you're switching from a slow release to a fast attack (8>4), which risks the bug unless you first recapture the rate counter.

Simplest thing to do is to use an ordinary hard-restart between effects; set release and gate to zero and wait for two frames.

Your effects #1 and #2 also risk the bug in the way lft mentioned in his post the other day; changing from a slow decay to a fast release can also trigger the bug. This is a little less audible though, as it just means a frame and a half delay before the sound starts dropping to silent, rather than missing the start of the sound.
2015-05-17 10:50
ChristopherJam

Registered: Aug 2004
Posts: 1370
(reading over the reply Agemixer made at the same time as me - I forgot about the noise lockup he refers to. If you're not disturbing any registers for the first few frames after you've set gate, then that's more likely to be the culprit. The ADSR bug will be occurring, but that'll just delay the start by a frame and a half, not kill the sound altogether)
2015-05-17 12:02
TWW

Registered: Jul 2009
Posts: 541
Yep, that did it.

Reset Voice:
lda #$08
sta $d404
+ No higher AD value than #$8f


Thanx.
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
Sentinel/Excess/TREX
Drees
Guests online: 83
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 The Ghost  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.8)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 Wafer Demo  (9.5)
7 TRSAC, Gabber & Pebe..  (9.5)
8 Onscreen 5k  (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 Crackers
1 Mr. Z  (9.9)
2 S!R  (9.9)
3 Mr Zero Page  (9.8)
4 Antitrack  (9.8)
5 OTD  (9.8)

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