Coder Social home page Coder Social logo

portaudio's Introduction

portaudio

This package provides an interface to the PortAudio audio I/O library. See the package documentation for details.

To build this package you must first have the PortAudio development headers and libraries installed. Some systems provide a package for this; e.g., on Ubuntu you would want to run apt-get install portaudio19-dev. On other systems you might have to install from source.

Thanks to sqweek for motivating and contributing to host API and device enumeration.

portaudio's People

Contributors

bryant1410 avatar gordonklaus avatar jkearse3 avatar mrdg 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  avatar  avatar  avatar

portaudio's Issues

Example `play.go` not working correctly

Hello there!

I stumbled over your module when looking for a library to interact with sound in go. So far so good, I got some things working with the help of your examples. However when I try to use the play.go example I can hear that the sound starts playing but then suddenly interrupts with the following error:

Playing.  Press Ctrl-C to stop.
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
panic: unexpected EOF

goroutine 1 [running]:
main.chk(...)
	/tmp/gugus/main.go:124
main.main()
	/tmp/gugus/main.go:77 +0x870
exit status 2

Using debugging tools I can see that this line produces the error when remaining is about 4500 (started by 8000 or so).
Interestingly enough the mp3.go example works fine.

I'm not a sound pro, so the problem could easily by on my side. But maybe you can help me out with that?

Some debugging information:

Determining FramesPerBuffer For Infinite Stream Time

Currently I am working to record audio via the input device and send it through a TCP Conn to a client who will then use the same library to play the audio. Before I have tried to face the issue of piping the stream data to a socket I wanted to figure out how to approach the issue of streaming for an unknown or infinite amount of time. Programmatically how would I go about this process as some of the OpenDefaultStream requires a length of frames per buffer to be provided but how could that be done if I plan to stream data indefinitely between an input device through a socket connection to an output device on another machine with no time limit?

"go install <your portaudio module>" doesn't work

Hello.
As I mentioned at the title, go install command does not work to install your package.

I tried "go get" command on Mac , instead of "go install", it does work but on Windows it doesn't.
Please let me know how to install your portaudio package.

my GO env
GO111MODULE = on
GOVERSION = go1.19.1

Get nothing using OpenDefaultStream in the latest mac os Big Sur.

System mac os Big Sur,
I install portaudio HEAD using brew:

brew install portaudio --HEAD

my code just like

	inputParams := portaudio.StreamDeviceParameters{
		Device:   inputDevice,
		Channels: 6,
	}
	outputParams := portaudio.StreamDeviceParameters{
		Device:   nil,
		Channels: 0,
	}
	p := portaudio.StreamParameters{
		Input:           inputParams,
		Output:          outputParams,
		SampleRate:      44100,
		FramesPerBuffer: 256,
		Flags:           portaudio.NoFlag,
	}

	var recorder2 = func(in []int32, out []int32, timeInfo portaudio.StreamCallbackTimeInfo, flags portaudio.StreamCallbackFlags) {
		fmt.Printf("Recording... %v %d %d \n", timeInfo.CurrentTime, len(in), len(out))
		fmt.Printf("Reco %v \n", in, out)
	}
	in := make([]int32, 256)
	stream, err := portaudio.OpenDefaultStream(1, 0, 44100, len(in), recorder2, in)
	defer stream.Close()
	stream.Start()
	time.Sleep(3 * time.Second)
	stream.Stop()

I got may 0 in buffer in, means I can't read any sound from input stream.

but this code worked in macOS Catalina 10.15

another python code using pyaudio also works in Big Sur.

Is this problem in this godriver ?

portaudio not initialising and exiting with exit code -1073741515 (0xC0000135)

Hi,

This is for go version go1.13.4 windows/amd64

So I have installed gcc and port audio and the headers from precompiled binaries and also I have built port audio from the source. Both times the dll is definiely found but as soon as I begin running the program it exits with exit code -1073741515 (0xC0000135) as shown below:

GOROOT=C:\Go #gosetup
GOPATH=C:\Users\nadav\go #gosetup
C:\Go\bin\go.exe build -o C:\Users\nadav\AppData\Local\Temp\___go_build_port_audio_test_go.exe "C:\Users\nadav\Documents\Nadav\Coding\GitHub Projects\led-colour-visualiser\port-audio-test.go" #gosetup
C:\Users\nadav\AppData\Local\Temp\___go_build_port_audio_test_go.exe #gosetup

Process finished with exit code -1073741515 (0xC0000135)

I am certain that the dll is found since when running ld it manages to find the dll file. For this reason I think the dll isn't working correctly for some reason. Do you have any ideas??

Thanks

edit: after some research 0xC0000135 might actually indicate a dll not found error. this is confusing me since gcc is definitely able to find the dll.

GEt live audio from microphone

Hi guys.

I would like to ask your help to get the live stream from the microphone and encode to ogg.

This is my code, this save two files one test.raw and work perfect, but output.ogg not play

// play -t raw -r 48000 -e signed -b 16 -c 1 test.raw
//

package main

import (
	"encoding/binary"
	"fmt"
	"os"
	"os/signal"
	"io/ioutil"

	"github.com/gordonklaus/portaudio"
	"gopkg.in/hraban/opus.v2"
)

func main() {
	var readBuffer = make([]byte, 0)
	sig := make(chan os.Signal, 1)
	signal.Notify(sig, os.Interrupt, os.Kill)

	fileName := "test.raw"

	f, err := os.Create(fileName)
	chk(err)


	portaudio.Initialize()
	defer portaudio.Terminate()
	in := make([]int16, 960)
	stream, err := portaudio.OpenDefaultStream(1, 0, 48000, len(in), in)
	chk(err)
	defer stream.Close()

	chk(stream.Start())
	for {
		chk(stream.Read())
		
		chk(binary.Write(f, binary.LittleEndian, in))
		buf, encErr := encode(in)
		if err != nil {
			panic(encErr)
		}
		readBuffer = append(readBuffer, buf...)

		//fmt.Println(in, len(in))
		select {
		case <-sig:		
			// write the whole body at once
			err = ioutil.WriteFile("output.ogg", readBuffer, 0644)
			if err != nil {
				panic(err)
			}
			return
		default:
		}
	}
	chk(stream.Stop())
}

func encode(pcm []int16) ([]byte, error){	
	const sampleRate = 48000
	const channels = 1 // mono; 2 for stereo
	const bufferSize = 1000 // choose any buffer size you like. 1k is plenty.

	enc, err := opus.NewEncoder(sampleRate, channels, opus.AppVoIP)
	if err != nil {
      panic(err)
	}	

	// Check the frame size. You don't need to do this if you trust your input.
	frameSize := len(pcm) // must be interleaved if stereo
	frameSizeMs := float32(frameSize) / channels * 1000 / sampleRate
	switch frameSizeMs {
		case 2.5, 5, 10, 20, 40, 60:
    	// Good.
	default:
		fmt.Println("Illegal frame size: ", frameSize,  "bytes", frameSizeMs)
    	return nil, err
	}

	data := make([]byte, bufferSize)
	n, err := enc.Encode(pcm, data)
	if err != nil {
    	panic(err)
	}
	data = data[:n] // only the first N bytes are opus data. Just like io.Reader.
	fmt.Print(n, len(data))
	return data, err
}

func chk(err error) {
	if err != nil {
		panic(err)
	}
}

but when i try play output.ogg with mplayer output.ogg i receive this message

MPlayer 1.3.0 (Debian), built with gcc-7 (C) 2000-2016 MPlayer Team
do_connect: could not connect to socket
connect: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing output.ogg.
libavformat version 57.83.100 (external)
libavformat file format detected.
[ogg @ 0xb6952e98]cannot find sync word
LAVF_header: av_open_input_stream() failed
libavformat file format detected.
[ogg @ 0xb6952e98]cannot find sync word
LAVF_header: av_open_input_stream() failed

How do I get microphone level? [HELP]

Hi! I'm trying to get the stream audio level to know if someone is talking in the room.

I've tried to get in of StreamCallback, but I don't know how to convert the buffers to get the audio level. Can you help me?

func (e *echo) callback(in []float32) {
	for i := range in {
		// TODO
                // convert this input audio to get audio level
	}
}

In Python, I got this piece of code that works fine.

I've tried also to use a mat.Norm() from gonum library to normalize the incoming buffer, but I couldn't.

Thanks!

Go 1.6beta1 - Changes to CGO pointer passing break portaudio

Hi,

I tried compiling portaudio against the new golang 1.6 beta 1 release and it breaks port audio bindings. As a part of 1.6 they tighten the rules regarding Go pointers being passed into C memory.

This means that while programs compile, at run-time they abort. See below for the noise.go example from the distribution.

This example worked fine on 1.5.x and lower.

The related changes are described in golang/go#12416.

$ ./noise.exe
panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running]:
github.com/gordonklaus/portaudio._cgoCheckPointer1(0x4b8d00, 0x1298e230, 0x0, 0x0, 0x0, 0x4b1dc0)
        ??:0 +0x41
github.com/gordonklaus/portaudio.OpenStream(0x0, 0x0, 0x0, 0x0, 0x12988300, 0x2, 0x989680, 0x0, 0x0, 0x40e58880, ...)
        C:/Users/april/Projects/super-eight/GoPath/src/github.com/gordonklaus/portaudio/portaudio.go:504 +0x2f5
main.main()
        c:/Users/april/Projects/super-eight/GoPath/src/github.com/gordonklaus/portaudio/examples/noise.go:18 +0x104

play.go example aiff file sounds "strange"

Trying to playback an aiff file with the play.go example, playback is almost correct still the sound is weird like there is some kind of bandpass filter shadowing a frequency range. There is no problem with the file it plays correctly in other players. Are all files supposed to play correctly in the example or maybe I should change the some configurations ?

Not sure if this is a problem with the code or it is supposed to be that way.
Thanks for any support

Startup messages on ARM

Hi. This is not a bug report. The two logs below show up when everything is working fine. But is it possible to prevent these messages from showing up on startup on ARM? It looks as if a couple of hundred ms are lost every time all these options are being tried out. If it was possible to hide these messages, that would be good already. But being able to hint what to try first (and make startup quicker this way) would be even better. Thank you.

  • startup on AMD64
    ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
    ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
    ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side

  • startup on ARM
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM sysdefault
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM sysdefault
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM front
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround21
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround21
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround40
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround41
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround50
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround51
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround71
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM iec958
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM spdif
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM spdif
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
    ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
    ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
    ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
    ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM dmix
    connect(2) call to /tmp/jack-1000/default/jack_0 failed (err=No such file or directory)
    attempt to connect to server failed

Working example with go-mpg123

I'm working on a project where I will be using go-mpg123 (a port of the libmpg123 bindings in golang) but I'm having a hard time getting that library to play nicely with port audio.

I've gotten reasonably far in this gist but the audio playback is really distorted for some reason and I cant figure out what would be the issue.

Has anyone been able to get these two libraries successfully working together, and if so is there anything blatantly wrong with my code example? If I'm able to get something working, would this be a good candidate for the examples directory?

cross-compiling

Hi! I'm using MacOS, and would like to create app that works with microphone, ready-to-use on any platform (Windows, Linux, Mac)... so the question is - how to achieve this on my Mac?
Or... from any other OS (not a big deal to use Vagrant and build from there).

Stereo broken

Slices passed to the callback don't provide enough data in stereo mode.
The patch provides a sine.go test running in stereo and a fix for the problem.

Original issue reported on code.google.com by [email protected] on 28 Sep 2012 at 7:43

Attachments:

Installing on MSYS2 gives error

I'm trying to install the Go Portaudio package on MSYS2. I installed the mingw-w64-x86_64-portaudio through pacman and got all the needed development tools to build, make, compile and what not.

Tho, when i try go get github.com/gordonklaus/portaudio i get the following error/output:

go build github.com/gordonklaus/portaudio: invalid flag in pkg-config --cflags: -mthreads

Invalid error returned for paNoDevice in DefaultInputDevice and DefaultOutputDevice

When there are no input devices or output devices on the system, DefaultInputDevice (DefaultOutputDevice) calls C.Pa_GetDefaultInputDevice (C.Pa_GetDefaultInputDevice) which returns paNoDevice.

paNoDevice is < 0 so the wrappers return newError(C.PaError(i)); however paNoDevice is not a PaError. It's just a special number returned when there's no device.

Later when this error is printed it prints Invalid error code because paNoDevice is not a valid error code.

This error should not be wrapped under a portaudio.Error but probably instead just return some constant portaudio.errNoDevice.

cgo panic, Go 1.6 behaviour

After upgrading to Go 1.6 i get a panic:

panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 5 [running]:
panic(0x42157c0, 0xc8200e6050)
/usr/local/go/src/runtime/panic.go:481 +0x3e6
code.google.com/p/portaudio-go/portaudio._cgoCheckPointer1(0x4194520, 0xc8200ec000, 0x0, 0x0, 0x0, 0x4184060)
??:0 +0x4d
code.google.com/p/portaudio-go/portaudio.OpenStream(0x0, 0x0, 0x0, 0xc820016240, 0x1, 0xd9fb92, 0x40e5888000000000, 0x400, 0x0, 0xc8200e6000, ...)
/Users/jpad/gocode/extern/src/code.google.com/p/portaudio-go/portaudio/portaudio.go:502 +0x3d1
...

I think this caused by the stricter 1.6 rules about Go/C memory sharing? Is there a way around it?

Can't compile for ARM on OSX

I want to compile Go program on Mac and execute it later on Raspberry Pi (ARM arch), I ma using this way:

CGO_ENABLED=1 GOARCH=arm GOOS=linux go build -o culture-bot-rpi rpi-test/main.go
# runtime/cgo
clang: error: argument unused during compilation: '-mno-thumb' [-Werror,-Wunused-command-line-argument]

Is there a way to be able to compile it?

error on goinstall

What steps will reproduce the problem?
1. use `goinstall portaudio-go.googlecode.com/hg/portaudio`

What to expect: install without errors

What do you see instead?

bart@bart-laptop:~$ goinstall portaudio-go.googlecode.com/hg/portaudio
/bin/bash: === cd 
/home/bart/go/src/pkg/portaudio-go.googlecode.com/hg/portaudio; bash gomake -f- 
install
CGOPKGPATH=portaudio-go.googlecode.com/hg cgo --  portaudio.go 
error: 'getPaStreamCallback' undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: 'paContinue' undeclared (first use in this function)
unresolved names
make: *** [_obj/_cgo_run] Error 2
--- exit status 2
goinstall: portaudio-go.googlecode.com/hg/portaudio: install: running bash: 
exit status 2 ($GOPATH not set)


What version of the product are you using? On what operating system?
bart@bart-laptop:~$ 8g -V
8g version release.r60.3 9516

bart@bart-laptop:~$ uname -a
Linux bart-laptop 2.6.32-37-generic #81-Ubuntu SMP Fri Dec 2 20:35:14 UTC 2011 
i686 GNU/Linux

bart@bart-laptop:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 10.04.3 LTS
Release:    10.04
Codename:   lucid

Original issue reported on code.google.com by [email protected] on 15 Jan 2012 at 9:41

windows dll

Hi,
I'm trying to include portaudio in my go project for windows, but when i run, it ask for libportaudio-2.dll
If i add the dll in the same folder of built exe it works, but i would to know if i can include the libportaudio-2.dll in the exe so that i can distribute it standalone.

Thanks

examples/record.go not working keep getting panice error

Hello there :)

I am keeping getting panic error:

error log:

./record.exe test
Recording.  Press Ctrl-C to stop.
panic: Undefined external error.

goroutine 1 [running]:
main.chk(...)
       /portaudio/examples/record.go:91
main.main()
       /portaudio/examples/record.go:72 +0x7ca

System info:

MINGW64_NT-10.0-19045 test 3.4.9.x86_64 2023-09-15 12:15 UTC x86_64 Msys

go version go1.21.1 windows/amd64

$ pacman -Q
base 2022.06-1
bash 5.2.015-2
bash-completion 2.11-3
brotli 1.1.0-1
bsdtar 3.7.2-1
bzip2 1.0.8-4
ca-certificates 20230311-1
coreutils 8.32-5
curl 8.3.0-1
dash 0.5.12-1
db 5.3.28-5
file 5.45-1
filesystem 2023.02.07-1
findutils 4.9.0-3
gawk 5.2.2-1
gcc-libs 13.2.0-2
gdbm 1.23-1
getent 2.18.90-4
gettext 0.22-2
git 2.42.0-2
gmp 6.3.0-1
gnupg 2.2.41-1
grep 1~3.0-6
gzip 1.13-1
heimdal 7.8.0-4
heimdal-libs 7.8.0-4
inetutils 2.4-2
info 7.0.3-3
less 643-1
libargp 20110921-4
libasprintf 0.22-2
libassuan 2.5.6-1
libbz2 1.0.8-4
libcbor 0.10.2-1
libcurl 8.3.0-1
libdb 5.3.28-5
libedit 20221030_3.1-1
libexpat 2.5.0-1
libffi 3.4.4-1
libfido2 1.13.0-1
libgcrypt 1.10.2-1
libgdbm 1.23-1
libgettextpo 0.22-2
libgnutls 3.8.1-2
libgpg-error 1.47-1
libgpgme 1.22.0-2
libhogweed 3.9.1-1
libiconv 1.17-1
libidn2 2.3.4-2
libintl 0.22-2
libksba 1.6.4-1
liblz4 1.9.4-1
liblzma 5.4.4-1
libnettle 3.9.1-1
libnghttp2 1.56.0-2
libnpth 1.6-1
libopenssl 3.1.3-1
libp11-kit 0.25.0-1
libpcre 8.45-4
libpcre2_8 10.42-1
libpsl 0.21.2-1
libreadline 8.2.001-3
libsqlite 3.42.0-2
libssh2 1.11.0-1
libtasn1 4.19.0-1
libunistring 1.1-2
libutil-linux 2.35.2-4
libxcrypt 4.4.36-1
libxml2 2.11.5-1
libxslt 1.1.38-1
libzstd 1.5.5-1
make 4.4.1-1
mingw-w64-x86_64-binutils 2.41-2
mingw-w64-x86_64-brotli 1.1.0-1
mingw-w64-x86_64-bzip2 1.0.8-2
mingw-w64-x86_64-c-ares 1.19.1-1
mingw-w64-x86_64-ca-certificates 20230311-1
mingw-w64-x86_64-crt-git 11.0.0.r170.g833753684-1
mingw-w64-x86_64-curl 8.3.0-1
mingw-w64-x86_64-expat 2.5.0-1
mingw-w64-x86_64-gcc 13.2.0-2
mingw-w64-x86_64-gcc-ada 13.2.0-2
mingw-w64-x86_64-gcc-fortran 13.2.0-2
mingw-w64-x86_64-gcc-libgfortran 13.2.0-2
mingw-w64-x86_64-gcc-libs 13.2.0-2
mingw-w64-x86_64-gcc-objc 13.2.0-2
mingw-w64-x86_64-gdb 13.2-3
mingw-w64-x86_64-gdb-multiarch 13.2-3
mingw-w64-x86_64-gettext 0.21.1-2
mingw-w64-x86_64-gmp 6.3.0-2
mingw-w64-x86_64-go 1.21.1-1
mingw-w64-x86_64-headers-git 11.0.0.r170.g833753684-1
mingw-w64-x86_64-isl 0.26-1
mingw-w64-x86_64-libffi 3.4.4-1
mingw-w64-x86_64-libgccjit 13.2.0-2
mingw-w64-x86_64-libiconv 1.17-3
mingw-w64-x86_64-libidn2 2.3.4-1
mingw-w64-x86_64-libmangle-git 11.0.0.r170.g833753684-1
mingw-w64-x86_64-libpsl 0.21.2-4
mingw-w64-x86_64-libssh2 1.11.0-2
mingw-w64-x86_64-libsystre 1.0.1-4
mingw-w64-x86_64-libtasn1 4.19.0-1
mingw-w64-x86_64-libtre-git r128.6fb7206-2
mingw-w64-x86_64-libunistring 1.1-1
mingw-w64-x86_64-libwinpthread-git 11.0.0.r170.g833753684-1
mingw-w64-x86_64-libxml2 2.11.5-1
mingw-w64-x86_64-make 4.4-2
mingw-w64-x86_64-mpc 1.3.1-2
mingw-w64-x86_64-mpdecimal 2.5.1-1
mingw-w64-x86_64-mpfr 4.2.1-2
mingw-w64-x86_64-ncurses 6.4.20230708-1
mingw-w64-x86_64-nghttp2 1.56.0-1
mingw-w64-x86_64-openssl 3.1.3-1
mingw-w64-x86_64-p11-kit 0.25.0-2
mingw-w64-x86_64-pkg-config 0.29.2-3
mingw-w64-x86_64-portaudio 1~19.7.0-4
mingw-w64-x86_64-python 3.11.5-2
mingw-w64-x86_64-readline 8.2.001-6
mingw-w64-x86_64-rust 1.72.1-1
mingw-w64-x86_64-sqlite3 3.43.1-1
mingw-w64-x86_64-tcl 8.6.12-2
mingw-w64-x86_64-termcap 1.3.1-6
mingw-w64-x86_64-tk 8.6.12-2
mingw-w64-x86_64-tools-git 11.0.0.r170.g833753684-1
mingw-w64-x86_64-tzdata 2023c-1
mingw-w64-x86_64-windows-default-manifest 6.4-4
mingw-w64-x86_64-winpthreads-git 11.0.0.r170.g833753684-1
mingw-w64-x86_64-winstorecompat-git 11.0.0.r170.g833753684-1
mingw-w64-x86_64-xxhash 0.8.2-1
mingw-w64-x86_64-xz 5.4.4-1
mingw-w64-x86_64-zlib 1.3-1
mingw-w64-x86_64-zstd 1.5.5-1
mintty 1~3.6.5-1
mpfr 4.2.1-1
msys2-keyring 1~20230703-1
msys2-launcher 1.5-1
msys2-runtime 3.4.9-2
nano 7.2-1
ncurses 6.4-2
nettle 3.9.1-1
openssh 9.4p1-1
openssl 3.1.3-1
p11-kit 0.25.0-1
pacman 6.0.2-9
pacman-contrib 1.9.1-1
pacman-mirrors 20221016-1
perl 5.36.1-2
perl-Authen-SASL 2.16-3
perl-Clone 0.46-1
perl-Convert-BinHex 1.125-2
perl-Encode-Locale 1.05-2
perl-Error 0.17029-1
perl-File-Listing 6.16-1
perl-HTML-Parser 3.81-1
perl-HTML-Tagset 3.20-3
perl-HTTP-Cookies 6.10-2
perl-HTTP-Daemon 6.16-1
perl-HTTP-Date 6.06-1
perl-HTTP-Message 6.44-1
perl-HTTP-Negotiate 6.01-3
perl-IO-HTML 1.004-2
perl-IO-Socket-SSL 2.083-1
perl-IO-Stringy 2.113-1
perl-LWP-MediaTypes 6.04-1
perl-MIME-tools 5.510-1
perl-MailTools 2.21-1
perl-Net-HTTP 6.23-1
perl-Net-SMTP-SSL 1.04-2
perl-Net-SSLeay 1.92-5
perl-TermReadKey 2.38-5
perl-TimeDate 2.33-2
perl-Try-Tiny 0.31-1
perl-URI 5.21-1
perl-WWW-RobotRules 6.02-2
perl-libwww 6.67-1
pinentry 1.2.1-1
rebase 4.5.0-4
sed 4.9-1
tar 1.35-1
time 1.9-3
tzcode 2023c-1
util-linux 2.35.2-4
wget 1.21.4-1
which 2.21-4
xz 5.4.4-1
zlib 1.3-1
zstd 1.5.5-1

Stuttering in realtime stream

How I can play real time stream without stuttering?
It is work code. Sometimes it leads to an error in the method Write (Output underflowed).
Thanks in advance for your help!

package main

import (
	"fmt"
	"log"
	"math"
	"sync"
	"time"

	"github.com/gordonklaus/portaudio"
)

func main() {

	params := Params{
		SamplesPerSecond: 8000,
		SamplesPerPacket: 2000,
	}

	quit := make(chan struct{})
	packets := generate(quit, params)

	var wg sync.WaitGroup
	wg.Add(1)
	go playPortaudio(&wg, packets, params)
	time.Sleep(10 * time.Second)
	close(quit)
	wg.Wait()
}

func playPortaudio(wg *sync.WaitGroup, packets <-chan []int16, params Params) {
	defer wg.Done()

	err := portaudio.Initialize()
	checkError(err)

	defer portaudio.Terminate()

	var (
		channels = 1

		numberInputChannels  = 0
		numberOutputChannels = channels
		sampleRate           = float64(params.SamplesPerSecond)
		framesPerBuffer      = params.SamplesPerPacket * channels
		out                  = make([]int16, framesPerBuffer)
	)

	stream, err := portaudio.OpenDefaultStream(
		numberInputChannels,
		numberOutputChannels,
		sampleRate,
		framesPerBuffer,
		&out,
	)
	checkError(err)

	err = stream.Start()
	checkError(err)

	for packet := range packets {
		copy(out, packet)

		err = stream.Write()
		if err != nil {
			fmt.Println("ERROR:", err)
		}
	}
}

func checkError(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func playPrintln(wg *sync.WaitGroup, packets <-chan []int16) {
	defer wg.Done()
	for packet := range packets {
		fmt.Println(len(packet))
	}
}

type Params struct {
	SamplesPerSecond int // sampleRate
	SamplesPerPacket int
}

func generate(quit <-chan struct{}, params Params) <-chan []int16 {
	packets := make(chan []int16)
	go func() {
		gen(quit, packets, params)
		close(packets)
	}()
	return packets
}

func gen(quit <-chan struct{}, packets chan<- []int16, params Params) {

	ts := NewToneSampler(
		Garmonica{
			Amplitude: float64(math.MaxInt16) * 0.7,
			Frequency: 1000,
			Phase:     0,
		},
		params.SamplesPerSecond,
	)

	t := time.Now()

	//sampleDuration := time.Second / time.Duration(params.SamplesPerSecond)
	packetDuration := (time.Second * time.Duration(params.SamplesPerPacket)) / time.Duration(params.SamplesPerSecond)

	//fmt.Println("packet duration:", packetDuration)

	for {
		packet := make([]int16, params.SamplesPerPacket)
		for i := range packet {
			packet[i] = int16(ts.NextSample())
		}

		select {
		case <-quit:
			return
		case packets <- packet:
		}

		// calc sleep
		t = t.Add(packetDuration)
		d := t.Sub(time.Now())
		if d > 0 {
			time.Sleep(d)
		}
	}
}

type Sampler interface {
	NextSample() float64
}

// amplitude * sin( 2 * pi * frequency * t + phase)
// w = 2 * pi * frequency
// amplitude * sin( w * t + phase)

type Garmonica struct {
	Amplitude, Frequency, Phase float64
}

type ToneSampler struct {
	g  Garmonica
	w  float64 // 2 * pi * frequency
	t  time.Duration
	dt time.Duration // sampleDuration
}

var _ Sampler = &ToneSampler{}

// sampleRate, samplesPerSecond
func NewToneSampler(g Garmonica, sampleRate int) *ToneSampler {

	w := 2.0 * math.Pi * g.Frequency
	sampleDuration := time.Second / time.Duration(sampleRate)

	return &ToneSampler{
		g:  g,
		w:  w,
		t:  0,
		dt: sampleDuration,
	}
}

func (p *ToneSampler) Reset() {
	p.t = 0
}

func (p *ToneSampler) NextSample() float64 {
	angle := p.w*p.t.Seconds() + p.g.Phase
	sample := p.g.Amplitude * math.Sin(angle)
	p.t += p.dt
	return sample
}

Device without default input or output not handled

When I run eg. examples/enumerate.go, I get a panic.

Looks like I have two audio devices found by portaudio;

1. OSS
2. ALSA

The first one does not have a input or output device at all. This is version 
19+svn20071022-3.2 of portaudio found on Debian Squeeze.

Using the latest version from SVN only shifts the order of them.

Am I not supposed to have a device like this? Attached is at least a small fix 
to the problem.

Original issue reported on code.google.com by [email protected] on 1 Nov 2013 at 3:34

Attachments:

Compiling a static library

Hi,
I'm trying to compile a portaudio.dll but that gives me a lot of headache.
So I was wondering if threre's a way to compile a static go library instead of a shared one.
I'm not very familiar with the whole cgo process and my knowledge of c/c++ is very basic.
I know that rtaudio has a way to create a static go library.
Maybe someone can get me in the right direction to do it with go-portaudio
Regards,
Cor

play.go example not working

Tried with several files, none works. In case it's not my files, a sample for testing would be a useful addition.

Playing Opus stream causes playback half speed

Hi,
I'm writing an open-source Subsonic client in GO.

Inspired by mp3 example I tried to make a function that would stream opus data on demand. It almost worked but it plays in half speed.

Assume that source file is 16bit 44100 stereo flac transcoded on the fly by server to same parameters opus but with lower 192 bitrate.

I tried to double sample rate but then it surprisingly plays 2x faster than normal... So I end with two times faster or two times slower playback

import (
	"os"
	"os/signal"
	"strconv"

	"gopkg.in/hraban/opus.v2"
	"github.com/gordonklaus/portaudio"

)

const rate float64 = 44100
const seconds = 2
const channels = 2


func PlayOpusStream(){
       // get data
        sig := make(chan os.Signal, 1)
	signal.Notify(sig, os.Interrupt, os.Kill)
	nodeID, _ := MainQueue.Get(NowPlayingIndex)
	param := map[string]string{
		"maxBitRate":            "192",
		"MainFormat":            "opus",
		"transcodings":          "opus",
		"estimateContentLength": "true",
	}
	portaudio.Initialize()
	defer portaudio.Terminate()
	out := make([]int16, 192)
        //Create reader
	reader, err := CurrentClient.Stream(nodeID.(string), param)
	chk(err)
        // Make opus stream
	opusStr, err := opus.NewStream(reader)
	chk(err)
	stream, err := portaudio.OpenDefaultStream(0, 2, rate, cap(out), &out)
	chk(err)
	chk(stream.Start())
	for {
		_, err := opusStr.Read(out)
		if err == opus.ErrStreamEOF {
			return
		}
		chk(stream.Write())
		select {
		case <-sig:
			return
		default:
		}
	}
	chk(stream.Stop())
	defer stream.Close()
}


func chk(err error) {
	if err != nil {
		panic(err)
	}

}

The second problem is, that opus decoder has in its method []int16 or []float32 so I can't play like in mp3 example with byte[]...

Could you help me find any solution?
Thanks in advance :)

Cheers
Michael

Any example code for the StreamCallback method?

Thanks for the work on this library!

I am having some timing issues with the simple blocking Write() method, so I though to give a try to the StreamCallback method. Is there any example code out there in the wild?

My attempt only creates some painful noise in my headphones:

// Frames should be arriving to this channel
frames := make(chan []int16, 50) // 20ms * 50 = 1sec

outDev, _ := portaudio.DefaultOutputDevice()
p := portaudio.HighLatencyParameters(nil, outDev)
p.Input.Channels = 0
p.Output.Channels = 1
p.SampleRate = float64(rate)
p.FramesPerBuffer = len(frame) // portaudio.FramesPerBufferUnspecified

cb := func(out []int16, timeInfo portaudio.StreamCallbackTimeInfo, flags portaudio.StreamCallbackFlags) {
	select {
	case out := <-frames:
		break;
	default:
		out = silence
	}
}

stream, _ := portaudio.OpenStream(p, cb)

Cannot use with gocv

I am getting this dyld error when trying to use portaudio alongside gocv (https://github.com/hybridgroup/gocv). I can use both libs separately, but once they are both included in the import, I receive the following:

ld: warning: building for macOS, but linking in object file (/var/folders/8v/llscdj8d6xjbl24jns0y8d653ffg5j/T/go-link-828557976/go.o) built for
dyld: Symbol not found: __ZTISt12length_error
  Referenced from: /var/folders/8v/llscdj8d6xjbl24jns0y8d653ffg5j/T/go-build438544180/b001/exe/main
  Expected in: /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox
 in /var/folders/8v/llscdj8d6xjbl24jns0y8d653ffg5j/T/go-build438544180/b001/exe/main
signal: abort trap

Using OS X 10.14.5 (Mojave), go version go1.12.6 darwin/amd64. I'm not sure where to look from here. Has anyone seen something like this before?

Playback cutoff in blocking stream mode

Hi,

I'm trying to decode and play an OGG file, but the playback is always cut off before the end of the file. I can get it to play fully if I add a few more stream.Write() calls at the end of my program, as if the output buffer was not completely exhausted somehow.

I wanted to try the play.go example to compare, but I was not able to find a WAV file that worked with the example code. I also tried with decoding a FLAC file but ran into the same issue.

Here's the code, and I'm attaching the sample OGG file as well. It's probably something wrong in my code and how I interact with the buffers, but I can't figure it out, any help would be appreciated!

Thanks!

package main

import (
	"fmt"
	"io"
	"os"

	"github.com/gordonklaus/portaudio"
	"github.com/jfreymuth/oggvorbis"
)

func main() {

	// PortAudio output buffer
	paBuf := make([]float32, 1024*8)

	file, err := os.Open("03 - OGG Sample.ogg")
	chk(err)
	defer file.Close()

	oggReader, err := oggvorbis.NewReader(file)
	chk(err)

	portaudio.Initialize()
	defer portaudio.Terminate()
	h, err := portaudio.DefaultHostApi()
	chk(err)

	fmt.Printf("Channels: %v, SampleRate: %v\n", oggReader.Channels(), oggReader.SampleRate())
	streamParameters := portaudio.StreamParameters{
		Output: portaudio.StreamDeviceParameters{
			Device:   h.DefaultOutputDevice,
			Channels: oggReader.Channels(),
			Latency:  h.DefaultOutputDevice.DefaultLowOutputLatency,
		},
		Input: portaudio.StreamDeviceParameters{
			Device: nil,
		},
		SampleRate:      float64(oggReader.SampleRate()),
		FramesPerBuffer: len(paBuf),
	}

	stream, err := portaudio.OpenStream(streamParameters, &paBuf)
	chk(err)

	defer stream.Close()
	chk(stream.Start())
	defer stream.Stop()

	var buffer []float32
	var n int
	for err != io.EOF {
		// Read enough data to fill paBuf
		for len(buffer) < len(paBuf) && err == nil {
			b := make([]float32, len(paBuf))
			n, err = oggReader.Read(b)
			buffer = append(buffer, b[:n]...)
		}

		fmt.Printf("buffer length: %v\n", len(buffer))

		if len(buffer) > 0 {
			n = copy(paBuf, buffer)
			buffer = buffer[n:]
			writeErr := stream.Write()
			chk(writeErr)
		}
	}

	fmt.Printf("finished. remaining in buffer: %v\n", len(buffer))
	for len(buffer) > 0 {
		n = Min(len(buffer), len(paBuf))
		copy(paBuf, buffer[:n])
		buffer = buffer[n:]
		writeErr := stream.Write()
		chk(writeErr)
	}

	// Uncomment these to get the complete playback
	// stream.Write()
	// stream.Write()
	// stream.Write()
	// stream.Write()

}

func chk(err error) {
	if err != nil {
		panic(err)
	}
}

func Min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

03 - OGG Sample.zip

Does not appear to work with PipeWire

Hi Gordon,

On my Arch Linux installation I use the latest version of PipeWire (0.3.32).

Pipewire provides supports for (at least) Jack and PulseAudio.

This works great with Firefox, SDL2, and Jack-related applications in general, but it fails when I run sigourney (which uses this portaudio package). I get:

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
Cannot connect to server socket err = Ingen slik fil eller filkatalog
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Press enter to quit...

When starting Jack with qjackctl first (which I believe uses PipeWire), I get a somewhat briefer error message:

ALSA lib pcm_dsnoop.c:600:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1035:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
ALSA lib pcm_dmix.c:1035:(snd_pcm_dmix_open) unable to open slave
Press enter to quit...

But the application does not appear to get an audio device (unless I am testing this incorrectly).

Any advice on this is appreciated.

And thanks for creating the portaudio package!

Cheers,
Alexander F. Rรธdseth

Opening a stream with a framesPerBuffer of 0 causes a buffer underrun and a stutter

s.Stream, err = portaudio.OpenDefaultStream(0, 2, sampleRate, 0, s.processAudio)

I noticed in your example I receive many messages about a underrun accompanied with a jarring stutter, I simply changed the framesPerBuffer parameter to 1024 and no longer received these messages.

Terminal output with original framesPerBuffer amount:

% go run main.go
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred

Running mp3 example with hajimehoshi/go-mp3 library

Hi!

I am trying to reproduce the mp3 example but using a different mp3 library. My current attempt is available in this gist.

The code compiles, the sound is playing, but it is heavily distorted - there is a glitch per each read-write cycle. One can see that by tweaking the bufsize variable - the smaller the buffer, the higher the glitching frequency.

I took a look at this issue, but I cannot quite figure out what is the problem in my case :(

Thanks!
Yuriy

Constant Beep When Playing Back Audio

I wrote two files, one client and one server to send data via TCP and currently I got the connection to work but the issue is on the client end where the audio is played all you can hear is a beep I have no idea why this is an issue as everything seems right programmatically.

License

Can you clarify what is the license under which your portaudio go code is published? Can you please add a license to it so it is clear.

"Unknow Error" in MacOS Big Sur

I update my mac to the latest system Big Sur
I installed portautio by

brew install portaudio

when I run OpenDefaultStream, I got the following error:

"||PaMacCore (AUHAL)|| Error on line 1277: err='-66748', msg=Unknown Error"

but my pyhton code using pyaudio works fine.

Then I run brew uninstall portaudio and
brew install portaudio --HEAD

the "Unknown Error" disappeared, but I got an Warrning!

ld: warning: directory not found for option '-L/usr/local/Cellar/portaudio/19.6.0/lib'

fatal error: checkptr: pointer arithmetic result points to invalid allocation

I am getting the following trace when running a test with the -race flag:

fatal error: checkptr: pointer arithmetic result points to invalid allocation

goroutine 20 [running]:
runtime.throw({0x718607?, 0x8?})
        /usr/lib/go/src/runtime/panic.go:1047 +0x5d fp=0xc00011bb98 sp=0xc00011bb68 pc=0x449e5d
runtime.checkptrArithmetic(0x1?, {0x0, 0x0, 0xc80?})
        /usr/lib/go/src/runtime/checkptr.go:69 +0xaa fp=0xc00011bbc8 sp=0xc00011bb98 pc=0x41a00a
github.com/gordonklaus/portaudio.getBuffer(0xc000190060, 0xc0001ae000)
        /home/user/go/pkg/mod/github.com/gordonklaus/[email protected]/portaudio.go:1038 +0x353 fp=0xc00011bc58 sp=0xc00011bbc8 pc=0x668633

Without the race flag - everything works without issues.

unable to open on a device

Hi everyone,

First of all, great job everyone involved in the construction of this piece of software.

I have been using portaudio very successfully for the past weeks for developing a low delay app for musicians
https://bitbucket.org/claudio_ortega/jambridge/src/master/doc/jambridge-README.md

Here's the bad news,
I've run today into an issue, which seems to be very likely system dependent.

I am using an AudioBox USB96 interface, which has been working and still works just fine.
Please find at the bottom the test case with the minimum piece of code that shows the failure.
The problem is in the call to OpenStream() which returns "PortAudio Internal Error"

The test passes in these two test beds:

  • (1) ubuntu 20.02 box
  • (2) iMac Late 2009 running Catalina (w/dosdude adaptor)

The exact same test does not pass in my third test bed:

  • (3) Mac Mini 2018 w/ Big Sur.

In all cases I am with go1.15.x, and I have no 'user' applications opened.
Also in all cases I've verified that the name for the device picked up by the call to DefaultInputDevice
is always the same: "AudioBox USB 96", which is the one that I expect and the one I want.

The audio parameters used in the test are: 44.1k/64samples/16bits/1channel.
However, I've tried with different combinations of sampling freq and buffer length,
all working fine on 1,2 above, but none of those have worked on (3).

I hope somebody has run into this issue, and hopefully might shed some light on it.

Thanks again for the great work put on this library.

Claudio

package audiotest

import (
	"testing"
	"time"
	"github.com/gordonklaus/portaudio"
)

func TestBigSurIssue(t *testing.T) {

	err := portaudio.Initialize()
	checkErr(t, err)

	inputDeviceInfo, err := portaudio.DefaultInputDevice()
	checkErr(t, err)

	streamParameters := portaudio.LowLatencyParameters(inputDeviceInfo, nil)
	streamParameters.SampleRate = 44100.0
	streamParameters.FramesPerBuffer = 64
	streamParameters.Input.Channels = 1
	streamParameters.Input.Latency = time.Millisecond

	_, err = portaudio.OpenStream(
		streamParameters,
		func(in []int16,
			outIgnore []int16,
			timeInfo portaudio.StreamCallbackTimeInfo,
			flags portaudio.StreamCallbackFlags,
		) {
		})
	checkErr(t, err)

	err = portaudio.Terminate()
	checkErr(t, err)
}

func checkErr(t testing.TB, err error) {
	if err != nil {
		t.Fatal(err)
	}
}

MacOS compile Windows error

Hello!
Is it real to compile portaudio for windows from macos?

I using this payload to go this:
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC="x86_64-w64-mingw32-gcc" go build -o recorder_v1.exe
but gettting error:
x86_64-w64-mingw32-gcc: error: unrecognized command-line option '-framework x4
Could you tell how fix it, pls?

Google Code is shutting down. Please migrate this project elsewhere.

What steps will reproduce the problem?
1. Go to https://code.google.com/p/portaudio-go/

What is the expected output?
Since Google Code is shutting down, I expect to see a link to a replacement 
repo.

What do you see instead?
Instead, this project's page seems completely oblivious to the Google Code 
shutdown.

Please provide any additional information below.
The "Export to GitHub" button is a convenient way to migrate to GitHub. More 
information is at the blog post explaining the shutdown at [1] and the summary 
page at [2].

References:
1. http://google-opensource.blogspot.com/2015/03/farewell-to-google-code.html
2. https://code.google.com/p/support/wiki/ReadOnlyTransition

Original issue reported on code.google.com by MarkHkamp on 10 Aug 2015 at 8:34

fatal error: unexpected signal during runtime execution

Hi,

I'm using this library to read an audio stream (of a click track) and determine when a click happens to start a playback of a light show. Unfortunately the program crashed every now and then, but not in a reproducible interval. The error thrown is the following - any idea what's going on there? :(

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0xb pc=0x76cc3e4c]
runtime stack:
runtime.throw(0x469cbf, 0x2a)
       /usr/local/go/src/runtime/panic.go:617 +0x5c
runtime.sigpanic()
       /usr/local/go/src/runtime/signal_unix.go:374 +0x3fc
goroutine 93703 [syscall]:
runtime.cgocall(0x39fcf0, 0xc285b4, 0xd5c784)
       /usr/local/go/src/runtime/cgocall.go:128 +0x5c fp=0xc2859c sp=0xc28584 pc=0x150fc
github.com/StageAutoControl/controller/vendor/github.com/gordonklaus/portaudio._Cfunc_Pa_OpenStream(0xd5c784, 0xcf35e0, 0x0, 0x0, 0x40e58880, 0x40, 0x0, 0x0, 0x15, 0x0)
       _cgo_gotypes.go:498 +0x38 fp=0xc285b0 sp=0xc2859c pc=0x1f5e60
github.com/StageAutoControl/controller/vendor/github.com/gordonklaus/portaudio.OpenStream.func1(0xd5c780, 0xcf0100, 0x1, 0x213766b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/gordonklaus/portaudio/portaudio.go:641 +0x168 fp=0xc285fc sp=0xc285b0 pc=0x1f9480
github.com/StageAutoControl/controller/vendor/github.com/gordonklaus/portaudio.OpenStream(0xcf0100, 0x1, 0x213766b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40e58880, ...)
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/gordonklaus/portaudio/portaudio.go:641 +0xa4 fp=0xc2865c sp=0xc285fc pc=0x1f7360
github.com/StageAutoControl/controller/vendor/github.com/gordonklaus/portaudio.OpenDefaultStream(0x1, 0x0, 0x0, 0x40e58880, 0x40, 0x100bd40, 0x1, 0x1, 0x40007, 0x0, ...)
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/gordonklaus/portaudio/portaudio.go:677 +0xa0 fp=0xc286dc sp=0xc2865c pc=0x1f74d4
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).start(0xcf9aa0, 0xb, 0xc0ab80)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:37 +0x17c fp=0xc28734 sp=0xc286dc pc=0x1fb604
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).Wait(0xcf9aa0, 0xe58a00, 0xe58a40, 0x8082d4, 0x0)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:87 +0x20 fp=0xc287bc sp=0xc28734 pc=0x1fba78
github.com/StageAutoControl/controller/pkg/cntl/playback.(*Player).wait.func2(0x100bd38, 0xe58a00, 0xe58a40, 0xcf9ad0)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/playback/player.go:83 +0x38 fp=0xc287dc sp=0xc287bc pc=0x1fe0cc
runtime.goexit()
       /usr/local/go/src/runtime/asm_arm.s:868 +0x4 fp=0xc287dc sp=0xc287dc pc=0x6fc78
created by github.com/StageAutoControl/controller/pkg/cntl/playback.(*Player).wait
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/playback/player.go:82 +0xe4
goroutine 1 [IO wait]:
internal/poll.runtime_pollWait(0x635c0ef8, 0x72, 0x0)
       /usr/local/go/src/runtime/netpoll.go:182 +0x48
internal/poll.(*pollDesc).wait(0xd5d874, 0x72, 0x0, 0x0, 0x456184)
       /usr/local/go/src/internal/poll/fd_poll_runtime.go:87 +0x80
internal/poll.(*pollDesc).waitRead(...)
       /usr/local/go/src/internal/poll/fd_poll_runtime.go:92
internal/poll.(*FD).Accept(0xd5d860, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
       /usr/local/go/src/internal/poll/fd_unix.go:384 +0x1b0
net.(*netFD).accept(0xd5d860, 0xfed9253, 0xcabf6ecc, 0x898)
       /usr/local/go/src/net/fd_unix.go:238 +0x20
net.(*TCPListener).accept(0xc10f08, 0x0, 0x1, 0x13bbc)
       /usr/local/go/src/net/tcpsock_posix.go:139 +0x20
net.(*TCPListener).AcceptTCP(0xc10f08, 0x10926a0, 0xc96f8900, 0x49e98)
       /usr/local/go/src/net/tcpsock.go:247 +0x40
net/http.tcpKeepAliveListener.Accept(0xc10f08, 0xdc6cb0, 0xc, 0xc000e0, 0x3185c0)
       /usr/local/go/src/net/http/server.go:3264 +0x1c
net/http.(*Server).Serve(0xd50400, 0x4fbc08, 0xc10f08, 0x0, 0x0)
       /usr/local/go/src/net/http/server.go:2859 +0x1e4
net/http.(*Server).ListenAndServe(0xd50400, 0x4, 0x45b23e)
       /usr/local/go/src/net/http/server.go:2797 +0xd4
github.com/StageAutoControl/controller/pkg/api/server.(*Server).Run(0xcf80f0, 0x4fc1e8, 0xcf2840, 0xc183d0, 0xc, 0xc18301, 0x0)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/api/server/server.go:110 +0x3e0
github.com/StageAutoControl/controller/cmd.glob..func4(0x7c79d8, 0xd00170, 0x0, 0x2)
       /etc/controller/src/github.com/StageAutoControl/controller/cmd/server.go:46 +0x304
github.com/StageAutoControl/controller/vendor/github.com/spf13/cobra.(*Command).execute(0x7c79d8, 0xd00140, 0x2, 0x2, 0x7c79d8, 0xd00140)
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/spf13/cobra/command.go:766 +0x204
github.com/StageAutoControl/controller/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x7c78a8, 0xc6a030, 0x0, 0x1)
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/spf13/cobra/command.go:850 +0x1f0
github.com/StageAutoControl/controller/vendor/github.com/spf13/cobra.(*Command).Execute(...)
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/spf13/cobra/command.go:800
github.com/StageAutoControl/controller/cmd.Execute()
       /etc/controller/src/github.com/StageAutoControl/controller/cmd/root.go:64 +0x24
main.main()
       /etc/controller/src/github.com/StageAutoControl/controller/main.go:12 +0x14
goroutine 19 [syscall, 124 minutes]:
os/signal.signal_recv(0x0)
       /usr/local/go/src/runtime/sigqueue.go:139 +0x130
os/signal.loop()
       /usr/local/go/src/os/signal/signal_unix.go:23 +0x14
created by os/signal.init.0
       /usr/local/go/src/os/signal/signal_unix.go:29 +0x30
goroutine 35 [chan receive, 124 minutes]:
github.com/StageAutoControl/controller/vendor/github.com/apinnecke/go-exitcontext.NewWithContext.func1(0xcf06c0, 0xcf6220)
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/apinnecke/go-exitcontext/context.go:23 +0x24
created by github.com/StageAutoControl/controller/vendor/github.com/apinnecke/go-exitcontext.NewWithContext
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/apinnecke/go-exitcontext/context.go:22 +0xc8
goroutine 4 [chan receive, 124 minutes]:
github.com/StageAutoControl/controller/cmd.glob..func2.1()
       /etc/controller/src/github.com/StageAutoControl/controller/cmd/root.go:46 +0x40
created by github.com/StageAutoControl/controller/cmd.glob..func2
       /etc/controller/src/github.com/StageAutoControl/controller/cmd/root.go:45 +0x1cc
goroutine 5 [chan receive, 124 minutes]:
github.com/StageAutoControl/controller/pkg/process.(*manager).listenExit(0xc0c660)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/process/manager.go:37 +0x3c
created by github.com/StageAutoControl/controller/pkg/process.NewManager
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/process/manager.go:31 +0x90
goroutine 6 [select]:
github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet.(*Node).pollReplyLoop(0xd56000)
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet/node.go:132 +0xf0
created by github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet.(*Node).Start
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet/node.go:110 +0x5c4
goroutine 7 [select]:
github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet.(*Node).recvLoop(0xd56000)
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet/node.go:222 +0x9c
created by github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet.(*Node).Start
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet/node.go:111 +0x5e0
goroutine 8 [select]:
github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet.(*Node).sendLoop(0xd56000)
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet/node.go:158 +0x80
created by github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet.(*Node).Start
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet/node.go:112 +0x5fc
goroutine 21 [IO wait]:
internal/poll.runtime_pollWait(0x635c0f7c, 0x72, 0x0)
       /usr/local/go/src/runtime/netpoll.go:182 +0x48
internal/poll.(*pollDesc).wait(0xd5d7d4, 0x72, 0x1000, 0x1000, 0x0)
       /usr/local/go/src/internal/poll/fd_poll_runtime.go:87 +0x80
internal/poll.(*pollDesc).waitRead(...)
       /usr/local/go/src/internal/poll/fd_poll_runtime.go:92
internal/poll.(*FD).ReadFrom(0xd5d7c0, 0xd32f70, 0x1000, 0x1000, 0x0, 0x0, 0x0, 0x0, 0x0)
       /usr/local/go/src/internal/poll/fd_unix.go:219 +0x16c
net.(*netFD).readFrom(0xd5d7c0, 0xd32f70, 0x1000, 0x1000, 0x1, 0x1, 0x3fe14, 0x75a78, 0x176c30)
       /usr/local/go/src/net/fd_unix.go:208 +0x38
net.(*UDPConn).readFrom(0xc10e58, 0xd32f70, 0x1000, 0x1000, 0x178304, 0xc1807c, 0x4, 0x4)
       /usr/local/go/src/net/udpsock_posix.go:47 +0x38
net.(*UDPConn).ReadFromUDP(0xc10e58, 0xd32f70, 0x1000, 0x1000, 0x4, 0x4, 0x1, 0x0)
       /usr/local/go/src/net/udpsock.go:109 +0x44
github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet.(*Node).recvLoop.func1(0xd56000)
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet/node.go:189 +0x6c
created by github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet.(*Node).recvLoop
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet/node.go:186 +0x30
goroutine 10 [select]:
github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet.(*Controller).pollLoop(0xc524c0)
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet/controller.go:171 +0x190
created by github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet.(*Controller).Start
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet/controller.go:130 +0x300
goroutine 11 [runnable]:
github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet.(*Controller).dmxUpdateLoop(0xc524c0)
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet/controller.go:248 +0x730
created by github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet.(*Controller).Start
       /etc/controller/src/github.com/StageAutoControl/controller/vendor/github.com/jsimonetti/go-artnet/controller.go:131 +0x31c
goroutine 12 [chan receive, 3 minutes]:
github.com/StageAutoControl/controller/pkg/artnet.(*controller).sendBackground(0xc0c600)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/artnet/controller.go:106 +0x138
created by github.com/StageAutoControl/controller/pkg/artnet.(*controller).Start
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/artnet/controller.go:65 +0x118
goroutine 13 [chan receive]:
github.com/StageAutoControl/controller/pkg/artnet.(*controller).debugDevices(0xc0c600)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/artnet/controller.go:127 +0x90
created by github.com/StageAutoControl/controller/pkg/artnet.(*controller).Start
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/artnet/controller.go:66 +0x134
goroutine 14 [chan receive, 124 minutes]:
github.com/StageAutoControl/controller/pkg/api/server.(*Server).Run.func2(0x4fc1e8, 0xcf2840, 0xd50400, 0xcf80f0)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/api/server/server.go:102 +0x38
created by github.com/StageAutoControl/controller/pkg/api/server.(*Server).Run
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/api/server/server.go:101 +0x358
goroutine 81119 [chan send, 11 minutes]:
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).notifyWait(0xf40090)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:81 +0x44
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).checkForPeak(0xf40090)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:73 +0x60
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).readStream(0xf40090)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:59 +0x3c
created by github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).start
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:46 +0x334
goroutine 53503 [chan send, 32 minutes]:
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).notifyWait(0xf40b10)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:81 +0x44
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).checkForPeak(0xf40b10)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:73 +0x60
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).readStream(0xf40b10)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:59 +0x3c
created by github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).start
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:46 +0x334
goroutine 31760 [chan send, 78 minutes]:
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).notifyWait(0xcfc0c0)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:81 +0x44
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).checkForPeak(0xcfc0c0)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:73 +0x60
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).readStream(0xcfc0c0)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:59 +0x3c
created by github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).start
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:46 +0x334
goroutine 577 [chan send, 117 minutes]:
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).notifyWait(0xcfcb40)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:81 +0x44
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).checkForPeak(0xcfcb40)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:73 +0x60
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).readStream(0xcfcb40)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:59 +0x3c
created by github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).start
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:46 +0x334
goroutine 10364 [chan send, 110 minutes]:
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).notifyWait(0x1038ab0)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:81 +0x44
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).checkForPeak(0x1038ab0)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:73 +0x60
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).readStream(0x1038ab0)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:59 +0x3c
created by github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).start
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:46 +0x334
goroutine 69747 [chan send, 18 minutes]:
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).notifyWait(0x1038030)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:81 +0x44
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).checkForPeak(0x1038030)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:73 +0x60
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).readStream(0x1038030)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:59 +0x3c
created by github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).start
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:46 +0x334
goroutine 47837 [chan send, 38 minutes]:
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).notifyWait(0xc962d0)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:81 +0x44
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).checkForPeak(0xc962d0)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:73 +0x60
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).readStream(0xc962d0)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:59 +0x3c
created by github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).start
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:46 +0x334
goroutine 34366 [chan send, 68 minutes]:
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).notifyWait(0xcfc150)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:81 +0x44
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).checkForPeak(0xcfc150)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:73 +0x60
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).readStream(0xcfc150)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:59 +0x3c
created by github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).start
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:46 +0x334
goroutine 49019 [chan send, 38 minutes]:
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).notifyWait(0xff2210)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:81 +0x44
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).checkForPeak(0xff2210)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:73 +0x60
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).readStream(0xff2210)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:59 +0x3c
created by github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).start
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:46 +0x334
goroutine 43926 [chan send, 41 minutes]:
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).notifyWait(0xf40000)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:81 +0x44
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).checkForPeak(0xf40000)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:73 +0x60
github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).readStream(0xf40000)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:59 +0x3c
created by github.com/StageAutoControl/controller/pkg/cntl/waiter.(*Audio).start
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/waiter/audio.go:46 +0x334
goroutine 93701 [select]:
github.com/StageAutoControl/controller/pkg/cntl/playback.(*Player).wait(0xcf9ad0, 0x4fc1e8, 0x10b6cc0, 0x0, 0x0)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/playback/player.go:89 +0x1b4
github.com/StageAutoControl/controller/pkg/cntl/playback.(*Player).PlaySong(0xcf9ad0, 0x4fc1e8, 0x10b6cc0, 0x10d2c30, 0x24, 0x0, 0x0)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/playback/player.go:112 +0x1c4
github.com/StageAutoControl/controller/pkg/cntl/playback.(*Process).Start(0xc53400, 0x4fc1e8, 0xcf2840, 0x10b0470, 0x6fc7c)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/cntl/playback/process.go:72 +0x370
github.com/StageAutoControl/controller/pkg/process.(*manager).Start.func1(0xc53440, 0xc0c660, 0x457548, 0x8)
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/process/manager.go:94 +0x3c
created by github.com/StageAutoControl/controller/pkg/process.(*manager).Start
       /etc/controller/src/github.com/StageAutoControl/controller/pkg/process/manager.go:93 +0x1d0

This is the code which reads the stream (Initialize and Terminate are called once on programm start and exit), with the line throwing the error marked: https://github.com/StageAutoControl/controller/blob/master/pkg/cntl/waiter/audio.go#L37

Looking forward to any helpful input - and thanks in advance!
Alex

EDIT: Cleaned up log for readability, removing systemd infos.

Playback issue with 24 bitsPerSample audio content

Hi, unfortunately I am not able to play back 24/96 flac files. Such content usually gives me an "Output underflowed" error message or just trash noise. Here some free 24bps content:

http://www.lindberg.no/hires/test/2L-125_stereo-88k-24b_04.flac

When I call OpenDefaultStream(), do I have to hand over a buffer created with make([]portaudio.Int24,framesPerBuffer) instead of make([]int16,framesPerBuffer)? Anything else I should be aware of when trying to play back 24bps audio content? Thank you.

how can I use go get ?

Dear Sir
Sorry for the interruption
I want to know if I can use go get to install this library?
or
How to install this library?

Issues installing on Windows

Hi,

I am trying to attach to audio streams on windows with go and have found many sources pointing to this package but I am having issues when running the go get command. Here are the steps I have taken so far:

  1. Downloaded the source for PortAudio
  2. Followed the instructions found here: https://github.com/PortAudio/portaudio/wiki/Notes_about_building_PortAudio_with_MinGW
  3. Added my PortAudio path to my PKG_CONFIG_PATH environment variable
  4. Run go get github.com/gordonklaus/portaudio

When I run the final command I get this error:

# github.com/gordonklaus/portaudio
C:\Users\user\go\pkg\mod\github.com\gordonklaus\[email protected]\portaudio.go:16:10: fatal error: portaudio.h: No such file or directory
   16 | #include <portaudio.h>
      |          ^~~~~~~~~~~~~
compilation terminated.

When looking at the file mentioned here I find that line 16 is contained in a multi line comment, so the fact that it is complaining makes no sense to me. Is there something that I have done wrong?

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.