layeh / gopus Goto Github PK
View Code? Open in Web Editor NEWgopus is a Go binding for the Opus audio codec
License: The Unlicense
gopus is a Go binding for the Opus audio codec
License: The Unlicense
Platform: Ubuntu 22.04.3 LTS
on WSL 2.0.9.0
(Win 11
)
Go Version: go1.21.5 linux/amd64
When trying to import the gopus library I get the following error(s):
error while importing layeh.com/gopus: build constraints exclude all Go files in /home/<myuser>/go/pkg/mod/layeh.com/[email protected]
could not import layeh.com/gopus (no required module provides package "layeh.com/gopus")
Minimal code to recreate:
package main
import "layeh.com/gopus"
I've been using your package for encoding opus for a little bit and it works fantastic. I really appreciate you having wrote it :)
I've recently started trying to use it to decode opus back into PCM and I'm running into problems where the result doesn't sound right (very very choppy/skippy sounding).
So I wrote a little test program and published it here : https://github.com/bwmarrin/oencdec
With this test, I'm doing 2 channel audio and it looks like the decoder output is half the size that it should be. The program reads in 1920 int16 values, encodes to opus, then decodes to PCM and the output is only 960 int16 values.
Any change you know what I'm doing wrong or is there possibly a bug in gopus somewhere?
root@S1ROZHA:~ # go install BogdanBot/cmd/bot
work/src/BogdanBot/cmd/bot/bot.go:18:2: code in directory /root/work/src/github.com/layeh/gopus expects import "layeh.com/gopus"
root@S1ROZHA:~#
Hello,
Since the Opus library is very small, the C source can be included within the package. This way user does not need to worry about installing the opus libraries in his system.
We did the same with the GLFW library here: https://github.com/go-gl/glfw/tree/master/v3.1/glfw
Line 5 in 0ebf989
Can you add openbsd to this line for the -lm flag? It resolves a compilation error that I get on OpenBSD.
Hey there, I am using this library and encode and decode my PCM data.
I use malgo to capture and play them back. I use the int16 mode.
I've written two functions that convert []byte to []int16 like so
func bytesToInts16(data []byte) []int16 {
samples := make([]int16, len(data)/2)
for i := 0; i < len(data) / 2; i++ {
samples[i] = int16(binary.LittleEndian.Uint16(data[i*2 : i*2+2]))
}
return samples
}
func ints16ToBytes(samples []int16) []byte {
data := make([]byte, len(samples)*2)
for i := 0; i < len(samples); i++ {
binary.LittleEndian.PutUint16(data[i*2 : i*2+2], uint16(samples[i]))
}
return data
}
and my onSamples malgo function looks something like this
func onSamples(pOutputSample, pInputSamples []byte, frameCount uint32) {
buffer := bytesToInts16(pInputSamples)
data, err := compressPCM(buffer, int(frameCount))
if err != nil {
fmt.Println(err)
return
}
decoded, err := decompressOpus(data, int(frameCount))
if err != nil {
fmt.Println(err)
return
}
// Convert back to bytes
decodedBytes := ints16ToBytes(decoded)
// set them as output
copy(pOutputSample, decodedBytes)
}
while my encode and decode
func compressPCM(pcm []int16, frameCount int) ([]byte, error) {
encoder, err := gopus.NewEncoder(48000, 1, gopus.Audio)
if err != nil {
return nil, err
}
encoded, err := encoder.Encode(pcm, frameCount, 960)
if err != nil {
return nil, err
}
return encoded, nil
}
func decompressOpus(data []byte, frameCount int) ([]int16, error) {
decoder, err := gopus.NewDecoder(48000, 1)
if err != nil {
return nil, fmt.Errorf("failed to create decoder: %w", err)
}
decoded, err := decoder.Decode(data, frameCount, false)
if err != nil {
return nil, fmt.Errorf("failed to decode: %w", err)
}
return decoded, nil
}
it's a mono channel, 48000Hz samples per second.
The audio quality is just horrible, any ideas what might be wrong?
I'm working on a project using gumble and thus also gopus as a dependency but go build
fails whenever I try to import gumble/opus:
$ go build
# github.com/LeoVerto/gumble-pulseaudio/vendor/layeh.com/gopus
vendor/layeh.com/gopus/opus_nonshared.go:9:11: fatal error: opus-1.1.2/config.h: No such file or directory
// #include "opus-1.1.2/config.h"
^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
That file definitely exists and my local clone of gopus is up to date.
I'm sorry if this is something trivial, I haven't worked with Go outside of hacking on some mumble related stuff.
I was trying to install matthieugrieger/mumbledj and ran into issues when it tried to install gopus, which is listed in it's dependencies. I installing opus-1.1.2, opus-tools-0.1.9, and go-1.6.2. The C compiler is Clang 3.4.1. I don't know enough about Go to figure out what it's failing on, but here are the last few lines:
/tmp/go-build789578334/github.com/layeh/gopus/_obj/opus_nonshared.cgo2.o: In function `logSum':
.vendor/src/github.com/layeh/gopus/opus-1.1.2/src/opus_multistream_encoder.c:212: undefined reference to `floorf'
.vendor/src/github.com/layeh/gopus/opus-1.1.2/src/opus_multistream_encoder.c:212: undefined reference to `floorf'
.vendor/src/github.com/layeh/gopus/opus-1.1.2/src/opus_multistream_encoder.c:212: undefined reference to `floorf'
.vendor/src/github.com/layeh/gopus/opus-1.1.2/src/opus_multistream_encoder.c:212: undefined reference to `floorf'
/tmp/go-build789578334/github.com/layeh/gopus/_obj/opus_nonshared.cgo2.o: In function `surround_analysis':
.vendor/src/github.com/layeh/gopus/opus-1.1.2/src/opus_multistream_encoder.c:323: undefined reference to `log'
/tmp/go-build789578334/github.com/layeh/gopus/_obj/opus_nonshared.cgo2.o: In function `FLOAT2INT16':
.vendor/src/github.com/layeh/gopus/opus-1.1.2/celt/float_cast.h:136: undefined reference to `lrintf'
/tmp/go-build789578334/github.com/layeh/gopus/_obj/opus_nonshared.cgo2.o: In function `tansig_approx':
.vendor/src/github.com/layeh/gopus/opus-1.1.2/src/mlp.c:88: undefined reference to `floorf'
.vendor/src/github.com/layeh/gopus/opus-1.1.2/src/mlp.c:88: undefined reference to `floorf'
cc: error: linker command failed with exit code 1 (use -v to see invocation)
goop: Command failed with exit status 2
*** Error code 2
The output of pkg-config --cflags opus
gives -I/usr/local/include/opus
, which should mean that the Opus header files can be found, correct? There is an opus.h
in that folder. It seems a lot of the undefined references are to math functions like pow, floor, cos, log, etc. How would I know if the math library is being linked (usually done with a compiler flag of -lm
)?
I am unable to compile gopus on Windows with Go 1.6.1
$ go version
go version go1.6.1 windows/amd64
Error:
$ go get github.com/layeh/gopus
# github.com/layeh/gopus
cc1.exe: sorry, unimplemented: 64-bit mode not compiled in
Go 1.6
$ go get github.com/layeh/gopus
In file included from ../../layeh/gopus/opus_nonshared.go:68:0:
../../layeh/gopus/opus-1.1.2/silk/NLSF2A.c:41:0: warning: "QA" redefined [enabled by default]
#define QA 16
^
In file included from ../../layeh/gopus/opus_nonshared.go:66:0:
../../layeh/gopus/opus-1.1.2/silk/LPC_inv_pred_gain.c:34:0: note: this is the location of the previous definition
#define QA 24
^
In file included from ../../layeh/gopus/opus-1.1.2/celt/bands.c:41:0,
from ../../layeh/gopus/opus_nonshared.go:120:
../../layeh/gopus/opus-1.1.2/celt/mathops.h:83:0: warning: "PI" redefined [enabled by default]
#define PI 3.141592653f
^
In file included from opus-1.1.2/silk/float/main_FLP.h:31:0,
from ../../layeh/gopus/opus-1.1.2/silk/enc_API.c:41,
from ../../layeh/gopus/opus_nonshared.go:21:
opus-1.1.2/silk/float/SigProc_FLP.h:150:0: note: this is the location of the previous definition
#define PI (3.1415926536f)
^
Add custom mode.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.