Ejemplo n.º 1
0
func SampleMultiply() s.Sound {
	// Includes: TimedSound and SineWave
	all := make([]s.Sound, 20)
	for i := 0; i < len(all); i++ {
		all[i] = s.MultiplyWithClip(s.NewTimedSound(s.NewSineWave(659.25), 200), 0.2+float64(i)/10.0)
	}
	return s.ConcatSounds(all...)
}
Ejemplo n.º 2
0
func SampleDenseIIR() s.Sound {
	// Includes: TimedSound and SineWave
	all := make([]s.Sound, 10)
	for i := 0; i < len(all); i++ {
		all[i] = s.NewTimedSound(s.NewSineWave(600*float64(i)/4), 200)
	}
	return s.NewDenseIIR(s.ConcatSounds(all...),
		[]float64{0.8922, -2.677, 2.677, -0.8922},
		[]float64{2.772, -2.57, 0.7961},
	)
}
Ejemplo n.º 3
0
func main() {
	runtime.GOMAXPROCS(2)

	fmt.Printf("Open the serial cable...\n")
	port, err := serial.OpenPort(&serial.Config{Name: findArduino(), Baud: 9600})
	if err != nil {
		log.Fatal(err)
	}
	time.Sleep(1 * time.Second)

	fmt.Printf("Generate the tone definition...\n")
	player := &Player{}
	toPlay := s.SumSounds(
		s.NewHzFromChannel(player.sampledToneGenerator()),
		s.NewSineWave(hzC/2.0),
	)

	buf := make([]byte, 128)
	startTime, readCount := time.Now(), 0
	for {
		if _, err := port.Read(buf); err != nil {
			if readCount == 0 {
				startTime = time.Now()
				player.Start(toPlay)
			}
			readCount++

			player.currentValue = float64(buf[0]) / 256.0
			if readCount%100000 == 0 {
				fmt.Printf("Value = %f\n", player.currentValue)
			}
			if readCount%1000000 == 0 {
				seconds := time.Since(startTime).Seconds()
				fmt.Printf("Read %d in %f seconds, at a rate of %f Hz\n",
					readCount, seconds, float64(readCount)/seconds)
			}
		}
	}
}
Ejemplo n.º 4
0
// noteToHz reads a note starting at an offset, and returns its Sound and the end offset.
func noteToSound(note string, offset int, base uint) (s.Sound, int) {
	baseHz, next := noteToHz(note, offset, base)
	return s.NewSineWave(baseHz), next
}
Ejemplo n.º 5
0
// MidiToSound converts a midi note into a sound that plays its pitch.
func MidiToSound(midiNote int) s.Sound {
	// NOTE: You can substitute here something that reads from .wav files
	// to synthesize the notes instead.
	return s.NewSineWave(midiToHz(midiNote))
}
Ejemplo n.º 6
0
func SampleSampler() s.Sound {
	// Includes: TimedSound and SineWave
	return s.LinearSample(s.NewTimedSound(s.NewSineWave(392.00), 500), 2.0)
}
Ejemplo n.º 7
0
func SampleAdsrEnvelope() s.Sound {
	// Includes: TimedSound and SineWave
	return s.NewADSREnvelope(
		s.NewTimedSound(s.NewSineWave(880.0), 875),
		50, 200, 0.5, 100)
}
Ejemplo n.º 8
0
func SampleTimedSineSound() s.Sound {
	// Includes: SineWave
	return s.NewTimedSound(s.NewSineWave(261.63), 1000)
}