gen2brain / malgo

Mini audio library
The Unlicense
288 stars 49 forks source link

How is Capture device set supposed to work? #52

Closed tphakala closed 6 months ago

tphakala commented 6 months ago

I am trying to select specific capture device by setting deviceConfig.Capture.DeviceID but code

    var infos []malgo.DeviceInfo
    infos, err = malgoCtx.Devices(malgo.Capture)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

    selectedDeviceInfo := infos[3]

    deviceConfig := malgo.DefaultDeviceConfig(malgo.Capture)
    deviceConfig.Capture.Format = malgo.FormatS16
    deviceConfig.Capture.Channels = conf.NumChannels
    deviceConfig.SampleRate = conf.SampleRate
    deviceConfig.Alsa.NoMMap = 1
    deviceConfig.Capture.DeviceID = unsafe.Pointer(&selectedDeviceInfo.ID)

produces an panic

Capture Devices 0: Discard all samples (playback) or generate zero samples (capture), [ok] 1: Default Audio Device, [ok] 2: Default Audio Device, [ok] 3: USB PnP Sound Device, USB Audio, [ok] panic: runtime error: cgo argument has Go pointer to unpinned Go pointer

gen2brain commented 6 months ago

DeviceID = infos[0].ID.Pointer()

tphakala commented 6 months ago

Indeed! Thank you