QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: madscijr on January 25, 2022, 11:07:21 pm
-
Is this kind of audio control possible with current commands in QB64?
If not, I would like to request it as a feature, or challenge the gurus (you know who you are) to develop something (hopefully cross-platform).
Back in the day, programming sounds on the Commodore 64 was pretty fun.
Its custom sound chip (the SID) had a bunch of useful features, many of which I haven't seen the equivalent of in QuickBasic, Visual Basic, or QB64 (or at least not an easy equivalent):
- 3 tone generators (voices), frequency 0-4 kHz (16 Bit decomposition)
- 4 forms of waves (sawtooth, triangle, rectangle pulse width modulation, (white) noise /rush)
- 3 amplitude modulator, until 48 dB
- 3 envelope generators
- Synchronization of the oscillators
- Ring modulation
- Programmable filters (low pass, bandpass, high pass)
- Master volume in 16 steps
among other features (including a random generator).
A modern equivalent might be the Web audio API https://www.w3.org/TR/webaudio/ (https://www.w3.org/TR/webaudio/)
which enables programming audio and sound synthesis in JavaScript. Here's an example
https://stuartmemo.com/qwerty-hancock/ (https://stuartmemo.com/qwerty-hancock/)
But back to doing sound on the C64 - here are some examples which you can run in an emulator.
Some online emulators that work:
- https://c64emulator.111mb.de/index.php?site=pp_javascript&lang=en&group=c64 (https://c64emulator.111mb.de/index.php?site=pp_javascript&lang=en&group=c64)
- https://www.retrodevops.com/c64.html (https://www.retrodevops.com/c64.html)
^^^
Click the "sound" button to enable audio.
The keyboard layout is wonky (I don't know why they can't include a "use PC keyboard layout" checkbox), here is help:
For Type
+ [
( *
) (
* =
= /
: `
etc.
Some sample sound programs:
From https://nickm.com/post/2010/07/one-line-c64-basic-music/comment-page-1/ (https://nickm.com/post/2010/07/one-line-c64-basic-music/comment-page-1/):
10 poke 54272+rnd(1) *25,rnd(1) *256 : goto 10
From https://link.springer.com/chapter/10.1007%2F978-1-4899-6787-9_15 (https://link.springer.com/chapter/10.1007%2F978-1-4899-6787-9_15):
5 REM *** SIREN ***
10 POKE 54296,15
20 POKE 54277,0 : POKE 54278,240
30 POKE 54276,33
40 FOR X =: 1 TO 255
50 POKE 54273,X : FOR J =: 1 TO 15 : NEXT J : NEXT X
60 FOR Z =: 255 TO 1 STEP - 1
70 POKE 54273,Z : NEXT
80 C =: C+ 1 : IF C =: 3 THEN POKE 54296,0 : END
90 GOTO 40
From https://www.c64-wiki.com/wiki/SID (https://www.c64-wiki.com/wiki/SID):
0 REM *** C64-WIKI SOUND-DEMO ***
10 S = 54272: W = 17: ON INT(RND(TI)*4)+1 GOTO 12,13,14,15
12 W = 33: GOTO 15
13 W = 65: GOTO 15
14 W = 129
15 POKE S+24,15: POKE S+5,97: POKE S+6,200: POKE S+4,W
16 FOR X = 0 TO 255 STEP (RND(TI)*15)+1
17 POKE S,X :POKE S+1,255-X
18 FOR Y = 0 TO 33: NEXT Y,X
19 FOR X = 0 TO 200: NEXT: POKE S+24,0
20 FOR X = 0 TO 100: NEXT: GOTO 10
21 REM *** ABORT ONLY WITH RUN/STOP ! ***
More info about C64 audio and the SID chip:
- https://www.c64-wiki.com/wiki/SID (https://www.c64-wiki.com/wiki/SID)
- https://retro64.altervista.org/blog/commodore-64-sid-music-programming-with-basic-playing-a-note/?doing_wp_cron=1643166242.1954340934753417968750 (https://retro64.altervista.org/blog/commodore-64-sid-music-programming-with-basic-playing-a-note/?doing_wp_cron=1643166242.1954340934753417968750)
- https://www.commodore.ca/manuals/c64_users_guide/c64-users_guide-07-creating_sound.pdf (https://www.commodore.ca/manuals/c64_users_guide/c64-users_guide-07-creating_sound.pdf)
- https://link.springer.com/chapter/10.1007%2F978-1-4899-6787-9_15 (https://link.springer.com/chapter/10.1007%2F978-1-4899-6787-9_15)
- https://www.lemon64.com/forum/viewtopic.php?t=37474&sid=1aba7292b3288296ba46e0de5f0f90d7 (https://www.lemon64.com/forum/viewtopic.php?t=37474&sid=1aba7292b3288296ba46e0de5f0f90d7)
- https://nickm.com/post/2010/07/one-line-c64-basic-music/comment-page-1/ (https://nickm.com/post/2010/07/one-line-c64-basic-music/comment-page-1/)
- https://www.atarimagazines.com/compute/issue49/424_1_Programming_64_Sound.php (https://www.atarimagazines.com/compute/issue49/424_1_Programming_64_Sound.php)
- https://commodore.software/index.php?option=com_jdownloads&view=download&id=11854:jch-c64-basic-sounds-collection&catid=162&Itemid=126 (https://commodore.software/index.php?option=com_jdownloads&view=download&id=11854:jch-c64-basic-sounds-collection&catid=162&Itemid=126)
Here is a JavaScript SID emulator
https://csdb.dk/release/?id=145523 (https://csdb.dk/release/?id=145523)
How can we get this kind of audio control in QB64?