Comments (9)
Sorry, I realized I could have been clearer with explaining how I'm trying to do this.
This is my attempt now, but I'm still getting the same error... I'm not really familiar with Cgo, so any help would be much appreciated.
...
infos, err := ctx.Devices(malgo.Duplex)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Duplex devices")
for i, info := range infos {
fmt.Printf("%d: %v, %s\n", i, info.ID, info.Name())
}
fmt.Println()
devConf1 := malgo.DeviceConfig {
DeviceType: malgo.Duplex,
SampleRate: 44100,
Capture: malgo.SubConfig{
DeviceID: &infos[0].ID,
Format: malgo.FormatS16,
Channels: 1,
},
Playback: malgo.SubConfig{
DeviceID: &infos[0].ID,
Format: malgo.FormatS16,
Channels: 1,
},
}
...
dev1, err := malgo.InitDevice(ctx.Context, devConf1, devCallbacks1)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
...
from malgo.
Passing ID to what? You should not use DefaultDeviceConfig but create custom DeviceConfig instead, which should contain ID from context.Devices you want to use. I had some examples where I needed that, but cannot find it, though, it should not be difficult.
from malgo.
Ok, need to check and test, API was different.
from malgo.
Have you had a chance to look at this yet?
from malgo.
No, didn't find time to check.
from malgo.
I am having the same issue, will post here if i can get it to work.
from malgo.
So I managed to get it to work by doing the following:
diff --git a/device_config.go b/device_config.go
index 3392191..f28010d 100644
--- a/device_config.go
+++ b/device_config.go
@@ -37,7 +37,7 @@ func (d *DeviceConfig) cptr() *C.ma_device_config {
// SubConfig type.
type SubConfig struct {
- DeviceID *DeviceID
+ DeviceID unsafe.Pointer
Format FormatType
Channels uint32
ChannelMap [C.MA_MAX_CHANNELS]uint8
diff --git a/device_info.go b/device_info.go
index dc7eb59..1e07d10 100644
--- a/device_info.go
+++ b/device_info.go
@@ -21,8 +21,8 @@ func (d DeviceID) String() string {
return hex.EncodeToString(d[:displayLen])
}
-func (d *DeviceID) cptr() *C.ma_device_id {
- return (*C.ma_device_id)(unsafe.Pointer(d))
+func (d *DeviceID) Cptr() unsafe.Pointer {
+ return C.CBytes(d[:])
}
// DeviceInfo type.
and setting the DeviceConfig struct as follows:
devConf1 := malgo.DeviceConfig {
DeviceType: malgo.Duplex,
SampleRate: 44100,
Capture: malgo.SubConfig{
DeviceID: infos[0].ID.Cptr(),
Format: malgo.FormatS16,
Channels: 1,
},
Playback: malgo.SubConfig{
DeviceID: infos[0].ID.Cptr(),
Format: malgo.FormatS16,
Channels: 1,
},
}
Let me know if this is an OK solution for you - I will create a PR with the changes if it is.
from malgo.
Just realized that the pointer returned by C.CBytes()
needs to be freed, but unfortunately the device config is not accessible from Uninit()
as far as I can see...
Though I guess that since with the above solution, the user is calling Cptr() on the device ID, they should also be responsible for calling C.free on it. It's a bit ugly though, because of the
// #include <stdlib.h>
import "C"
that's needed in the user application.
from malgo.
It should be fixed in 1b98196 , just pass DeviceID: infos[0].ID.Pointer()
or whatever index of device.
@fbrozovic No need to free anything in this case, it is not allocated from Go, whatever you allocate in C from Go should be freed.
from malgo.
Related Issues (20)
- Q: Why is iOS not supported? HOT 15
- please update to v0.10.35 HOT 1
- Documentation issue for InitDevice HOT 2
- DeviceInfo.Name function returns a string with null bytes in it HOT 1
- Warnings on macOS 12.1
- Documentation/Examples of using loopback. HOT 1
- Microphone Not Working on built and notarized binary - MacOS HOT 6
- Q: how to encode input audio bytes to PCM properly HOT 1
- Having trouble specifying device dynamically. HOT 1
- Q: Is it possible to get individual audio streams from applications? HOT 1
- Extend WasapiDeviceConfig to support loopbackProcessID and loopbackProcessExclude
- SIGSEGV from `ma_device_uninit` HOT 4
- test segfault after upgrade to v0.11.10 HOT 1
- Dynamic Linking fails on OSX OSX 13.5.2 and 14.0 (Sonoma) HOT 2
- NULL Audio device on MacOS 14.1.1 (23B81) HOT 3
- Q: Support for High Level API HOT 1
- Release v0.11.11 HOT 2
- How is Capture device set supposed to work? HOT 2
- Runtime selection between PulseAudio and ALSA? HOT 1
- Capture on mac HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from malgo.