Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@superfashi
Created July 6, 2017 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superfashi/7254a03172135a2f04b4c2ea8bc0a710 to your computer and use it in GitHub Desktop.
Save superfashi/7254a03172135a2f04b4c2ea8bc0a710 to your computer and use it in GitHub Desktop.
for the paper "Conversion Between Mathematical Functions And Sound"
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