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