Bohgosity BumaskiL
2011-09-29 06:47:17 UTC
' This is source for the new background sound at:
' http://ecn.ab.ca/~brewhaha/Sound/Just_Intonation.htm
' It is also a demonstration of numbers in that document.
' Source 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- No fees above internet cost may be taken for this.
' -ND- Use in video or on web pages requires permission.
' Recordings are mine. Performance is not.
' Parallel (Timbre) Harmonics:
DATA 3,7,8,5
' Pitch, Length, Glide Fraction;
' Ratio names are between notes.
DATA 0, 1, 0
DATA 360, 3, 0
DATA 0, 1, 0
' Major Sixth
DATA 600, 2, 0
' Minor Second
DATA 540, 4, 0
' Minor Second
DATA 600, 4, 0
DATA 0, 4, 0
' Unison
DATA 600, 3, 0
DATA 0, 1, 0
' Minor Second
DATA 540, 2, 0
' Major Second
DATA 480, 4, 0
' Major Second
DATA 540, 4, 0
DATA 0, 4, 0
' Minor Second
DATA 600, 3, 0
DATA 0, 1, 0
' Minor Second
DATA 540, 2, 0
' Major Second
DATA 480, 4, 0
' Major Second
DATA 540, 2, 8
' Perfect Fourth
DATA 0, 1, 0
DATA 720, 6, 0
' Perfect Fifth
DATA 480, 4, 0
DATA 0, 4, 0
' Minor Sixth
DATA 320, 3, 0
DATA 0, 1, 0
' Pythagorean Major Sixth
DATA 540, 2, 0
' Major Second
DATA 480, 4, 0
' Major Second
DATA 540, 4, 0
DATA 0, 4, 0
' Unison
DATA 540, 3, 0
DATA 0, 1, 0
' Major Second
DATA 480, 2, 0
' Minor Second
DATA 432, 4, 0
' Minor Second
DATA 480, 4, 0
DATA 0, 4, 0
' Major Second
DATA 540, 3, 0
DATA 0, 1, 0
' Major Second
DATA 480, 2, 0
' Minor Second
DATA 432, 4, 0
' Minor Second
DATA 480, 2, 0
DATA 0, 1, 0
' Perfect Fourth
DATA 640, 6, 0
' Grave Fifth
DATA 432, 4, 0
DATA 0, 4, 0
' Perfect Fifth
DATA 288, 3, 0
DATA 0, 1, 0
' Perfect Fifth
DATA 432, 2, 0
' Minor Semitone
DATA 405, 4, 0
' Minor Semitone
DATA 432, 4, 0
DATA 0, 4, 0
' Unison
DATA 432, 3, 0
DATA 0, 1, 0
' Major Second
DATA 384, 2, 0
' Minor Semitone
DATA 360, 4, 0
' Minor Semitone
DATA 384, 4, 0
DATA 0, 4, 0
' Major Second
DATA 480, 3, 0
DATA 0, 1, 0
' Minor Second
DATA 432, 2, 0
' Major Second
DATA 384, 4, 0
' Major Second
DATA 480, 2, 0
' Minor Third
DATA 576, 4, 0
DATA 0, 1, 0
' Perfect Fifth
DATA 384, 4, 0
DATA 0, 1, 0
' Major Second
DATA 432, 6, 0
DATA 0, 6, 0
' Classic Augmented Fourth
DATA 600, 3, 0
DATA 0, 1, 0
' Minor Second
DATA 540, 2, 0
' Major Second
DATA 480, 4, 0
' Major Second
DATA 540, 2, 0
' Perfect Fourth
DATA 720, 4, 0
DATA 0, 2, 0
' Octave
DATA 360, 6, 0
DATA 0, 1, 0
' Perfect Fourth
DATA 480, 6, 0
' F# G G# A A# B C C# D D# E F
' 288 320
' 360,384,405,432,450,480, 500, 540, 576, 600, 640, 675
' 720,768,810,864,900,960,1000,1080,1152,1200,1280,1350
DATA 0,24, 0
' The rest of this message is public domain.
OPTION BASE 1
DIM harmonics(8) AS DOUBLE
DIM chanamp(2, 8) AS DOUBLE
DIM velocity(8) AS DOUBLE
DIM acceleration(8) AS DOUBLE
DIM Angle(8) AS DOUBLE
DIM Phase(8) AS DOUBLE
DIM TerminalAngle(8) AS DOUBLE
DIM DropAngle(8) AS DOUBLE
DIM PhaseDir(8) 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 = 4
pi = 3.141592653589793#
TwoPi = pi * 2
samplerate = 44100
BeatsPerSecond = 9
lastnote = 0
' For this to work, fbc and waveedit must be in your path.
OPEN "\sox\hask.raw" FOR OUTPUT AS #2
OPEN "hask.bat" FOR OUTPUT AS #1
PRINT #1, "fbc -lang qb hask.bas"
PRINT #1, "hask.exe"
PRINT #1, "cd \sox"
PRINT #1, "sox -c 2 -r"; samplerate; " -sw hask.raw hask.wav stat"
PRINT #1, "WaveEdit.exe c:\sox\hask.wav"
PRINT #1, "cd \basic"
CLOSE #1
temp = 1 / numharmonics
' This pans harmonics in relation to one.
FOR k = 1 TO numharmonics
chanamp(1, k) = temp * k
chanamp(2, k) = 1 - temp * k
NEXT k
' This cuts amplitude in proportion to a harmonic.
FOR k = 1 TO numharmonics
READ harmonics(k)
chanamp(1, k) = (2 / harmonics(k) * 32767) * chanamp(1, k)
chanamp(2, k) = (2 / harmonics(k) * 32767) * chanamp(2, k)
harmonics(k) = harmonics(k) / 5
NEXT k
100
FOR g = 1 TO 77
READ note, length, glide
IF g > 0 THEN
' SOUND note, length * 2
END IF
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
samples = samples / 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
acceleration(k) = (acceleration(k) - 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
acceleration(k) = (acceleration(k) - 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 = 0
FOR k = 1 TO numharmonics
AmpLeft = AmpLeft + Phase(k) * chanamp(1, k)
NEXT k
amp = CINT(AmpLeft)
PRINT #2, CHR$(amp AND 255);
PRINT #2, CHR$((amp AND 65280) / 256);
AmpRight = 0
FOR k = 1 TO numharmonics
AmpRight = AmpRight + Phase(k) * chanamp(2, k)
NEXT k
amp = CINT(AmpRight)
PRINT #2, CHR$(amp AND 255);
PRINT #2, CHR$((amp AND 65280) / 256);
RETURN
' http://ecn.ab.ca/~brewhaha/Sound/Just_Intonation.htm
' It is also a demonstration of numbers in that document.
' Source 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- No fees above internet cost may be taken for this.
' -ND- Use in video or on web pages requires permission.
' Recordings are mine. Performance is not.
' Parallel (Timbre) Harmonics:
DATA 3,7,8,5
' Pitch, Length, Glide Fraction;
' Ratio names are between notes.
DATA 0, 1, 0
DATA 360, 3, 0
DATA 0, 1, 0
' Major Sixth
DATA 600, 2, 0
' Minor Second
DATA 540, 4, 0
' Minor Second
DATA 600, 4, 0
DATA 0, 4, 0
' Unison
DATA 600, 3, 0
DATA 0, 1, 0
' Minor Second
DATA 540, 2, 0
' Major Second
DATA 480, 4, 0
' Major Second
DATA 540, 4, 0
DATA 0, 4, 0
' Minor Second
DATA 600, 3, 0
DATA 0, 1, 0
' Minor Second
DATA 540, 2, 0
' Major Second
DATA 480, 4, 0
' Major Second
DATA 540, 2, 8
' Perfect Fourth
DATA 0, 1, 0
DATA 720, 6, 0
' Perfect Fifth
DATA 480, 4, 0
DATA 0, 4, 0
' Minor Sixth
DATA 320, 3, 0
DATA 0, 1, 0
' Pythagorean Major Sixth
DATA 540, 2, 0
' Major Second
DATA 480, 4, 0
' Major Second
DATA 540, 4, 0
DATA 0, 4, 0
' Unison
DATA 540, 3, 0
DATA 0, 1, 0
' Major Second
DATA 480, 2, 0
' Minor Second
DATA 432, 4, 0
' Minor Second
DATA 480, 4, 0
DATA 0, 4, 0
' Major Second
DATA 540, 3, 0
DATA 0, 1, 0
' Major Second
DATA 480, 2, 0
' Minor Second
DATA 432, 4, 0
' Minor Second
DATA 480, 2, 0
DATA 0, 1, 0
' Perfect Fourth
DATA 640, 6, 0
' Grave Fifth
DATA 432, 4, 0
DATA 0, 4, 0
' Perfect Fifth
DATA 288, 3, 0
DATA 0, 1, 0
' Perfect Fifth
DATA 432, 2, 0
' Minor Semitone
DATA 405, 4, 0
' Minor Semitone
DATA 432, 4, 0
DATA 0, 4, 0
' Unison
DATA 432, 3, 0
DATA 0, 1, 0
' Major Second
DATA 384, 2, 0
' Minor Semitone
DATA 360, 4, 0
' Minor Semitone
DATA 384, 4, 0
DATA 0, 4, 0
' Major Second
DATA 480, 3, 0
DATA 0, 1, 0
' Minor Second
DATA 432, 2, 0
' Major Second
DATA 384, 4, 0
' Major Second
DATA 480, 2, 0
' Minor Third
DATA 576, 4, 0
DATA 0, 1, 0
' Perfect Fifth
DATA 384, 4, 0
DATA 0, 1, 0
' Major Second
DATA 432, 6, 0
DATA 0, 6, 0
' Classic Augmented Fourth
DATA 600, 3, 0
DATA 0, 1, 0
' Minor Second
DATA 540, 2, 0
' Major Second
DATA 480, 4, 0
' Major Second
DATA 540, 2, 0
' Perfect Fourth
DATA 720, 4, 0
DATA 0, 2, 0
' Octave
DATA 360, 6, 0
DATA 0, 1, 0
' Perfect Fourth
DATA 480, 6, 0
' F# G G# A A# B C C# D D# E F
' 288 320
' 360,384,405,432,450,480, 500, 540, 576, 600, 640, 675
' 720,768,810,864,900,960,1000,1080,1152,1200,1280,1350
DATA 0,24, 0
' The rest of this message is public domain.
OPTION BASE 1
DIM harmonics(8) AS DOUBLE
DIM chanamp(2, 8) AS DOUBLE
DIM velocity(8) AS DOUBLE
DIM acceleration(8) AS DOUBLE
DIM Angle(8) AS DOUBLE
DIM Phase(8) AS DOUBLE
DIM TerminalAngle(8) AS DOUBLE
DIM DropAngle(8) AS DOUBLE
DIM PhaseDir(8) 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 = 4
pi = 3.141592653589793#
TwoPi = pi * 2
samplerate = 44100
BeatsPerSecond = 9
lastnote = 0
' For this to work, fbc and waveedit must be in your path.
OPEN "\sox\hask.raw" FOR OUTPUT AS #2
OPEN "hask.bat" FOR OUTPUT AS #1
PRINT #1, "fbc -lang qb hask.bas"
PRINT #1, "hask.exe"
PRINT #1, "cd \sox"
PRINT #1, "sox -c 2 -r"; samplerate; " -sw hask.raw hask.wav stat"
PRINT #1, "WaveEdit.exe c:\sox\hask.wav"
PRINT #1, "cd \basic"
CLOSE #1
temp = 1 / numharmonics
' This pans harmonics in relation to one.
FOR k = 1 TO numharmonics
chanamp(1, k) = temp * k
chanamp(2, k) = 1 - temp * k
NEXT k
' This cuts amplitude in proportion to a harmonic.
FOR k = 1 TO numharmonics
READ harmonics(k)
chanamp(1, k) = (2 / harmonics(k) * 32767) * chanamp(1, k)
chanamp(2, k) = (2 / harmonics(k) * 32767) * chanamp(2, k)
harmonics(k) = harmonics(k) / 5
NEXT k
100
FOR g = 1 TO 77
READ note, length, glide
IF g > 0 THEN
' SOUND note, length * 2
END IF
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
samples = samples / 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
acceleration(k) = (acceleration(k) - 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
acceleration(k) = (acceleration(k) - 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 = 0
FOR k = 1 TO numharmonics
AmpLeft = AmpLeft + Phase(k) * chanamp(1, k)
NEXT k
amp = CINT(AmpLeft)
PRINT #2, CHR$(amp AND 255);
PRINT #2, CHR$((amp AND 65280) / 256);
AmpRight = 0
FOR k = 1 TO numharmonics
AmpRight = AmpRight + Phase(k) * chanamp(2, k)
NEXT k
amp = CINT(AmpRight)
PRINT #2, CHR$(amp AND 255);
PRINT #2, CHR$((amp AND 65280) / 256);
RETURN