Author Topic: SID-chip like audio in QB64?  (Read 3224 times)

0 Members and 1 Guest are viewing this topic.

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
SID-chip like audio in QB64?
« 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/
which enables programming audio and sound synthesis in JavaScript. Here's an example
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:
^^^
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:
Code: [Select]
For   Type
+     [
(     *
)     (
*     =
=     /
:     `
etc.

Some sample sound programs:

From https://nickm.com/post/2010/07/one-line-c64-basic-music/comment-page-1/:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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:

Here is a JavaScript SID emulator
https://csdb.dk/release/?id=145523

How can we get this kind of audio control in QB64?

« Last Edit: January 26, 2022, 03:10:19 am by madscijr »