Bohgosity BumaskiL
2011-06-03 22:11:28 UTC
' Newsgroups-Were: rec.food.chocolate
' This is source code for sound embedded in:
' http://ecn.ab.ca/~brewhaha/Biology/Cocoa_Brazil.htm
' It is for your perusal, and if you corrupt it enough, use.
' -CC- Released in a creative commons.
' -BY- http://ecn.ab.ca/~brewhaha/ BrewJay's Babble Bin
' -NC- Some commercial uses require permission
' -ND- Use in video or on web pages requires permission
' Parallel (Timbre) Harmonics
DATA 5,9,11,7,15,27,33,21,40,72,88,56
' Note, length, glide fraction
' 3=quarter, 6=half, 9=dotted half, 12=whole
' Zero is a rest.
DATA 1408,6,0
' Pythagorean minor third
DATA 1188,9,0
DATA 0,3,0
' Major Second
DATA 1056,9,0,0,6,0
' Perfect Fourth
DATA 1408,6,0
' Major Third
DATA 1760,6,0
' Minor Second
DATA 1584,9,0
DATA 0,3,0
' Major Second
DATA 1408,12,0
' Major Second
DATA 1584,9,4,0,3,0
' Septimal Major Third
DATA 1232,6,0
' Septimal Minor Third
DATA 1056,9,0
DATA 0,3,0
' Septimal Whole Tone
DATA 924,9,0,0,6,0
' Perfect Fourth
DATA 1232,6,0
' Septimal Major Third
DATA 1584,6,0
' Major Second
DATA 1408,9,0
DATA 0,3,0
' Septimal Whole Tone
DATA 1232,12,0
' Septimal Whole Tone
DATA 1408,9,4,0,3,0
' Pythagorean Minor Third
DATA 1188,6,0
' Undecimal Neutral Third
DATA 972,9,0
DATA 0,3,0
' Undecimal Neutral Second
DATA 891,9,0,0,6,0
' Perfect Fourth
DATA 1188,3,0
DATA 0,3,0
' Septendecimal Major Third
DATA 1496,9,0
' 17:15
DATA 1320,12,4,0,3,0
' Minor Second
DATA 1188,3,0
DATA 0,3,0
' Minor Second
DATA 1320,12,0
DATA 0,3,0
' Minor Second
DATA 1188,12,0,0,40,0
' The remainder of this message is public domain.
OPTION BASE 1
DIM harmonics(12) AS DOUBLE
DIM chanamp(12) AS SINGLE
DIM Velocity(12) AS DOUBLE
DIM Acceleration(12) AS DOUBLE
DIM Angle(12) AS DOUBLE
DIM Phase(12) AS DOUBLE
DIM TerminalAngle(12) AS DOUBLE
DIM DropAngle(12) AS DOUBLE
DIM PhaseDir(12) AS INTEGER
DIM BeatsPerSecond AS DOUBLE
DIM AmpLeft AS DOUBLE
DIM AmpRight AS DOUBLE
DIM temp AS DOUBLE
DIM TwoPi AS DOUBLE
DIM basis, note, length, glide AS SINGLE
DIM samplerate AS LONG
DIM amp AS LONG
DIM k, g, t, lastnote, samples, numharmonics AS INTEGER
DIM test AS STRING
test = "0"
numharmonics = 12
pi = 3.141592653589793#
TwoPi = pi * 2
samplerate = 44100
BeatsPerSecond = 20
lastnote = 0
skey = 1
OPEN "\sox\yumday.raw" FOR OUTPUT AS #2
OPEN "yumday.bat" FOR OUTPUT AS #1
PRINT #1, "fbc -lang qb yumday.bas"
PRINT #1, "yumday.exe"
PRINT #1, "cd \sox"
PRINT #1, "sox -c 2 -r"; samplerate; " -sw yumday.raw yumday.wav stat"
CLOSE #1
FOR k = 1 TO numharmonics
READ harmonics(k)
chanamp(k) = 5 / harmonics(k) / 2.25 * 32767
harmonics(k) = harmonics(k) / 50
NEXT k
100
FOR g = 1 TO 40
READ note, length, glide
' SOUND note, length
IF test = "0" THEN
IF note = 0 AND lastnote = 0 THEN
samples = samplerate * length / BeatsPerSecond
GOSUB 300
GOTO 75
END IF
IF note = 0 AND lastnote <> 0 THEN
GOSUB 250
lastnote = note
samples = samplerate * length / BeatsPerSecond
GOSUB 300
GOTO 75
END IF
IF note <> 0 AND lastnote = 0 THEN
lastnote = note
samples = samplerate * length / BeatsPerSecond
GOSUB 275
GOTO 75
END IF
IF note <> 0 AND lastnote <> 0 THEN
IF glide > 0 THEN
samples = samplerate * length / BeatsPerSecond / glide
GOSUB 300
END IF
samples = samplerate * length / BeatsPerSecond
lastnote = note
GOSUB 300
GOTO 75
END IF
END IF
75 NEXT g
IF test = "1" THEN END
CLOSE #2
END
250
FOR k = 1 TO numharmonics
temp = Angle(k) / TwoPi
Angle(k) = (temp - FIX(temp)) * TwoPi
IF Angle(k) > pi * 3 / 2 THEN
TerminalAngle(k) = pi * 3.5
PhaseDir(k) = 2
DropAngle(k) = pi * 2.5
ELSEIF Angle(k) > pi / 2 THEN
TerminalAngle(k) = pi * 2.5
PhaseDir(k) = 1
DropAngle(k) = pi * 3 / 2
ELSE
TerminalAngle(k) = pi * 3 / 2
PhaseDir(k) = -1
DropAngle(k) = pi / 2
END IF
NEXT k
260
FOR k = 1 TO numharmonics
Phase(k) = SIN(Angle(k))
SELECT CASE PhaseDir(k)
CASE 2
IF Angle(k) >= DropAngle(k) THEN
Phase(k) = Phase(k) / 2 + .5
END IF
CASE 1
IF Angle(k) >= DropAngle(k) THEN
Phase(k) = Phase(k) / 2 - .5
END IF
CASE -1
IF Angle(k) >= DropAngle(k) THEN
Phase(k) = Phase(k) / 2 + .5
END IF
END SELECT
IF Angle(k) < TerminalAngle(k) THEN
Angle(k) = Angle(k) + Velocity(k)
ELSE
Angle(k) = TerminalAngle(k)
END IF
NEXT k
GOSUB 400
FOR k = 1 TO numharmonics
IF Angle(k) < TerminalAngle(k) THEN GOTO 260
NEXT k
FOR k = 1 TO numharmonics
Angle(k) = Angle(k) - Angle(k)
NEXT k
RETURN
275
' This starts a wave from zero, using half the amplitude, a start
' from where sin(angle) = -1, and a bias of half. This cuts
' a leading click that I can hear on some equipment with some tunes.
FOR k = 1 TO numharmonics
Velocity(k) = TwoPi * lastnote * harmonics(k) / samplerate
Acceleration(k) = (TwoPi * note * harmonics(k) / samplerate -
Velocity(k)) / samples
PhaseDir(k) = 1
Angle(k) = 3 / 2 * pi
NEXT k
280
FOR k = 1 TO numharmonics
IF PhaseDir(k) = 1 THEN
Phase(k) = SIN(Angle(k)) / 2 + .5
ELSE
Phase(k) = SIN(Angle(k))
END IF
Angle(k) = Angle(k) + Velocity(k)
Velocity(k) = Velocity(k) + Acceleration(k)
NEXT k
samples = samples - 1
GOSUB 400
FOR k = 1 TO numharmonics
IF PhaseDir(k) = 1 THEN
Phase(k) = (Phase(k) - .5) * 2
END IF
IF Phase(k) > SIN(Angle(k)) THEN
PhaseDir(k) = -1
END IF
NEXT k
FOR k = 1 TO numharmonics
IF PhaseDir(k) = 1 GOTO 280
NEXT k
300
FOR k = 1 TO numharmonics
Velocity(k) = TwoPi * lastnote * harmonics(k) / samplerate
Acceleration(k) = (TwoPi * note * harmonics(k) / samplerate -
Velocity(k)) / samples
NEXT k
FOR t = 1 TO samples
FOR k = 1 TO numharmonics
Velocity(k) = Velocity(k) + Acceleration(k)
Angle(k) = Angle(k) + Velocity(k)
Phase(k) = SIN(Angle(k))
NEXT k
GOSUB 400
NEXT t
RETURN
400
AmpLeft = AmpLeft - AmpLeft
FOR k = 1 TO (numharmonics - 1) STEP 2
AmpLeft = AmpLeft + Phase(k) * chanamp(k)
NEXT k
amp = CINT(AmpLeft)
PRINT #2, CHR$(amp AND 255);
PRINT #2, CHR$((amp AND 65280) / 256);
AmpRight = AmpRight - AmpRight
FOR k = 2 TO numharmonics STEP 2
AmpRight = AmpRight + Phase(k) * chanamp(k)
NEXT k
amp = CINT(AmpRight)
PRINT #2, CHR$(amp AND 255);
PRINT #2, CHR$((amp AND 65280) / 256);
RETURN
END
' This is source code for sound embedded in:
' http://ecn.ab.ca/~brewhaha/Biology/Cocoa_Brazil.htm
' It is for your perusal, and if you corrupt it enough, use.
' -CC- Released in a creative commons.
' -BY- http://ecn.ab.ca/~brewhaha/ BrewJay's Babble Bin
' -NC- Some commercial uses require permission
' -ND- Use in video or on web pages requires permission
' Parallel (Timbre) Harmonics
DATA 5,9,11,7,15,27,33,21,40,72,88,56
' Note, length, glide fraction
' 3=quarter, 6=half, 9=dotted half, 12=whole
' Zero is a rest.
DATA 1408,6,0
' Pythagorean minor third
DATA 1188,9,0
DATA 0,3,0
' Major Second
DATA 1056,9,0,0,6,0
' Perfect Fourth
DATA 1408,6,0
' Major Third
DATA 1760,6,0
' Minor Second
DATA 1584,9,0
DATA 0,3,0
' Major Second
DATA 1408,12,0
' Major Second
DATA 1584,9,4,0,3,0
' Septimal Major Third
DATA 1232,6,0
' Septimal Minor Third
DATA 1056,9,0
DATA 0,3,0
' Septimal Whole Tone
DATA 924,9,0,0,6,0
' Perfect Fourth
DATA 1232,6,0
' Septimal Major Third
DATA 1584,6,0
' Major Second
DATA 1408,9,0
DATA 0,3,0
' Septimal Whole Tone
DATA 1232,12,0
' Septimal Whole Tone
DATA 1408,9,4,0,3,0
' Pythagorean Minor Third
DATA 1188,6,0
' Undecimal Neutral Third
DATA 972,9,0
DATA 0,3,0
' Undecimal Neutral Second
DATA 891,9,0,0,6,0
' Perfect Fourth
DATA 1188,3,0
DATA 0,3,0
' Septendecimal Major Third
DATA 1496,9,0
' 17:15
DATA 1320,12,4,0,3,0
' Minor Second
DATA 1188,3,0
DATA 0,3,0
' Minor Second
DATA 1320,12,0
DATA 0,3,0
' Minor Second
DATA 1188,12,0,0,40,0
' The remainder of this message is public domain.
OPTION BASE 1
DIM harmonics(12) AS DOUBLE
DIM chanamp(12) AS SINGLE
DIM Velocity(12) AS DOUBLE
DIM Acceleration(12) AS DOUBLE
DIM Angle(12) AS DOUBLE
DIM Phase(12) AS DOUBLE
DIM TerminalAngle(12) AS DOUBLE
DIM DropAngle(12) AS DOUBLE
DIM PhaseDir(12) AS INTEGER
DIM BeatsPerSecond AS DOUBLE
DIM AmpLeft AS DOUBLE
DIM AmpRight AS DOUBLE
DIM temp AS DOUBLE
DIM TwoPi AS DOUBLE
DIM basis, note, length, glide AS SINGLE
DIM samplerate AS LONG
DIM amp AS LONG
DIM k, g, t, lastnote, samples, numharmonics AS INTEGER
DIM test AS STRING
test = "0"
numharmonics = 12
pi = 3.141592653589793#
TwoPi = pi * 2
samplerate = 44100
BeatsPerSecond = 20
lastnote = 0
skey = 1
OPEN "\sox\yumday.raw" FOR OUTPUT AS #2
OPEN "yumday.bat" FOR OUTPUT AS #1
PRINT #1, "fbc -lang qb yumday.bas"
PRINT #1, "yumday.exe"
PRINT #1, "cd \sox"
PRINT #1, "sox -c 2 -r"; samplerate; " -sw yumday.raw yumday.wav stat"
CLOSE #1
FOR k = 1 TO numharmonics
READ harmonics(k)
chanamp(k) = 5 / harmonics(k) / 2.25 * 32767
harmonics(k) = harmonics(k) / 50
NEXT k
100
FOR g = 1 TO 40
READ note, length, glide
' SOUND note, length
IF test = "0" THEN
IF note = 0 AND lastnote = 0 THEN
samples = samplerate * length / BeatsPerSecond
GOSUB 300
GOTO 75
END IF
IF note = 0 AND lastnote <> 0 THEN
GOSUB 250
lastnote = note
samples = samplerate * length / BeatsPerSecond
GOSUB 300
GOTO 75
END IF
IF note <> 0 AND lastnote = 0 THEN
lastnote = note
samples = samplerate * length / BeatsPerSecond
GOSUB 275
GOTO 75
END IF
IF note <> 0 AND lastnote <> 0 THEN
IF glide > 0 THEN
samples = samplerate * length / BeatsPerSecond / glide
GOSUB 300
END IF
samples = samplerate * length / BeatsPerSecond
lastnote = note
GOSUB 300
GOTO 75
END IF
END IF
75 NEXT g
IF test = "1" THEN END
CLOSE #2
END
250
FOR k = 1 TO numharmonics
temp = Angle(k) / TwoPi
Angle(k) = (temp - FIX(temp)) * TwoPi
IF Angle(k) > pi * 3 / 2 THEN
TerminalAngle(k) = pi * 3.5
PhaseDir(k) = 2
DropAngle(k) = pi * 2.5
ELSEIF Angle(k) > pi / 2 THEN
TerminalAngle(k) = pi * 2.5
PhaseDir(k) = 1
DropAngle(k) = pi * 3 / 2
ELSE
TerminalAngle(k) = pi * 3 / 2
PhaseDir(k) = -1
DropAngle(k) = pi / 2
END IF
NEXT k
260
FOR k = 1 TO numharmonics
Phase(k) = SIN(Angle(k))
SELECT CASE PhaseDir(k)
CASE 2
IF Angle(k) >= DropAngle(k) THEN
Phase(k) = Phase(k) / 2 + .5
END IF
CASE 1
IF Angle(k) >= DropAngle(k) THEN
Phase(k) = Phase(k) / 2 - .5
END IF
CASE -1
IF Angle(k) >= DropAngle(k) THEN
Phase(k) = Phase(k) / 2 + .5
END IF
END SELECT
IF Angle(k) < TerminalAngle(k) THEN
Angle(k) = Angle(k) + Velocity(k)
ELSE
Angle(k) = TerminalAngle(k)
END IF
NEXT k
GOSUB 400
FOR k = 1 TO numharmonics
IF Angle(k) < TerminalAngle(k) THEN GOTO 260
NEXT k
FOR k = 1 TO numharmonics
Angle(k) = Angle(k) - Angle(k)
NEXT k
RETURN
275
' This starts a wave from zero, using half the amplitude, a start
' from where sin(angle) = -1, and a bias of half. This cuts
' a leading click that I can hear on some equipment with some tunes.
FOR k = 1 TO numharmonics
Velocity(k) = TwoPi * lastnote * harmonics(k) / samplerate
Acceleration(k) = (TwoPi * note * harmonics(k) / samplerate -
Velocity(k)) / samples
PhaseDir(k) = 1
Angle(k) = 3 / 2 * pi
NEXT k
280
FOR k = 1 TO numharmonics
IF PhaseDir(k) = 1 THEN
Phase(k) = SIN(Angle(k)) / 2 + .5
ELSE
Phase(k) = SIN(Angle(k))
END IF
Angle(k) = Angle(k) + Velocity(k)
Velocity(k) = Velocity(k) + Acceleration(k)
NEXT k
samples = samples - 1
GOSUB 400
FOR k = 1 TO numharmonics
IF PhaseDir(k) = 1 THEN
Phase(k) = (Phase(k) - .5) * 2
END IF
IF Phase(k) > SIN(Angle(k)) THEN
PhaseDir(k) = -1
END IF
NEXT k
FOR k = 1 TO numharmonics
IF PhaseDir(k) = 1 GOTO 280
NEXT k
300
FOR k = 1 TO numharmonics
Velocity(k) = TwoPi * lastnote * harmonics(k) / samplerate
Acceleration(k) = (TwoPi * note * harmonics(k) / samplerate -
Velocity(k)) / samples
NEXT k
FOR t = 1 TO samples
FOR k = 1 TO numharmonics
Velocity(k) = Velocity(k) + Acceleration(k)
Angle(k) = Angle(k) + Velocity(k)
Phase(k) = SIN(Angle(k))
NEXT k
GOSUB 400
NEXT t
RETURN
400
AmpLeft = AmpLeft - AmpLeft
FOR k = 1 TO (numharmonics - 1) STEP 2
AmpLeft = AmpLeft + Phase(k) * chanamp(k)
NEXT k
amp = CINT(AmpLeft)
PRINT #2, CHR$(amp AND 255);
PRINT #2, CHR$((amp AND 65280) / 256);
AmpRight = AmpRight - AmpRight
FOR k = 2 TO numharmonics STEP 2
AmpRight = AmpRight + Phase(k) * chanamp(k)
NEXT k
amp = CINT(AmpRight)
PRINT #2, CHR$(amp AND 255);
PRINT #2, CHR$((amp AND 65280) / 256);
RETURN
END