Created
July 6, 2017 16:52
-
-
Save superfashi/7254a03172135a2f04b4c2ea8bc0a710 to your computer and use it in GitHub Desktop.
for the paper "Conversion Between Mathematical Functions And Sound"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"os" | |
"math" | |
"github.com/youpy/go-wav" | |
) | |
const ( | |
numChannels uint16 = 1 | |
sampleRate uint32 = 44100 | |
bitsPerSample uint16 = 16 | |
numSamples uint32 = sampleRate * 1 | |
timeStep float64 = 1. / float64(sampleRate) | |
amplitude = 1 << (bitsPerSample - 1) | |
frequency = 440 // Standard A | |
) | |
var samples [numSamples]wav.Sample | |
func getFValue(t float64) int { | |
return // value for certain time `t` | |
} | |
func main() { | |
curStep := 0. | |
for i := range samples { | |
samples[i] = wav.Sample{Values: [2]int{getFValue(curStep), 0}} | |
curStep += timeStep | |
} | |
fil, err := os.Create("out.wav") | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer fil.Close() | |
if err := wav.NewWriter(fil, numSamples, numChannels, sampleRate, bitsPerSample).WriteSamples(samples[:]); err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment