Giter Site home page Giter Site logo

malgo's Introduction

malgo

Build Status GoDoc Go Report Card

Go bindings for miniaudio library.

Requires cgo but does not require linking to anything on the Windows/macOS and it links only -ldl on Linux/BSDs.

Installation

go get -u github.com/gen2brain/malgo

Documentation

Documentation on GoDoc. Also check examples.

Platforms

  • Windows (WASAPI, DirectSound, WinMM)
  • Linux (PulseAudio, ALSA, JACK)
  • FreeBSD/NetBSD/OpenBSD (OSS/audio(4)/sndio)
  • macOS/iOS (CoreAudio)
  • Android (OpenSL|ES, AAudio)

malgo's People

Contributors

biotinker avatar chiefmarlin avatar danfletcher1 avatar dertseha avatar edaniels avatar egonelbre avatar gen2brain avatar godsic avatar intermernet avatar keithcat1 avatar lolwutcode avatar rgeorgiev583 avatar santiagos01 avatar sugarme avatar zserge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

malgo's Issues

API/release status?

Hello there and thank you for this wrapper!
I want to know how stable the API is and whether you are planning to do any versioned releases?

I intend to use the audio library and would like to extend it to support multiple operations in parallel; Right now for instance there's only one callback possible at a time. Changing this would require API-breaking changes.
Hence my question whether you are planning to do a v1 release after such a contribution, or a v1 release now, followed by a v2 release.

Documentation issue for InitDevice

The formal parameters of InitDevice list: context Context, deviceConfig DeviceConfig, deviceCallbacks DeviceCallbacks but the documentation says: The device ID can be nil, in which c...
There is no device ID in the parameterlist. It would be nice if there was, as I cannot select a specific device now with InitDevice.
Can the documention be in-line with the parameters?
Can you explain how to init a specific device, given it's device ID?

test segfault after upgrade to v0.11.10

one commit prior works but now we get this on macos (13):

[signal SIGSEGV: segmentation violation code=0x2 addr=0x10 pc=0x19ba11218]

runtime stack:
runtime.throw({0x1044fb29f?, 0x16bab10c0?})
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/panic.go:1047 +0x40 fp=0x16bab1060 sp=0x16bab1030 pc=0x104381b60
runtime.sigpanic()
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/signal_unix.go:819 +0x1e4 fp=0x16bab1090 sp=0x16bab1060 pc=0x1043974d4

goroutine 7 [syscall]:
runtime.cgocall(0x10443c350, 0x14000058a68)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/cgocall.go:158 +0x54 fp=0x14000058a30 sp=0x140000589f0 pc=0x104350124
github.com/gen2brain/malgo._Cfunc_ma_device_init(0x135b04080, 0x14000000360, 0x138808200)
	_cgo_gotypes.go:1727 +0x38 fp=0x14000058a60 sp=0x14000058a30 pc=0x1044368a8
github.com/gen2brain/malgo.InitDevice.func2({0xac4400000001?}, 0x0?, 0x0?)
	/Users/eric/malgo/device.go:51 +0xa4 fp=0x14000058ab0 sp=0x14000058a60 pc=0x104438114
github.com/gen2brain/malgo.InitDevice({0x0?}, {0x1, 0xac44, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...}, ...)
	/Users/eric/malgo/device.go:51 +0x198 fp=0x14000058d50 sp=0x14000058ab0 pc=0x104437e08
github.com/gen2brain/malgo_test.TestErrors(0x14000138b60)
	/Users/eric/malgo/miniaudio_test.go:147 +0x17c fp=0x14000058f60 sp=0x14000058d50 pc=0x10443b8ec
testing.tRunner(0x14000138b60, 0x104563128)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/testing/testing.go:1446 +0x10c fp=0x14000058fb0 sp=0x14000058f60 pc=0x1044003ac
testing.(*T).Run.func1()
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/testing/testing.go:1493 +0x2c fp=0x14000058fd0 sp=0x14000058fb0 pc=0x1044010ec
runtime.goexit()
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/asm_arm64.s:1172 +0x4 fp=0x14000058fd0 sp=0x14000058fd0 pc=0x1043b1d94
created by testing.(*T).Run
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/testing/testing.go:1493 +0x300

goroutine 1 [chan receive]:
runtime.gopark(0x14000115a68?, 0x104351b34?, 0x78?, 0x5a?, 0x10435967c?)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/proc.go:363 +0xe4 fp=0x140001159f0 sp=0x140001159d0 pc=0x1043844a4
runtime.chanrecv(0x140001341c0, 0x14000115aff, 0x1)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/chan.go:583 +0x454 fp=0x14000115a80 sp=0x140001159f0 pc=0x104352e84
runtime.chanrecv1(0x14000012450?, 0x1?)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/chan.go:442 +0x14 fp=0x14000115ab0 sp=0x14000115a80 pc=0x104352a24
testing.(*T).Run(0x14000003d40, {0x1044f3988?, 0xacb88d9f6ee?}, 0x104563128)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/testing/testing.go:1494 +0x314 fp=0x14000115b50 sp=0x14000115ab0 pc=0x104401044
testing.runTests.func1(0x0?)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/testing/testing.go:1846 +0x70 fp=0x14000115ba0 sp=0x14000115b50 pc=0x104402cb0
testing.tRunner(0x14000003d40, 0x14000115cb8)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/testing/testing.go:1446 +0x10c fp=0x14000115bf0 sp=0x14000115ba0 pc=0x1044003ac
testing.runTests(0x140001200a0?, {0x10461a400, 0x4, 0x4}, {0x8300000000000000?, 0x83c14fc439cdb9ed?, 0x1046202a0?})
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/testing/testing.go:1844 +0x3f0 fp=0x14000115ce0 sp=0x14000115bf0 pc=0x104402b70
testing.(*M).Run(0x140001200a0)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/testing/testing.go:1726 +0x4f0 fp=0x14000115ee0 sp=0x14000115ce0 pc=0x104401910
main.main()
	_testmain.go:55 +0x1d0 fp=0x14000115f70 sp=0x14000115ee0 pc=0x10443bdf0
runtime.main()
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/proc.go:250 +0x24c fp=0x14000115fd0 sp=0x14000115f70 pc=0x1043840dc
runtime.goexit()
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/asm_arm64.s:1172 +0x4 fp=0x14000115fd0 sp=0x14000115fd0 pc=0x1043b1d94

goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/proc.go:363 +0xe4 fp=0x1400004afa0 sp=0x1400004af80 pc=0x1043844a4
runtime.goparkunlock(...)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/proc.go:369
runtime.forcegchelper()
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/proc.go:302 +0xac fp=0x1400004afd0 sp=0x1400004afa0 pc=0x10438433c
runtime.goexit()
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/asm_arm64.s:1172 +0x4 fp=0x1400004afd0 sp=0x1400004afd0 pc=0x1043b1d94
created by runtime.init.6
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/proc.go:290 +0x24

goroutine 18 [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/proc.go:363 +0xe4 fp=0x14000046770 sp=0x14000046750 pc=0x1043844a4
runtime.goparkunlock(...)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/proc.go:369
runtime.bgsweep(0x0?)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/mgcsweep.go:278 +0xa4 fp=0x140000467b0 sp=0x14000046770 pc=0x10436ff94
runtime.gcenable.func1()
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/mgc.go:178 +0x28 fp=0x140000467d0 sp=0x140000467b0 pc=0x104364558
runtime.goexit()
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/asm_arm64.s:1172 +0x4 fp=0x140000467d0 sp=0x140000467d0 pc=0x1043b1d94
created by runtime.gcenable
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/mgc.go:178 +0x74

goroutine 19 [GC scavenge wait]:
runtime.gopark(0x1400008e000?, 0x104520e38?, 0x1?, 0x0?, 0x0?)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/proc.go:363 +0xe4 fp=0x14000046f50 sp=0x14000046f30 pc=0x1043844a4
runtime.goparkunlock(...)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/proc.go:369
runtime.(*scavengerState).park(0x104620320)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/mgcscavenge.go:389 +0x5c fp=0x14000046f80 sp=0x14000046f50 pc=0x10436df4c
runtime.bgscavenge(0x0?)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/mgcscavenge.go:617 +0x44 fp=0x14000046fb0 sp=0x14000046f80 pc=0x10436e4f4
runtime.gcenable.func2()
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/mgc.go:179 +0x28 fp=0x14000046fd0 sp=0x14000046fb0 pc=0x1043644f8
runtime.goexit()
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/asm_arm64.s:1172 +0x4 fp=0x14000046fd0 sp=0x14000046fd0 pc=0x1043b1d94
created by runtime.gcenable
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/mgc.go:179 +0xb8

goroutine 3 [finalizer wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/proc.go:363 +0xe4 fp=0x1400004b580 sp=0x1400004b560 pc=0x1043844a4
runtime.goparkunlock(...)
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/proc.go:369
runtime.runfinq()
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/mfinal.go:180 +0x120 fp=0x1400004b7d0 sp=0x1400004b580 pc=0x104363780
runtime.goexit()
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/asm_arm64.s:1172 +0x4 fp=0x1400004b7d0 sp=0x1400004b7d0 pc=0x1043b1d94
created by runtime.createfing
	/opt/homebrew/Cellar/go/1.19.3/libexec/src/runtime/mfinal.go:157 +0x84
exit status 2
FAIL	github.com/gen2brain/malgo	2.208s```

Q: Why is iOS not supported?

malgo does not list iOS as a supported platform, but macOS. As far as I understand, Miniaudio is based on Core Audio for both macOS and iOS. So I am surprised by this restriction.
Is this a hard constraint, i.e. is there a technical burden that prohibits deployment, or is it just not tested?

Many thanks for an answer to help me out!

Doesn't work with go mod?

microphone-demo export GO111MODULE=off
➜  microphone-demo go get -u github.com/gen2brain/malgo
➜  microphone-demo export GO111MODULE=on
➜  microphone-demo go get -u github.com/gen2brain/malgo
go: finding github.com/gen2brain/malgo latest
# github.com/gen2brain/malgo
In file included from ../../../../pkg/mod/github.com/gen2brain/[email protected]/context.go:3:
./malgo.h:4:10: fatal error: 'miniaudio/miniaudio.h' file not found
#include "miniaudio/miniaudio.h"
         ^~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
➜  microphone-demo

You can see that with go mod enabled, I cannot install this package at all. It installs without go mod.

Capture example doesn't run on macOS 10.15.3?

Hello, when I run the capture example on my Mac-mini (2018, Catalina 10.15.3) it exits early with this error:

Assertion failed: (tNext <= framesReadFromClient+1), function ma_src_read_deinterleaved__linear, file /Users/craig/go/pkg/mod/github.com/gen2brain/[email protected]/miniaudio.h, line 30529

The Mac mini doesn't have a microphone, but I have a guitar usb interface that is considered the default input device in sound preferences. Also, I'm running it in iterm, which does have access to the input device in the privacy settings. Would you expect this setup to work?

unable to obtain correct number of samples

Hi everyone,

I am trying to capture audio with minimum latency (10mSec) using malgo.

I am having a problem.
I am not sure if it is myself making a mistake or I have hit a bug in malgo.
I do not know frankly.

The brief statement is:
-- I am using malgo 0.10.19
-- I need to capture from a predefined device @ 44.1ks/sec, with 16 bits, and 1 channel
-- during a 10 seconds take, the number of bytes obtained is very different from the expected

Details:

The device used as input is being chosen out from the list of available devices produced by malgo itself,
notice that the test selects one of the pre-listed devices.
https://bitbucket.org/claudio_ortega/jambridge2/src/master/src/audio/test/device_capture_test.go

It fills in the config structure with the selected capturing device ID. Then it starts the device, and then it waits for 10 seconds for the capturing device to inject the samples in the callback before stopping the capture and ending the test.

** Expected:
The total number of bytes expected after 10 seconds is something around the theoretical

2*44.1ks/sec*10sec = 882,000 bytes

** Observed:
The config for the device occurs between lines 37 and 44.
The output produced by the test case into the console is in here:
https://bitbucket.org/claudio_ortega/jambridge2/src/master/notes/bug-report.txt
between lines 75 and 128
Notice that the number of bytes obtained is 52800, when the expected is 882000

It might be me making a mistake, that would be great to know.
Can anybody see if I am missing something obvious here?.

Having trouble specifying device dynamically.

Unable to dynamically pull a device ID from config file.

I've tried defining struct with device being int, string and interface. No combination seems to work.

I usally hammer my way through to solve issues, but this one has me stumped.

	deviceConfig := malgo.DefaultDeviceConfig(malgo.Capture)
	deviceConfig.Capture.Format = malgo.FormatS16
	deviceConfig.Capture.Channels = 1
	// deviceConfig.Capture.SampleRate = 44100
	deviceConfig.Capture.DeviceID = device

Ideas?

Question: simultaneous capture and playback

Probably the right place to ask this would be mini_al repo, but maybe Go bindings do it differently.

I would like to have an app that does sound capture and playback at the same time through the same device. My approach of making a config with two callbacks (send and recv) doesn't seem to work on Linux/PulseAudio and Linux/Alsa. If I initialize device with Capture mode - only capture happens, if I do it in Playback mode - only playback happends. If I use a bitmask - nothing changes (because Playback mode = 0). My attempt to open the same default device in two goroutines results in various crashes.

So I wonder what is the correct way to do this? I haven't found any hints in the docs yet, and the examples only demonstrate mutually exclusive capture and playback.

Thanks, and sorry if the question is irrelevant here.

Documentation/Examples of using loopback.

Hi,

I couldn't find either a document or example of recording from speakers.
Is it possible to do so?

Since I've seen that there's an example on miniaudio git doing the exact thing I have in mind I'm guessing it should be possible. But simply recording from speaker device doesn't work.

Use sndio on OpenBSD

This library apparently uses OSS on OpenBSD currently, this seems unnessecary. The underlying library supports sndio which is OpenBSDs native audio library. Switching to sndio would mean this would have no additional dependencies on OpenBSD. I believe audio(4) would be preferably on NetBSD also.

Warnings on macOS 12.1

Hi,
Perhaps you may find this useful, i am getting the following warnings running enumerate example on m1 macOS 12.1.
It still lists device, these are just warnings.

Thanks

github.com/gen2brain/malgo

In file included from miniaudio.c:4:
/Users/q/go/pkg/mod/github.com/gen2brain/[email protected]/miniaudio.h:24495:36: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
In file included from miniaudio.c:4:
/Users/q/go/pkg/mod/github.com/gen2brain/[email protected]/miniaudio.h:24529:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
In file included from miniaudio.c:4:
/Users/q/go/pkg/mod/github.com/gen2brain/[email protected]/miniaudio.h:24571:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
In file included from miniaudio.c:4:
/Users/q/go/pkg/mod/github.com/gen2brain/[email protected]/miniaudio.h:24600:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
In file included from miniaudio.c:4:
/Users/q/go/pkg/mod/github.com/gen2brain/[email protected]/miniaudio.h:24655:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
In file included from miniaudio.c:4:
/Users/q/go/pkg/mod/github.com/gen2brain/[email protected]/miniaudio.h:24693:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
In file included from miniaudio.c:4:
/Users/q/go/pkg/mod/github.com/gen2brain/[email protected]/miniaudio.h:24783:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
In file included from miniaudio.c:4:
/Users/q/go/pkg/mod/github.com/gen2brain/[email protected]/miniaudio.h:24905:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
In file included from miniaudio.c:4:
/Users/q/go/pkg/mod/github.com/gen2brain/[email protected]/miniaudio.h:24943:29: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
In file included from miniaudio.c:4:
/Users/q/go/pkg/mod/github.com/gen2brain/[email protected]/miniaudio.h:24972:41: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
In file included from miniaudio.c:4:
/Users/q/go/pkg/mod/github.com/gen2brain/[email protected]/miniaudio.h:26058:37: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
In file included from miniaudio.c:4:
/Users/q/go/pkg/mod/github.com/gen2brain/[email protected]/miniaudio.h:26087:37: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
In file included from miniaudio.c:4:
/Users/q/go/pkg/mod/github.com/gen2brain/[email protected]/miniaudio.h:26533:37: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here

Build on android not playing audio

I build with ndk playback.go after renaming package and main method to Run with command:
gomobile bind -o pult.aar -target=android
I got aar and tried to call Run. But I didn't hear any sound. In logs i saw:
AUDIO_OUTPUT_FLAG_FAST denied by server; frameCount 0 -> 1772

How to build on android, it marked as supported os.

How is Capture device set supposed to work?

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

SIGSEGV from `ma_device_uninit`

Encountered SIGSEGV when trying to execute Uninit() for a device. This happened to me even when I ran the example code in this repository. The recording seems to work as expected though, it's just that I keep getting SIGSEGV every time I want to close/uninit the device.

How to reproduce:
go run _examples/capture/capture.go

Expected outcome:
Successful execution

Actual outcome:

Recording...
Press Enter to stop recording...

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x7fe4d7ffe910 pc=0x7fe540daac99]

runtime stack:
runtime.throw({0x503538?, 0x219f790?})
        /usr/local/go/src/runtime/panic.go:992 +0x71
runtime.sigpanic()
        /usr/local/go/src/runtime/signal_unix.go:802 +0x3a9

goroutine 1 [syscall]:
runtime.cgocall(0x49d520, 0xc000074c08)
        /usr/local/go/src/runtime/cgocall.go:157 +0x5c fp=0xc000074be0 sp=0xc000074ba8 pc=0x40dc9c
github.com/gen2brain/malgo._Cfunc_ma_device_uninit(0x219f730)
        _cgo_gotypes.go:1569 +0x45 fp=0xc000074c08 sp=0xc000074be0 pc=0x498e85
github.com/gen2brain/malgo.(*Device).Uninit.func1(0x4ebd40?)
        [REDACTED]/malgo/device.go:146 +0x3a fp=0xc000074c40 sp=0xc000074c08 pc=0x49a61a
github.com/gen2brain/malgo.(*Device).Uninit(0xc0001a8030)
        [REDACTED]/malgo/device.go:146 +0xb3 fp=0xc000074c70 sp=0xc000074c40 pc=0x49a593
main.main()
        [REDACTED]/malgo/_examples/capture/capture.go:68 +0x4f2 fp=0xc000074f80 sp=0xc000074c70 pc=0x49ca52
runtime.main()
        /usr/local/go/src/runtime/proc.go:250 +0x212 fp=0xc000074fe0 sp=0xc000074f80 pc=0x43e372
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1571 +0x1 fp=0xc000074fe8 sp=0xc000074fe0 pc=0x466fa1
exit status 2

Environment:

  • OS: Ubuntu 22.04
  • Go version: 1.18.1

NULL Audio device on MacOS 14.1.1 (23B81)

Hey,
I just noticed that on latest MacOS 14.1.1 (23B81) audio devices no longer show up correctly, only 2 devices available are as below:

enumeration % go run enumeration.go

Playback Devices
0: 00, NULL Playback Device, [ok], formats: [{Format:0 Channels:0 SampleRate:0 Flags:0}]

Capture Devices
0: 00, NULL Capture Device, [ok], formats: [{Format:0 Channels:0 SampleRate:0 Flags:0}]

It used to work fine on MacOS before, but i cant recall what the last working MacOS version was.
@gen2brain

Capture on mac

Hi,
When im running capture example on macos 14.4.1, it doesnt appear to actually capture anything as all the data stored is 0s and there is no mac indicator dot (orange dot in corner) that indicates that its recording.

Any suggestions what i can check ?
I have tried the capture example from miniaudio and it works fine.

I feel like i've had this issue a while back when using this lib, but cannot recall how i fixed it.

Thanks
@gen2brain

This is the log of the capture example run:

LOG <WASAPI backend is disabled.
>
LOG <DirectSound backend is disabled.
>
LOG <WinMM backend is disabled.
>
LOG <Attempting to initialize Core Audio backend...
>
LOG <Loading library: /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
>
LOG <Loading symbol: CFStringGetCString
>
LOG <Loading symbol: CFRelease
>
LOG <Loading library: /System/Library/Frameworks/CoreAudio.framework/CoreAudio
>
LOG <Loading symbol: AudioObjectGetPropertyData
>
LOG <Loading symbol: AudioObjectGetPropertyDataSize
>
LOG <Loading symbol: AudioObjectSetPropertyData
>
LOG <Loading symbol: AudioObjectAddPropertyListener
>
LOG <Loading symbol: AudioObjectRemovePropertyListener
>
LOG <Loading library: /System/Library/Frameworks/AudioUnit.framework/AudioUnit
>
LOG <Loading symbol: AudioComponentFindNext
>
LOG <Loading symbol: AudioComponentFindNext
>
LOG <Loading symbol: AudioComponentInstanceDispose
>
LOG <Loading symbol: AudioComponentInstanceNew
>
LOG <Loading symbol: AudioOutputUnitStart
>
LOG <Loading symbol: AudioOutputUnitStop
>
LOG <Loading symbol: AudioUnitAddPropertyListener
>
LOG <Loading symbol: AudioUnitGetPropertyInfo
>
LOG <Loading symbol: AudioUnitGetProperty
>
LOG <Loading symbol: AudioUnitSetProperty
>
LOG <Loading symbol: AudioUnitInitialize
>
LOG <Loading symbol: AudioUnitRender
>
LOG <System Architecture:
>
LOG <  Endian: LE
>
LOG <  SSE2:   NO
>
LOG <  AVX2:   NO
>
LOG <  NEON:   YES
>
Recording...
LOG <[Core Audio]
>
LOG <  External Microphone (Capture)
>
LOG <    Format:      32-bit IEEE Floating Point -> 16-bit Signed Integer
>
LOG <    Channels:    1 -> 1
>
LOG <    Sample Rate: 44100 -> 44100
>
LOG <    Buffer Size: 441*3 (1323)
>
LOG <    Conversion:
>
LOG <      Pre Format Conversion:  NO
>
LOG <      Post Format Conversion: YES
>
LOG <      Channel Routing:        NO
>
LOG <      Resampling:             NO
>
LOG <      Passthrough:            NO
>
LOG <      Channel Map In:         {CHANNEL_MONO}
>
LOG <      Channel Map Out:        {CHANNEL_MONO}
>
LOG <  External Headphones (Playback)
>
LOG <    Format:      16-bit Signed Integer -> 32-bit IEEE Floating Point
>
LOG <    Channels:    1 -> 2
>
LOG <    Sample Rate: 44100 -> 44100
>
LOG <    Buffer Size: 441*3 (1323)
>
LOG <    Conversion:
>
LOG <      Pre Format Conversion:  YES
>
LOG <      Post Format Conversion: NO
>
LOG <      Channel Routing:        YES
>
LOG <      Resampling:             NO
>
LOG <      Passthrough:            NO
>
LOG <      Channel Map In:         {CHANNEL_MONO}
>
LOG <      Channel Map Out:        {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}
>
Press Enter to stop recording...

Playing...
LOG <[Core Audio]
>
LOG <  External Microphone (Capture)
>
LOG <    Format:      32-bit IEEE Floating Point -> 16-bit Signed Integer
>
LOG <    Channels:    1 -> 1
>
LOG <    Sample Rate: 44100 -> 44100
>
LOG <    Buffer Size: 441*3 (1323)
>
LOG <    Conversion:
>
LOG <      Pre Format Conversion:  NO
>
LOG <      Post Format Conversion: YES
>
LOG <      Channel Routing:        NO
>
LOG <      Resampling:             NO
>
LOG <      Passthrough:            NO
>
LOG <      Channel Map In:         {CHANNEL_MONO}
>
LOG <      Channel Map Out:        {CHANNEL_MONO}
>
LOG <  External Headphones (Playback)
>
LOG <    Format:      16-bit Signed Integer -> 32-bit IEEE Floating Point
>
LOG <    Channels:    1 -> 2
>
LOG <    Sample Rate: 44100 -> 44100
>
LOG <    Buffer Size: 441*3 (1323)
>
LOG <    Conversion:
>
LOG <      Pre Format Conversion:  YES
>
LOG <      Post Format Conversion: NO
>
LOG <      Channel Routing:        YES
>
LOG <      Resampling:             NO
>
LOG <      Passthrough:            NO
>
LOG <      Channel Map In:         {CHANNEL_MONO}
>
LOG <      Channel Map Out:        {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}
>
Press Enter to quit...

capture example does not compile

go run _examples/capture/capture.go
# command-line-arguments
_examples/capture/capture.go:25:14: deviceConfig.Format undefined (type malgo.DeviceConfig has no field or method Format)
_examples/capture/capture.go:26:14: deviceConfig.Channels undefined (type malgo.DeviceConfig has no field or method Channels)
_examples/capture/capture.go:34:60: deviceConfig.Format undefined (type malgo.DeviceConfig has no field or method Format)
_examples/capture/capture.go:36:43: deviceConfig.Channels undefined (type malgo.DeviceConfig has no field or method Channels)
_examples/capture/capture.go:47:3: unknown field 'Recv' in struct literal of type malgo.DeviceCallbacks
_examples/capture/capture.go:49:33: too many arguments in call to malgo.InitDevice
	have (malgo.Context, malgo.DeviceType, nil, malgo.DeviceConfig, malgo.DeviceCallbacks)
	want (malgo.Context, malgo.DeviceConfig, malgo.DeviceCallbacks)
_examples/capture/capture.go:67:45: deviceConfig.Channels undefined (type malgo.DeviceConfig has no field or method Channels)
_examples/capture/capture.go:76:38: deviceConfig.Channels undefined (type malgo.DeviceConfig has no field or method Channels)
_examples/capture/capture.go:81:3: unknown field 'Send' in struct literal of type malgo.DeviceCallbacks
_examples/capture/capture.go:84:32: too many arguments in call to malgo.InitDevice
	have (malgo.Context, malgo.DeviceType, nil, malgo.DeviceConfig, malgo.DeviceCallbacks)
	want (malgo.Context, malgo.DeviceConfig, malgo.DeviceCallbacks)
_examples/capture/capture.go:84:32: too many errors

Odd behavior after periodically capturing audio over a long period of time

Hey! This ain't so much an 'error' but a general usage type of question.

So I wrote a program that is kind of based off of the capture example but using a timer. The source of that program is more or less here.

The parameters I'm passing into malgo look like this:

[Mike]
pollDuration = 5 // Every five seconds, capture one second of audio.
channels     = 1
sampleRate   = 8000
NoMMap       = 1
bufferSize   = 1000

Now, the application runs fine and it does exactly what I want it to do - which is to continuously detect whether or not my microphone is capturing audio. However, after probably, like, a few hours of running I start seeing problems from the perspective of other applications. If another application tries to grab control of the mic, then that application freezes up. This occurs even after I shut down my own application.

Is this some sort of locking issues? Am I doing something grossly inefficient? The platform I'm on is Windows 10.

Any and all help is super appreciated.

Examples not compiled

Hi there, I run into some problems while trying to compile the examples.
Error Reports:

$ go run ./_examples/playback/playback.go ./track01.mp3
# command-line-arguments
_examples/playback/playback.go:74:14: deviceConfig.Format undefined (type malgo.DeviceConfig has no field or method Format)
_examples/playback/playback.go:75:14: deviceConfig.Channels undefined (type malgo.DeviceConfig has no field or method Channels)
_examples/playback/playback.go:79:59: deviceConfig.Format undefined (type malgo.DeviceConfig has no field or method Format)
_examples/playback/playback.go:87:3: unknown field 'Send' in struct literal of type malgo.DeviceCallbacks
_examples/playback/playback.go:89:33: too many arguments in call to malgo.InitDevice
        have (malgo.Context, malgo.DeviceType, nil, malgo.DeviceConfig, malgo.DeviceCallbacks)
        want (malgo.Context, malgo.DeviceConfig, malgo.DeviceCallbacks)

It seems that examples don't match the code. I'm not sure... may the examples remain unchanged after updating?

Q: Support for High Level API

Hi, I am new to miniaudio but since I am looking around for a more complete Go library for audio, I came across miniaudio and your binding project.

From the documentation of miniaudio it appears that there is both a Low Level API and a High Level API, with the latter adding mixing and effects capabilities, as well as a node graph, something that sounds very appealing and much like Web Audio API.

Are there any plans to expose bindings for the High Level API?

Microphone Not Working on built and notarized binary - MacOS

Hi,

I am fairly new to go and just made a little binary to pipe the microphone sound to the google speech to text cloud API, it works fine when i do a go run of the code. It also works when i build on my mac machine.

But once i build and notarized the binary to send it to someone in a zip, the microphone input recording don't seem to work when they run the app.

Am i missing something ? Should i be able to build and expect all the included binaries of the plugin to work on the build ?

i feel like it could be related to macOS microphone permission, when i launch the binary there is no prompt to give access to the microphone.

Thanks ❤️

Dynamic Linking fails on OSX OSX 13.5.2 and 14.0 (Sonoma)

Since release OSX 13.5.2 onwards, OSX CoreFoundation libs et al fail to dynamically link, resulting in no backend beeing opened.

Refer to this issue of miniaudio:

mackron/miniaudio#750

I followed the instructions here and brought malgo back to work:

in file miniaudio.c i added no runtime linking:


#include "_cgo_export.h"

#ifdef __APPLE__
    #define MA_NO_RUNTIME_LINKING
#endif

#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"

in file miniaudio.go a added in line 14:

#cgo darwin LDFLAGS: -framework CoreFoundation -framework CoreAudio -framework AudioToolbox

I will provide a pull request if desired.

Regards,
dezi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.