Subject-Was: Re: 7/4 Interval Name
' In the thread I wrote a tagline.
' Then I wrote a duet for it.
' Septimal: A musical reduced fraction that contains
' only factors of seven or less in its
' denominator and its numerator.
' http://ecn.ab.ca/~brewhaha/Sound/septimal.mp3
' CC-BY-NC-ND // Recordings are mine. Performance is not.
' Data: Part One, Part Two, Length...
' (Ignoring zeros after the first one...)
' Name of jump appears in comments between notes,
' unless it is obscure, when it is a reduced fraction.
' All names come from:
' http://www.huygens-fokker.org/docs/intervals.html
DATA 0, 0, 1, "Jerminal Rest"
DATA 18, 36, 6, "Octave"
DATA 24, 32, 3, "Perfect Fourth"
DATA 28, 36, 2, "Septimal Major Third"
DATA 36, 32, 3, "Major Second, tails in"
DATA 28, 28, 2, "Unison"
DATA 21, 24, 6, "Septimal Whole Tone"
DATA 28, 36, 3, "Septimal Major Third"
DATA 36, 21, 6, "Septimal Major Sixth, tails in"
DATA 28, 28, 6, "Unison"
DATA 0, 0, 20, "Terminal Rest"
OPTION BASE 1
DIM TwoPi AS DOUBLE
DIM pi AS DOUBLE
DIM temp AS DOUBLE
DIM BeatsPerSecond AS DOUBLE
DIM Angle(4) AS DOUBLE
DIM Velocity(4) AS DOUBLE
DIM Acceleration(4) AS DOUBLE
DIM Phase(4) AS DOUBLE
DIM note(4) AS INTEGER
DIM LastNote(4) AS INTEGER
DIM length AS INTEGER
DIM harmonics(4) 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(4) AS INTEGER
DIM glide AS INTEGER
DIM GlideTrim AS LONG
DIM test AS STRING
DIM TerminalAngle(4) AS DOUBLE
DIM DropAngle(4) AS DOUBLE
DIM PhaseDir(4) AS DOUBLE
DIM rationame AS STRING
PRINT
test = "0"
' I frequently flip that.
NumHarmonics = 2
BeatsPerSecond = 10#
pi = 3.141592653589793#
TwoPi = pi * 2
SampleRate = 8000
IF test = "0" THEN
OPEN "\sox\septimal.raw" FOR OUTPUT AS #4
END IF
' This is where I write a batch file that assumes where
' your FreeBasic and your Sound Exchange are.
' You might need to type it in manually the first time
' if all you hav is freebasic.
OPEN "septimal.bat" FOR OUTPUT AS #1
PRINT #1, "e:\progra~1\freebasic\fbc -lang qb d:\basic\septimal.bas"
PRINT #1, "septimal.exe"
PRINT #1, "cd \sox"
PRINT #1, "sox -c 2 -r"; SampleRate; " -sw septimal.raw septimal.wav stat"
CLOSE #1
' This maps powers of two to an Ay-sharp.
harmonics(1) = 440 / 2 ^ (1 / 12) ^ 73
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 11
READ note(1), note(2), length, rationame
PRINT #2, USING "DATA ##-,##-,##"; note(1); note(2); length
' That is for feeding transpositions back into this code.
' Sometimes I experiment with different basis frequencies on the
' left and right channels, and seldom is a work finished until
' both channels hav the same basis frequency, because that makes
' it more trival and less error prone to name ratios (intervals).
' The trend for my hand calculations is to raise numbers,
' and with a little tweaking, lower numbers often work.
IF g > 0 THEN
' SOUND note(2) * 13, 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/