Implement EnumerateDevices and register all devices

This commit is contained in:
Atsushi Watanabe
2020-02-12 20:21:09 +09:00
committed by Lukas Herman
parent ed1352b6ff
commit 5653cdf9e8
10 changed files with 93 additions and 16 deletions
+25 -2
View File
@@ -12,11 +12,24 @@ import (
type microphone struct {
c *pulse.Client
id string
samplesChan chan<- []float32
}
func init() {
driver.GetManager().Register(&microphone{})
pa, err := pulse.NewClient()
if err != nil {
// No pulseaudio
return
}
defer pa.Close()
sources, err := pa.ListSources()
if err != nil {
panic(err)
}
for _, source := range sources {
driver.GetManager().Register(&microphone{id: source.ID()}, source.ID())
}
}
func (m *microphone) Open() error {
@@ -47,7 +60,17 @@ func (m *microphone) AudioRecord(p prop.Media) (audio.Reader, error) {
options = append(options, pulse.RecordStereo)
}
latency := p.Latency.Seconds()
options = append(options, pulse.RecordSampleRate(p.SampleRate), pulse.RecordLatency(latency))
src, err := m.c.SourceByID(m.id)
if err != nil {
return nil, err
}
options = append(options,
pulse.RecordSampleRate(p.SampleRate),
pulse.RecordLatency(latency),
pulse.RecordSource(src),
)
samplesChan := make(chan []float32, 1)
var buff []float32