Created
April 20, 2020 19:23
-
-
Save gitlarryf/a6b4baa0dbf132925aaaa5f0182781c8 to your computer and use it in GitHub Desktop.
Sample program to play a tune through the SID module in Neon.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#| | |
| File: daisy.neon | |
| | |
| This file plays "Daisy Bell" (Bicycle Built For Two) to demonstrate the use of the | |
| core sid library. | |
|# | |
#IMPORT bitwise | |
IMPORT sid | |
VAR Voice: Number := 1 # Play the tune out of voice 3. | |
FUNCTION wf(wave: Number): String | |
CASE wave | |
WHEN sid.WAVEFORM_TRIANGLE DO RETURN "Triangle" | |
WHEN sid.WAVEFORM_SAWTOOTH DO RETURN "Sawtooth" | |
WHEN sid.WAVEFORM_PULSE DO RETURN "Pulse Width" | |
WHEN sid.WAVEFORM_NOISE DO RETURN "Noise" | |
WHEN OTHERS DO | |
RETURN "Multiple Waveforms" | |
END CASE | |
END FUNCTION | |
FUNCTION init(v: Number, wave: Number) | |
sid.setChip(sid.chip_model.MOS6581) | |
sid.setSamplingParameters(1022730, sid.sampling_method.SAMPLE_RESAMPLE_INTERPOLATE, 44100) | |
print("Playing tune with \(wf(wave)) waveform.") | |
sid.setWaveform(v, wave) | |
sid.setPulseWidth(v, 1024) | |
sid.setEnvelope(v, 2, 4, 8, 8) | |
#sid.setRingModulation(v, TRUE) | |
sid.setFilterEable(v, TRUE) | |
sid.setVolume(15) | |
sid.run(500) | |
END FUNCTION | |
FUNCTION play(voice: Number, freq: Number, dur: Number) | |
sid.setFrequency(voice, freq*6) | |
sid.setGate(voice, TRUE) | |
# If duration is ZERO, then we play the note for 1 second, but we do not let up on the key.. | |
IF dur = 0 THEN | |
sid.run(1000) | |
EXIT FUNCTION | |
END IF | |
sid.run(dur) | |
sid.setGate(voice, FALSE) | |
END FUNCTION | |
FUNCTION sleep(dur: Number) | |
# Un-gate all the voices, which will enable the Release cycle of the ADSR envelope, | |
# to allow a "pause" in the music. | |
sid.setGate(1, FALSE) | |
sid.setGate(2, FALSE) | |
sid.setGate(3, FALSE) | |
# Run the SID chip for the duration of the sleep cycle. | |
sid.run(dur) | |
END FUNCTION | |
FUNCTION PlayTune(v: Number, wave: Number) | |
init(v, wave) | |
play(v, 2093, 769) | |
play(v, 1760, 769) | |
play(v, 1396, 769) | |
play(v, 1046, 769) | |
play(v, 1174, 192) | |
play(v, 1318, 192) | |
play(v, 1396, 192) | |
play(v, 1174, 385) | |
play(v, 1396, 192) | |
play(v, 1046, 962) | |
sleep(385) | |
play(v, 1568, 769) | |
play(v, 2093, 769) | |
play(v, 1760, 769) | |
play(v, 1396, 769) | |
play(v, 1174, 192) | |
play(v, 1318, 192) | |
play(v, 1396, 192) | |
play(v, 1568, 385) | |
play(v, 1760, 192) | |
play(v, 1568, 962) | |
sleep(3) | |
play(v, 1760, 192) | |
play(v, 1864, 192) | |
play(v, 1760, 192) | |
play(v, 1568, 192) | |
play(v, 2093, 385) | |
play(v, 1760, 192) | |
play(v, 1568, 192) | |
play(v, 1396, 962) | |
play(v, 1568, 192) | |
play(v, 1760, 385) | |
play(v, 1396, 192) | |
play(v, 1174, 385) | |
play(v, 1396, 192) | |
play(v, 1174, 192) | |
play(v, 1046, 962) | |
play(v, 1046, 192) | |
play(v, 1396, 385) | |
play(v, 1760, 192) | |
play(v, 1568, 385) | |
play(v, 1046, 192) | |
play(v, 1396, 385) | |
play(v, 1760, 192) | |
play(v, 1568, 192) | |
play(v, 1760, 192) | |
play(v, 1864, 192) | |
play(v, 2093, 192) | |
play(v, 1760, 192) | |
play(v, 1396, 192) | |
play(v, 1568, 385) | |
play(v, 1046, 192) | |
play(v, 1396, 1282) | |
sid.run(1000) | |
END FUNCTION | |
VAR waveform: Number := 0 | |
VAR wav: String := input("Play tune with which waveform (S,P,T,N)? [T] ") | |
IF wav = "" THEN | |
wav := "T" | |
END IF | |
CASE wav[0] | |
WHEN "S", "s" DO | |
waveform := sid.WAVEFORM_SAWTOOTH | |
WHEN "T", "t" DO | |
waveform := sid.WAVEFORM_TRIANGLE | |
WHEN "P", "p" DO | |
waveform := sid.WAVEFORM_PULSE | |
WHEN "N", "n" DO | |
waveform := sid.WAVEFORM_NOISE | |
END CASE | |
PlayTune(Voice, waveform) | |
sid.setVolume(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment