Discussion:
No way to trade RainForest for coffee land is fair.
(too old to reply)
Bohgosity BumaskiL
2011-06-23 18:19:09 UTC
Permalink
' http://ecn.ab.ca/~brewhaha/Sound/priceless.mp3
' CC-BY-NC-ND // Recordings are mine. Performance is not.

' Subject-Was: COFFEE THE WONDER DRUG...

' Please note crossposting in replies,
' quote only issues you will address,
' and you are welcome to delete all
' of my text, or take it from the
' orijinator of this thread, in mormonism.

' I hate reading about "antioxidant polyphenols" on coffee cans,
' because I know it is what you want to hear when you buy the
' mostly commonly used drug in the western world, so all those
' words do is remind me that antioxidants are over-rated.

' Coffee causes cancer. Coffeine does not.

' -CC- Released in a Creative Commons
' -BY- BrewJay's Babble Bin
' -NC- Some commercial uses require permission.
' -ND- Recordings are mine. Performance is not.

' Data: Part One, Part Two, Length, Concert Ratio Name...
' All names come from:
' http://www.huygens-fokker.org/docs/intervals.html
DATA 0, 0, 1, "Jerminal Rest"
DATA 405, 810, 6, "Octave"
DATA 480, 720, 6, "Perfect Fifth"
DATA 400, 480, 3, "Minor Third"
DATA 648, 540, 6, "Minor Third, tails in"
DATA 0, 0, 2, "Rest"
DATA 720, 810, 6, "Major Second"
DATA 640, 720, 3, "Major Second"
DATA 540, 540, 6, "Unison"
DATA 432, 432, 5, "Unison"
DATA 0, 0, 2, "Rest"
DATA 720, 810, 3, "Major Second"
DATA 0, 0, 3, "Rest"
DATA 540, 720, 3, "Perfect Fourth"
DATA 432, 540, 6, "Major Third"
DATA 720, 810, 3, "Major Second"
DATA 0, 0, 3, "Rest"
DATA 640, 640, 6, "Unison"
DATA 0, 0, 20, "Terminal Rest"

' The remainder of this message is public domain.

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

OPTION BASE 1
DIM TwoPi AS DOUBLE
DIM pi AS DOUBLE
DIM temp AS DOUBLE
DIM BeatsPerSecond AS DOUBLE
DIM Angle(2) AS DOUBLE
DIM Velocity(2) AS DOUBLE
DIM Acceleration(2) AS DOUBLE
DIM Phase(2) AS DOUBLE
DIM note(2) AS INTEGER
DIM LastNote(2) AS INTEGER
DIM length AS INTEGER
DIM harmonics(2) AS DOUBLE
DIM Samples AS LONG
DIM t AS LONG
DIM SampleRate AS LONG
DIM k AS INTEGER
DIM g AS INTEGER
DIM amp AS INTEGER
DIM basis AS INTEGER
DIM NumHarmonics AS INTEGER
DIM Sign(2) AS INTEGER
DIM glide AS INTEGER
DIM GlideTrim AS LONG
DIM test AS STRING
DIM TerminalAngle(2) AS DOUBLE
DIM DropAngle(2) AS DOUBLE
DIM PhaseDir(2) AS DOUBLE
DIM rationame AS STRING

PRINT
test = "0"
' I frequently flip that.
NumHarmonics = 2
BeatsPerSecond = 10#
pi = 3.141592653589793#
TwoPi = pi * 2
SampleRate = 44100

IF test = "0" THEN
OPEN "\sox\forest.raw" FOR OUTPUT AS #4
END IF

' This batch file will compile and view
' if nero waveedit and fbc are in your path.
OPEN "forest.bat" FOR OUTPUT AS #1
PRINT #1, "fbc -lang qb c:\basic\forest.bas"
PRINT #1, "forest.exe"
PRINT #1, "cd \sox"
PRINT #1, "sox -c 2 -r"; SampleRate; " -sw forest.raw forest.wav stat"
PRINT #1, "waveedit c:\sox\forest.wav"
CLOSE #1

' This maps 405 (tonic) to a 12-TET Ay.
harmonics(1) = (440 / 2 ^ (1 / 12) ^ 24) / 405
harmonics(2) = harmonics(1)
FOR k = 1 TO NumHarmonics
note(k) = 0
LastNote(k) = 0
NEXT k

OPEN "con" FOR APPEND AS #2

glide = 30
100
FOR g = 1 TO 19
READ note(1), note(2), length, rationame
PRINT #2, USING "DATA ##-,##-,## &"; note(1); note(2); length;
rationame
' That is for feeding transpositions back into this code, although
' am using a tuning that maps roughly to 12-TET, so I did not use it.
IF g > 0 THEN
' SOUND note(1) * harmonics(1), length * 2
END IF
IF test = "0" THEN
IF note(1) = 0 AND LastNote(1) = 0 THEN
Samples = SampleRate * length / BeatsPerSecond
GOSUB 300
GOTO 75
END IF
IF note(1) = 0 AND LastNote(1) <> 0 THEN
GOSUB 250
FOR k = 1 TO NumHarmonics
LastNote(k) = note(k)
NEXT k
Samples = SampleRate * length / BeatsPerSecond
GOSUB 300
GOTO 75
END IF
IF LastNote(1) = 0 AND note(1) <> 0 THEN
FOR k = 1 TO NumHarmonics
LastNote(k) = note(k)
NEXT k
Samples = SampleRate * length / BeatsPerSecond
GOSUB 275
GOTO 75
END IF
IF note(1) <> 0 AND LastNote(1) <> 0 THEN
Samples = SampleRate * length / BeatsPerSecond
/ glide
GlideTrim = Samples
GOSUB 300
Samples = SampleRate * length /
BeatsPerSecond - GlideTrim
FOR k = 1 TO NumHarmonics
LastNote(k) = note(k)
NEXT k
GOSUB 300
GOTO 75
END IF
END IF

75 NEXT g
CLOSE #4

END

' *Neat* Silencer -- finishes a wave like 275 starts one.
' When it reaches a peak or a trough, then it cuts amplitude in half
' and biases it by half.
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) = 1
DropAngle(k) = pi * 2.5
ELSEIF Angle(k) > pi / 2 THEN
TerminalAngle(k) = pi * 2.5
PhaseDir(k) = 0
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 1
IF Angle(k) >= DropAngle(k) THEN
Phase(k) = Phase(k) / 2 + .5
END IF
CASE 0
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(k) * harmonics(k) / SampleRate
Acceleration(k) = (TwoPi * note(k) * 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
' Calculate constants of change for write loop.
FOR k = 1 TO NumHarmonics
Velocity(k) = TwoPi * LastNote(k) * harmonics(k) / SampleRate
Acceleration(k) = (TwoPi * note(k) * harmonics(k) /
SampleRate - Velocity(k)) / Samples
NEXT k

' Main write loop. Static Phases problem solved at 250.
FOR t = 1 TO Samples
FOR k = 1 TO NumHarmonics
Phase(k) = SIN(Angle(k))
NEXT k

GOSUB 400

FOR k = 1 TO NumHarmonics
Angle(k) = Angle(k) + Velocity(k)
Velocity(k) = Velocity(k) + Acceleration(k)
NEXT k
NEXT t
RETURN

400
' Write a sample.
amp = CINT(Phase(1) * 32000)
PRINT #4, CHR$(amp AND 255);
PRINT #4, CHR$((amp AND 65280) / 256);

amp = CINT(Phase(2) * 32000)
PRINT #4, CHR$(amp AND 255);
PRINT #4, CHR$((amp AND 65280) / 256);
RETURN

' http://ecn.ab.ca/~brewhaha/Sound/
Bohgosity BumaskiL
2011-07-11 00:26:40 UTC
Permalink
-----BEGIN PGP SIGNED MESSAGE-----

' This is source for the background sound on:
' http://ecn.ab.ca/~brewhaha/Biology/Banana_Peel_Tea.htm
' CC-BY-NC-ND // Recordings are mine. Performance is not.
' _______________________________________________________

' Please note crossposting in replies,
' quote only issues you will address,
' and you are welcome to delete all
' of my text, or take it from the
' orijinator of this thread, in mormonism.

' -CC- Released in a Creative Commons
' -BY- BrewJay's Babble Bin
' -NC- Some commercial uses require permission.
' -ND- Recordings are mine. Performance is not.

' Data: Part One, Part Two, Length, Concert Ratio Name...
' Names come from (square brackets indicate synthesis):
' http://www.huygens-fokker.org/docs/intervals.html
DATA 0, 0, 1, "Jerminal Rest"
DATA 24, 24, 6, "Unison"
DATA 40, 16, 6, "[Major Eleventh]"
DATA 36, 20, 9, "Minor Seventh"
DATA 30, 24, 12, "Major Third"
DATA 0, 0, 3, "Rest"
DATA 27, 27, 6, "Unison"
DATA 36, 36, 6, "unison"
DATA 30, 18, 9, "Major Sixth"
DATA 27, 27, 12, "Unison"
DATA 0, 0, 3, "Rest"
DATA 40, 30, 6, "Perfect Fourth"
DATA 36, 24, 9, "Major Second"
DATA 18, 20, 12, "Minor Second, tails in"
DATA 36, 27, 9, "Perfect Fourth"
DATA 24, 32, 12, "Perfect Fourth"
DATA 0, 0, 30, "Terminal Rest"

' Notice that 40:27 (grave fifth) occurs in series and not
' in concert. The remainder of this message is public domain.

OPTION BASE 1
DIM TwoPi AS DOUBLE
DIM pi AS DOUBLE
DIM temp AS DOUBLE
DIM BeatsPerSecond AS DOUBLE
DIM Angle(2) AS DOUBLE
DIM Velocity(2) AS DOUBLE
DIM Acceleration(2) AS DOUBLE
DIM Phase(2) AS DOUBLE
DIM note(2) AS INTEGER
DIM LastNote(2) AS INTEGER
DIM length AS INTEGER
DIM harmonics(2) AS DOUBLE
DIM samples AS LONG
DIM t AS LONG
DIM SampleRate AS LONG
DIM k AS INTEGER
DIM g AS INTEGER
DIM amp AS INTEGER
DIM basis AS INTEGER
DIM NumHarmonics AS INTEGER
DIM Sign(2) AS INTEGER
DIM glide AS INTEGER
DIM GlideTrim AS LONG
DIM test AS STRING
DIM TerminalAngle(2) AS DOUBLE
DIM DropAngle(2) AS DOUBLE
DIM PhaseDir(2) AS DOUBLE
DIM rationame AS STRING

PRINT
test = "1"
' I frequently flip that.
NumHarmonics = 2
BeatsPerSecond = 15#
pi = 3.141592653589793#
TwoPi = pi * 2
SampleRate = 44100

IF test = "0" THEN
OPEN "\sox\forest.raw" FOR OUTPUT AS #4
END IF

' This batch file will compile and view
' if nero waveedit and fbc are in your path.
OPEN "forest.bat" FOR OUTPUT AS #1
PRINT #1, "fbc -lang qb c:\basic\forest.bas"
PRINT #1, "forest.exe"
PRINT #1, "cd \sox"
PRINT #1, "sox -c 2 -r"; SampleRate; " -sw forest.raw forest.wav stat"
PRINT #1, "waveedit c:\sox\forest.wav"
CLOSE #1

' All of my notes were divisible by fifteen, so I divided
' them by fifteen to better understand what I was doing.
' B C C#, D , D#, E F F# G G# A A#
' 360,384,405,432,450,480, 500, 540, 576, 600, 640, 675
' 720,768,810,864,900,960,1000,1080,1152,1200,1280,1350

' This maps 24 (tonic) to a 12-TET C-sharp.
harmonics(1) = (440 / 2 ^ (1 / 12) ^ 20) / 24
harmonics(2) = harmonics(1)
FOR k = 1 TO NumHarmonics
note(k) = 0
LastNote(k) = 0
NEXT k

OPEN "con" FOR APPEND AS #2

glide = 30
100
FOR g = 1 TO 17
READ note(1), note(2), length, rationame
PRINT #2, USING "DATA ###-,"; note(1) * 15;
PRINT #2, USING "###-,##"; note(2) * 15; length;
PRINT #2, ", "; rationame

' That is for feeding transpositions back into this code, although I
' am using a tuning that maps roughly to 12-TET, so I did not use it.
IF g > 0 THEN
SOUND note(1) * harmonics(2), length
END IF
IF test = "0" THEN
IF note(1) = 0 AND LastNote(1) = 0 THEN
samples = SampleRate * length / BeatsPerSecond
GOSUB 300
GOTO 75
END IF
IF note(1) = 0 AND LastNote(1) <> 0 THEN
GOSUB 250
FOR k = 1 TO NumHarmonics
LastNote(k) = note(k)
NEXT k
samples = SampleRate * length / BeatsPerSecond
GOSUB 300
GOTO 75
END IF
IF LastNote(1) = 0 AND note(1) <> 0 THEN
FOR k = 1 TO NumHarmonics
LastNote(k) = note(k)
NEXT k
samples = SampleRate * length / BeatsPerSecond
GOSUB 275
GOTO 75
END IF
IF note(1) <> 0 AND LastNote(1) <> 0 THEN
samples = SampleRate * length / BeatsPerSecond
samples = samples / glide
GlideTrim = samples
GOSUB 300
samples = SampleRate * length / BeatsPerSecond
samples = samples - GlideTrim
FOR k = 1 TO NumHarmonics
LastNote(k) = note(k)
NEXT k
GOSUB 300
GOTO 75
END IF
END IF

75 NEXT g
CLOSE #4

END

' *Neat* Silencer -- finishes a wave like 275 starts one.
' When it reaches a peak or a trough, then it cuts amplitude in half
' and biases it by half.
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) = 1
DropAngle(k) = pi * 2.5
ELSEIF Angle(k) > pi / 2 THEN
TerminalAngle(k) = pi * 2.5
PhaseDir(k) = 0
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 1
IF Angle(k) >= DropAngle(k) THEN
Phase(k) = Phase(k) / 2 + .5
END IF
CASE 0
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(k) * harmonics(k) / SampleRate
Acceleration(k) = TwoPi * note(k) * 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
' Calculate constants of change for write loop.
FOR k = 1 TO NumHarmonics
Velocity(k) = TwoPi * LastNote(k) * harmonics(k) / SampleRate
Acceleration(k) = TwoPi * note(k) * harmonics(k) / SampleRate
Acceleration(k) = (Acceleration(k) - Velocity(k)) / samples
NEXT k

' Main write loop. Static Phases problem solved at 250.
FOR t = 1 TO samples
FOR k = 1 TO NumHarmonics
Phase(k) = SIN(Angle(k))
NEXT k

GOSUB 400

FOR k = 1 TO NumHarmonics
Angle(k) = Angle(k) + Velocity(k)
Velocity(k) = Velocity(k) + Acceleration(k)
NEXT k
NEXT t
RETURN

400
' Write a sample.
amp = CINT(Phase(1) * 32000)
PRINT #4, CHR$(amp AND 255);
PRINT #4, CHR$((amp AND 65280) / 256);

amp = CINT(Phase(2) * 32000)
PRINT #4, CHR$(amp AND 255);
PRINT #4, CHR$((amp AND 65280) / 256);
RETURN

' http://ecn.ab.ca/~brewhaha/Sound/
rakman
2011-07-11 10:06:45 UTC
Permalink
Posting off topic crap isn't fair either

Continue reading on narkive:
Loading...