Select default device instead of first
This commit is contained in:
parent
eb258b1c09
commit
79189fd2b3
|
|
@ -23,39 +23,30 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Playback Devices")
|
playback_device := infos[0].ID
|
||||||
for i, info := range infos {
|
for _, info := range infos {
|
||||||
e := "ok"
|
if info.IsDefault != 0 {
|
||||||
full, err := ctx.DeviceInfo(malgo.Playback, info.ID, malgo.Shared)
|
playback_device = info.ID
|
||||||
if err != nil {
|
break
|
||||||
e = err.Error()
|
|
||||||
}
|
}
|
||||||
fmt.Printf(" %d: %v, %s, [%s], formats: %+v\n",
|
|
||||||
i, info.ID, info.Name(), e, full.Formats)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println()
|
|
||||||
|
|
||||||
// Capture devices.
|
|
||||||
infos, err = ctx.Devices(malgo.Capture)
|
infos, err = ctx.Devices(malgo.Capture)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Capture Devices")
|
capture_device := infos[0].ID
|
||||||
for i, info := range infos {
|
for _, info := range infos {
|
||||||
e := "ok"
|
if info.IsDefault != 0 {
|
||||||
full, err := ctx.DeviceInfo(malgo.Capture, info.ID, malgo.Shared)
|
capture_device = info.ID
|
||||||
if err != nil {
|
|
||||||
e = err.Error()
|
|
||||||
}
|
}
|
||||||
fmt.Printf(" %d: %v, %s, [%s], formats: %+v\n",
|
|
||||||
i, info.ID, info.Name(), e, full.Formats)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inDeviceConfig := malgo.DefaultDeviceConfig(malgo.Capture)
|
inDeviceConfig := malgo.DefaultDeviceConfig(malgo.Capture)
|
||||||
inDeviceConfig.Capture.Format = malgo.FormatF32
|
inDeviceConfig.Capture.Format = malgo.FormatF32
|
||||||
inDeviceConfig.Capture.Channels = 1
|
inDeviceConfig.Capture.Channels = 1
|
||||||
|
inDeviceConfig.Capture.DeviceID = capture_device.Pointer()
|
||||||
inDeviceConfig.SampleRate = 44100
|
inDeviceConfig.SampleRate = 44100
|
||||||
inDeviceConfig.PeriodSizeInFrames = 100
|
inDeviceConfig.PeriodSizeInFrames = 100
|
||||||
inDeviceConfig.Alsa.NoMMap = 1
|
inDeviceConfig.Alsa.NoMMap = 1
|
||||||
|
|
@ -64,6 +55,7 @@ func main() {
|
||||||
outDeviceConfig := malgo.DefaultDeviceConfig(malgo.Playback)
|
outDeviceConfig := malgo.DefaultDeviceConfig(malgo.Playback)
|
||||||
outDeviceConfig.Playback.Format = malgo.FormatF32
|
outDeviceConfig.Playback.Format = malgo.FormatF32
|
||||||
outDeviceConfig.Playback.Channels = 1
|
outDeviceConfig.Playback.Channels = 1
|
||||||
|
outDeviceConfig.Playback.DeviceID = playback_device.Pointer()
|
||||||
outDeviceConfig.SampleRate = 44100
|
outDeviceConfig.SampleRate = 44100
|
||||||
outDeviceConfig.PeriodSizeInFrames = 100
|
outDeviceConfig.PeriodSizeInFrames = 100
|
||||||
outDeviceConfig.Alsa.NoMMap = 1
|
outDeviceConfig.Alsa.NoMMap = 1
|
||||||
|
|
@ -83,13 +75,13 @@ func main() {
|
||||||
Data: onSendFrames,
|
Data: onSendFrames,
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Creating playback device\n")
|
fmt.Printf("Creating playback device %s\n", playback_device)
|
||||||
outDevice, err := malgo.InitDevice(ctx.Context, outDeviceConfig, playbackCallbacks)
|
outDevice, err := malgo.InitDevice(ctx.Context, outDeviceConfig, playbackCallbacks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Starting playback device\n")
|
fmt.Printf("Starting playback\n")
|
||||||
err = outDevice.Start()
|
err = outDevice.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
@ -112,7 +104,7 @@ func main() {
|
||||||
Data: onRecvFrames,
|
Data: onRecvFrames,
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Creating capture device\n")
|
fmt.Printf("Creating capture device %s\n", capture_device)
|
||||||
inDevice, err := malgo.InitDevice(ctx.Context, inDeviceConfig, captureCallbacks)
|
inDevice, err := malgo.InitDevice(ctx.Context, inDeviceConfig, captureCallbacks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue