Exemplo n.º 1
0
func main() {
	var err error
	e := func() {
		if err != nil {
			fmt.Printf("Error: %v\n", err)
			os.Exit(1)
		}
	}
	devs, err := tm.ListDevices()
	e()
	showDevices(devs)
	dev, err := selectDevice(devs)
	e()
	fmt.Printf("Device selected: %v\n", dev.Name)
	datachan, closechan, errchan, err := tm.MakeInputChannel(dev)
	e()
	fmt.Println("Got data channel, etc....")
	go func() {
		for err := range errchan {
			fmt.Printf("Error from errchan: $v\n", err)
		}
	}()
	fmt.Println("Attempting to read from data channel....")
	tms := <-datachan
	fmt.Println("Got first sample!")
	go func() { closechan <- true }()
	fmt.Printf("We have data at %v Hz! here it is: %v\n", tms.SampleHz, tms.Samples)
	ffted := tm.SamplesToFrequencies(tms)
	fmt.Printf("We have a Fast Fourier Transformed sample with consecutive frequencies varying by %v Hz! Here are the frequencies: %v\n", ffted.DeltaHz, ffted.Freqs)
	unffted := tm.FrequenciesToSamples(ffted)
	fmt.Printf("Back from FFT! We have data at %v Hz! here it is: %v\n", unffted.SampleHz, unffted.Samples)
}
Exemplo n.º 2
0
func main() {
	var tms tm.TMSnippet
	tms.SampleHz = 1 // Only kept track of by FFT functions, not used for actual FFT
	s := sinArr(5, 100)
	tms.Samples = make([]float32, len(s))
	for i, v := range s {
		tms.Samples[i] = float32(v)
	}
	fmt.Printf("Samples: %v\n", (tms.Samples))
	freqs := tm.SamplesToFrequencies(&tms)
	fmt.Printf("Frequencies: %v\n", (freqs.Freqs))
}