Created
January 13, 2017 18:00
-
-
Save adamryman/8f3d203d3a2849c84f31dc068e281b5d to your computer and use it in GitHub Desktop.
vizvizviz
This file contains hidden or 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 viz | |
import ( | |
"log" | |
"math" | |
"os" | |
"github.com/mjibson/go-dsp/fft" | |
"github.com/mjibson/go-dsp/wav" | |
) | |
var logger = log.New(os.Stderr, "Render", log.LstdFlags) | |
func Circle(w *wav.Wav, chordNum int) error { | |
seconds := w.Samples / int(w.SampleRate) | |
samplesPerChord := chordNum * w.Samples | |
frequencies := make([]float64, chordNum) | |
uniquesChan := make(chan float64) | |
uniques := make([]float64) | |
go sortUniques(uniques, uniquesChan) | |
_ = frequencies | |
// We stop early and use the rest of the data for the lasts chord | |
for i := 0; i < seconds; i++ { | |
nextWav, err := w.ReadFloats(int(w.SampleRate)) | |
if err != nil { | |
} | |
go func(index int, data []float64) { | |
next, err := processSample(nextWav) | |
if err != nil { | |
logger.Println(err) | |
return | |
} | |
frequencies[ii] = next | |
x <- | |
}(i, nextWave) | |
} | |
return nil | |
} | |
func processSample(sample []float32) (float64, error) { | |
ya = fft.FFTReal(float32To64(sample)) | |
return 0, nil | |
} | |
func float32To64(in []float32) []float64 { | |
out := make([]float64, len(in)) | |
for i, v := range in { | |
out[i] = float64(v) | |
} | |
return out | |
} | |
func sortUniques(uniques []float64, in chan float64) { | |
next := <- in | |
for i, v := range uniques { | |
if next >= v { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment