Beispiel #1
0
// Generates the golden files. See test/sounds_test.go for actual test.
func main() {
	// Singlethreaded for now...
	runtime.GOMAXPROCS(4)

	// Parse flags...
	sampleRate := s.CyclesPerSecond
	minFreq := flag.Float64("minFreq", 110.0, "minimum frequency")
	maxFreq := flag.Float64("maxFreq", 14080.0, "maximum frequency")
	bpo := flag.Int("bpo", 24, "Buckets per octave")
	flag.Parse()

	remainingArgs := flag.Args()
	if len(remainingArgs) < 1 || len(remainingArgs) > 2 {
		panic("Required: <input> [<input>] filename arguments")
	}
	inputFile := remainingArgs[0]
	inputFile2 := inputFile
	if len(remainingArgs) == 2 {
		inputFile2 = remainingArgs[1]
	}

	inputSound := f.Read(inputFile)
	// inputSound := s.NewTimedSound(s.NewSineWave(440.0), 1000)
	inputSound.Start()
	defer inputSound.Stop()

	// minFreq, maxFreq, bpo := 110.0, 14080.0, 24
	params := cq.NewCQParams(sampleRate, *minFreq, *maxFreq, *bpo)
	constantQ := cq.NewConstantQ(params)
	cqInverse := cq.NewCQInverse(params)
	latency := constantQ.OutputLatency + cqInverse.OutputLatency

	// Two inputs version - TODO, switch back to input + output.
	inputSound2 := f.Read(inputFile2)
	inputSound2.Start()
	defer inputSound2.Stop()
	constantQ2 := cq.NewConstantQ(params)

	startTime := time.Now()
	// TODO: Skip the first 'latency' samples for the stream.
	fmt.Printf("TODO: Skip latency (= %d) samples)\n", latency)
	columns := constantQ.ProcessChannel(inputSound.GetSamples())
	columns2 := constantQ2.ProcessChannel(inputSound2.GetSamples())
	samples := cqInverse.ProcessChannel(mergeChannels(columns, columns2))
	asSound := s.WrapChannelAsSound(samples)

	// if outputFile != "" {
	// f.Write(asSound, outputFile)
	// } else {
	output.Play(asSound)
	// }

	elapsedSeconds := time.Since(startTime).Seconds()
	fmt.Printf("elapsed time (not counting init): %f sec\n", elapsedSeconds)
}
Beispiel #2
0
// Generates the golden files. See test/sounds_test.go for actual test.
func main() {
	// Needs to be at least 2 when doing openGL + sound output at the same time.
	runtime.GOMAXPROCS(3)

	sampleRate := s.CyclesPerSecond
	minFreq := flag.Float64("minFreq", 27.5*4.0, "minimum frequency")
	maxFreq := flag.Float64("maxFreq", 3520.0/4.0, "maximum frequency")
	octaves := 3
	bpo := flag.Int("bpo", 72, "Buckets per octave")
	flag.Parse()

	remainingArgs := flag.Args()
	argCount := len(remainingArgs)
	if argCount < 1 || argCount > 2 {
		panic("Required: <input> [<output>] filename arguments")
	}
	inputFile := remainingArgs[0]
	outputFile := ""
	if argCount == 2 {
		outputFile = remainingArgs[1]
	}

	// minFreq, maxFreq, bpo := 110.0, 14080.0, 24
	params := cq.NewCQParams(sampleRate, *minFreq, *maxFreq, *bpo)
	spectrogram := cq.NewSpectrogram(params)

	inputSound := f.Read(inputFile)
	// fmt.Printf("TODO: Go back to reading %s\n", inputFile)
	// inputSound := s.NewTimedSound(
	// 	s.SumSounds(
	// 		s.NewSineWave(440.00),
	// 		// s.NewSineWave(440.00),
	// 		s.NewSineWave(698.46),
	// 	), 10000)
	inputSound.Start()
	defer inputSound.Stop()

	startTime := time.Now()
	if outputFile != "" {
		// Write to file
		columns := spectrogram.ProcessChannel(inputSound.GetSamples())
		outputBuffer := bytes.NewBuffer(make([]byte, 0, 1024))
		width, height := 0, 0
		for col := range columns {
			for _, c := range col {
				cq.WriteComplex(outputBuffer, c)
			}
			if width%1000 == 0 {
				fmt.Printf("At frame: %d\n", width)
			}
			width++
			height = len(col)
		}
		fmt.Printf("Done! - %d by %d\n", width, height)
		ioutil.WriteFile(outputFile, outputBuffer.Bytes(), 0644)

	} else {
		// No file, so play and show instead:
		soundChannel, specChannel := splitChannel(inputSound.GetSamples())
		go func() {
			columns := spectrogram.ProcessChannel(specChannel)
			toShow := util.NewSpectrogramScreen(882, *bpo*octaves, *bpo)
			toShow.Render(columns, 1)
		}()
		output.Play(s.WrapChannelAsSound(soundChannel))
	}

	elapsedSeconds := time.Since(startTime).Seconds()
	fmt.Printf("elapsed time (not counting init): %f sec\n", elapsedSeconds)

	if outputFile == "" {
		// Hang around to the view can be looked at.
		for {
		}
	}
}