Discussion:
Cocoa Brazil
(too old to reply)
Bohgosity BumaskiL
2011-06-03 22:11:28 UTC
Permalink
' 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
Bohgosity BumaskiL
2011-06-03 23:06:33 UTC
Permalink
Post by Bohgosity BumaskiL
' Perfect Fourth
DATA 1584,9,0
' Minor Third
Instead of 17:15 and a named septendecimal ratio, and it sounds
better.
Bohgosity BumaskiL
2011-06-03 23:56:48 UTC
Permalink
' 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

' Pitch, Length, Glide Fraction;
' Ratio names are between notes.
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

' Perfect Fourth
DATA 1584,9,0
' Minor Third
DATA 1320,12,4,0,3,0
' Perfect Fourth
DATA 1760,3,0
DATA 0,3,0

' Octave
DATA 880,12,0
DATA 0,3,0

' Acute Fourth
DATA 1188,12,0,0,40,0

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
Bohgosity BumaskiL
2011-06-05 16:12:15 UTC
Permalink
' 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

' F# G G# A A# B C C# D D# E F
' 360,384,405,432,450,480, 500, 540, 576, 600, 640, 675
' 720,768,810,864,900,960,1000,1080,1152,1200,1280,1350

' See thread about Tweaking Terry Riley's Harp for meaning above.

' Parallel (Timbre) Harmonics:
DATA 5,9,25,81,121,49,11,7

' Pitch, Length, Glide Fraction;
' Ratio names are between notes.
DATA 720, 8,0
' Minor Third
DATA 600,12,0
DATA 0, 2,0

' Minor Second
DATA 540,12,0,0,4,0
' Minor Second
DATA 600, 8,0
' Perfect Fifth
DATA 900, 8,8
DATA 0, 1,0
' Major Second
DATA 800,12,0
DATA 0, 2,0

' Minor Second
DATA 720,12,0
' Minor Second
DATA 800,12,4,0,4,0
' Major Third
DATA 640, 8,0
' Pythagorean Minor Third
DATA 540,12,0
' Major Second
DATA 0, 2,0
DATA 480,12,0,0,4,0
' Major Second
DATA 540, 8,0
' Grave Fifth
DATA 800, 8,8
DATA 0, 1,0
' Minor Second
DATA 720,12,0
DATA 0, 2,0
' Major Second
DATA 640,12,0
' Major Second
DATA 720,12,4,0,4,0

' Minor Third
DATA 600, 8,0
' Minor Third
DATA 500,12,0

DATA 0, 4,0
' Minor Second
DATA 450, 8,0
DATA 0, 4,0

' Minor Second
DATA 500, 8,0
' Minor Seventh
DATA 900,12,8
' Major Third
DATA 720, 8,0
DATA 0, 4,0

' Minor Third
DATA 600, 6,0
' Perfect Fourth
DATA 800,12,0
DATA 0, 2,0
' Minor Second
DATA 720,12,0,0,40,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 = 8
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

temp = 1 / numharmonics
FOR k = 1 TO numharmonics
chanamp(1, k) = temp * k
chanamp(2, k) = 1 - temp * k
NEXT k


FOR k = 1 TO numharmonics
READ harmonics(k)
chanamp(1, k) = (5 / harmonics(k) / 1.6 * 32767) * chanamp(1,
k)
chanamp(2, k) = (5 / harmonics(k) / 1.6 * 32767) * chanamp(2,
k)
harmonics(k) = harmonics(k) / 25
NEXT k

100
FOR g = 1 TO 40
READ note, length, glide
IF g > 0 THEN
' SOUND note, length
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 / 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
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 = AmpRight - AmpRight
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
Eric Boon
2011-06-05 18:07:16 UTC
Permalink
On 6/5/11 6:12 PM, Bohgosity BumaskiL wrote:
(yawn)
Post by Bohgosity BumaskiL
400
AmpLeft = AmpLeft - AmpLeft
...
Post by Bohgosity BumaskiL
AmpRight = AmpRight - AmpRight
Why not just write 'AmpLeft = 0' and 'AmpRight = 0' ?
Bohgosity BumaskiL
2011-06-06 04:48:05 UTC
Permalink
Post by Eric Boon
(yawn)
Post by Bohgosity BumaskiL
400
AmpLeft = AmpLeft - AmpLeft
...
Post by Bohgosity BumaskiL
AmpRight = AmpRight - AmpRight
Why not just write 'AmpLeft = 0' and 'AmpRight = 0' ?
Efficiency: It's the lowest level code. No data fetch is involved in
the instruction to subtract a register from itself. If you ever read
professional assembler code, you'll see things like:
XOR EAX,EAX
Usually, being efficient is not worth it, until someone commissions
you to write hardware (even then, you hav deadlines, so usually the
best choice is to use someone else's code, and hope you select a
choice author). For example, working against efficiency, I just
rewrote my "even panning" (chanamp() initialization near the
beginning) code for accuracy and understandability, rather than
efficiency.

I'm glad I did, too, because that way I'm not rewriting constants to
normalize and balance my output every time I change timbre harmonics.
_______
When you see an open mind, you are probably attending an autopsy.
Eric Boon
2011-06-06 05:32:23 UTC
Permalink
Post by Eric Boon
(yawn)
Post by Bohgosity BumaskiL
400
AmpLeft = AmpLeft - AmpLeft
...
Post by Bohgosity BumaskiL
AmpRight = AmpRight - AmpRight
Why not just write 'AmpLeft = 0' and 'AmpRight = 0' ?
Efficiency: It's the lowest level code. No data fetch is involved in the
instruction to subtract a register from itself. If you ever read
XOR EAX,EAX
Not only have I read professional assembler code, I've even written it.
You're not writing assembler here, but BASIC. You've got a compiler
to do all that optimization stuff for you. This is not being efficient,
this is just being obscure.

Continue reading on narkive:
Loading...