Skip to content

Commit

Permalink
Merge pull request #13 from scruzin/channels-param
Browse files Browse the repository at this point in the history
Channels param: 1 for mono, 2 for stereo.
  • Loading branch information
yobert authored Apr 12, 2019
2 parents d38d89f + 7ff4275 commit e9392a2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cmd/record/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import (

func main() {
var (
channels int
rate int
duration_str string
file string
)

flag.IntVar(&channels, "channels", 2, "Channels (1 for mono, 2 for stereo)")
flag.IntVar(&rate, "rate", 44100, "Frame rate (Hz)")
flag.StringVar(&duration_str, "duration", "5s", "Recording duration")
flag.StringVar(&file, "file", "out.wave", "Output file")
Expand Down Expand Up @@ -63,7 +65,7 @@ func main() {
}
fmt.Printf("Recording device: %v\n", recordDevice)

recording, err := record(recordDevice, duration, rate)
recording, err := record(recordDevice, duration, channels, rate)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand All @@ -79,16 +81,16 @@ func main() {
return
}

// record audio for duration seconds
func record(rec *alsa.Device, duration time.Duration, rate int) (alsa.Buffer, error) {
// record audio for given duration
func record(rec *alsa.Device, duration time.Duration, channels, rate int) (alsa.Buffer, error) {
var err error

if err = rec.Open(); err != nil {
return alsa.Buffer{}, err
}
defer rec.Close()

_, err = rec.NegotiateChannels(1, 2)
_, err = rec.NegotiateChannels(channels)
if err != nil {
return alsa.Buffer{}, err
}
Expand Down

0 comments on commit e9392a2

Please sign in to comment.