Skip to content

Commit

Permalink
Gofmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommy committed Dec 19, 2014
1 parent e88c76d commit d5c02cf
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions examples/sinewave.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@
package main

import (
".." // pulse-simple
"encoding/binary"
"math"
"fmt"
".." // pulse-simple
"encoding/binary"
"fmt"
"math"
)

func main() {
ss := pulse.SampleSpec{pulse.SAMPLE_FLOAT32LE, 44100, 1}
pb, err := pulse.Playback("pulse-simple test", "playback test", &ss)
defer pb.Free()
defer pb.Drain()
if err != nil {
fmt.Printf("Could not create playback stream: %s\n", err)
return
}
playsine(pb, &ss)
ss := pulse.SampleSpec{pulse.SAMPLE_FLOAT32LE, 44100, 1}
pb, err := pulse.Playback("pulse-simple test", "playback test", &ss)
defer pb.Free()
defer pb.Drain()
if err != nil {
fmt.Printf("Could not create playback stream: %s\n", err)
return
}
playsine(pb, &ss)
}

func playsine(s *pulse.Stream, ss *pulse.SampleSpec) {
num_notes := 5
f := []float64{220, 247, 277, 294, 330}
n := []string{"A3", "B3", "C#4", "D4", "E4"}
r := float64(ss.Rate)
data := make([]byte, 4*ss.Rate)
tau := 2*math.Pi
for j := 0; j < num_notes; j++ {
fmt.Printf("%v\n", n[j])
for i := 0; i < int(ss.Rate); i++ {
// (f) Hz sine wave, with 0.5Hz sine envelope over 1 second duration
sample := float32((math.Sin(tau * f[j] * float64(i) / r) / 3.0) *
math.Sin((tau / 2.0) * float64(i) / r))
bits := math.Float32bits(sample)
binary.LittleEndian.PutUint32(data[4*i:4*i+4], bits)
}
s.Write(data)
}
num_notes := 5
f := []float64{220, 247, 277, 294, 330}
n := []string{"A3", "B3", "C#4", "D4", "E4"}
r := float64(ss.Rate)
data := make([]byte, 4*ss.Rate)
tau := 2 * math.Pi
for j := 0; j < num_notes; j++ {
fmt.Printf("%v\n", n[j])
for i := 0; i < int(ss.Rate); i++ {
// (f) Hz sine wave, with 0.5Hz sine envelope over 1 second duration
sample := float32((math.Sin(tau*f[j]*float64(i)/r) / 3.0) *
math.Sin((tau/2.0)*float64(i)/r))
bits := math.Float32bits(sample)
binary.LittleEndian.PutUint32(data[4*i:4*i+4], bits)
}
s.Write(data)
}
}

0 comments on commit d5c02cf

Please sign in to comment.