Skip to content

Instantly share code, notes, and snippets.

@adamryman
Created January 13, 2017 18:00
Show Gist options
  • Select an option

  • Save adamryman/8f3d203d3a2849c84f31dc068e281b5d to your computer and use it in GitHub Desktop.

Select an option

Save adamryman/8f3d203d3a2849c84f31dc068e281b5d to your computer and use it in GitHub Desktop.

Revisions

  1. adamryman created this gist Jan 13, 2017.
    69 changes: 69 additions & 0 deletions viz.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    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 {

    }

    }



    }