-
-
Save akaroot/bd040d722bd2fd2bb5e42c80bb35243c to your computer and use it in GitHub Desktop.
example code for go-sox issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fatal error: unexpected signal during runtime execution | |
[signal SIGSEGV: segmentation violation code=0x1 addr=0x7ff4e39978c0 pc=0x7ff4e39978c0] | |
runtime stack: | |
runtime.throw(0x6b2a8e, 0x2a) | |
/usr/local/go/goroot/src/runtime/panic.go:619 +0x81 | |
runtime.sigpanic() | |
/usr/local/go/goroot/src/runtime/signal_unix.go:372 +0x28e | |
goroutine 5 [syscall]: | |
runtime.cgocall(0x6137a0, 0xc42005ba88, 0xc42005ba90) | |
/usr/local/go/goroot/src/runtime/cgocall.go:128 +0x64 fp=0xc42005ba58 sp=0xc42005ba20 pc=0x4046e4 | |
github.com/krig/go-sox._Cfunc_sox_open_read(0x7ff4d40008c0, 0x0, 0x0, 0x0, 0x0) | |
_cgo_gotypes.go:791 +0x4e fp=0xc42005ba88 sp=0xc42005ba58 pc=0x46801e | |
github.com/krig/go-sox.OpenRead0.func1(0x7ff4d40008c0, 0x0, 0x0, 0x0, 0xc420064218) | |
/home/akaroot/go/src/github.com/krig/go-sox/sox.go:377 +0x74 fp=0xc42005bac0 sp=0xc42005ba88 pc=0x469334 | |
github.com/krig/go-sox.OpenRead0(0x6aa1e2, 0xf, 0x0, 0x0, 0x0, 0x0, 0x4000105) | |
/home/akaroot/go/src/github.com/krig/go-sox/sox.go:377 +0xbe fp=0xc42005bb10 sp=0xc42005bac0 pc=0x46884e | |
github.com/krig/go-sox.OpenRead(0x6aa1e2, 0xf, 0xa18b40) | |
/home/akaroot/go/src/github.com/krig/go-sox/sox.go:366 +0x42 fp=0xc42005bb58 sp=0xc42005bb10 pc=0x468772 | |
main.convert(0x6aa1e2, 0xf, 0x6aab98, 0x11, 0x40e5888000000000, 0x1, 0x0, 0x0) | |
/home/akaroot/go/src/akaroot/voice-test/main.go:37 +0x63 fp=0xc42005bc70 sp=0xc42005bb58 pc=0x6127f3 | |
main.handler(0x6dc520, 0xc4201120e0, 0xc420110100) | |
/home/akaroot/go/src/akaroot/voice-test/main.go:29 +0x97 fp=0xc42005bcf0 sp=0xc42005bc70 pc=0x612697 | |
net/http.HandlerFunc.ServeHTTP(0x6bad30, 0x6dc520, 0xc4201120e0, 0xc420110100) | |
/usr/local/go/goroot/src/net/http/server.go:1947 +0x44 fp=0xc42005bd18 sp=0xc42005bcf0 pc=0x5ed5c4 | |
net/http.(*ServeMux).ServeHTTP(0xa18b40, 0x6dc520, 0xc4201120e0, 0xc420110100) | |
/usr/local/go/goroot/src/net/http/server.go:2337 +0x130 fp=0xc42005bd58 sp=0xc42005bd18 pc=0x5ef230 | |
net/http.serverHandler.ServeHTTP(0xc42007cdd0, 0x6dc520, 0xc4201120e0, 0xc420110100) | |
/usr/local/go/goroot/src/net/http/server.go:2694 +0xbc fp=0xc42005bd88 sp=0xc42005bd58 pc=0x5efd3c | |
net/http.(*conn).serve(0xc420088780, 0x6dc6e0, 0xc420064280) | |
/usr/local/go/goroot/src/net/http/server.go:1830 +0x651 fp=0xc42005bfc8 sp=0xc42005bd88 pc=0x5ec7d1 | |
runtime.goexit() | |
/usr/local/go/goroot/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc42005bfd0 sp=0xc42005bfc8 pc=0x458051 | |
created by net/http.(*Server).Serve | |
/usr/local/go/goroot/src/net/http/server.go:2795 +0x27b | |
goroutine 1 [IO wait]: | |
internal/poll.runtime_pollWait(0x7ff4e773ff00, 0x72, 0x0) | |
/usr/local/go/goroot/src/runtime/netpoll.go:173 +0x57 | |
internal/poll.(*pollDesc).wait(0xc420108018, 0x72, 0xc420064000, 0x0, 0x0) | |
/usr/local/go/goroot/src/internal/poll/fd_poll_runtime.go:85 +0x9b | |
internal/poll.(*pollDesc).waitRead(0xc420108018, 0xffffffffffffff00, 0x0, 0x0) | |
/usr/local/go/goroot/src/internal/poll/fd_poll_runtime.go:90 +0x3d | |
internal/poll.(*FD).Accept(0xc420108000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) | |
/usr/local/go/goroot/src/internal/poll/fd_unix.go:372 +0x1a8 | |
net.(*netFD).accept(0xc420108000, 0xc420088800, 0xc420059d88, 0x404208) | |
/usr/local/go/goroot/src/net/fd_unix.go:238 +0x42 | |
net.(*TCPListener).accept(0xc42000e038, 0xc420059db8, 0x403167, 0xc420088800) | |
/usr/local/go/goroot/src/net/tcpsock_posix.go:136 +0x2e | |
net.(*TCPListener).AcceptTCP(0xc42000e038, 0xc420059e00, 0xc420059e08, 0x18) | |
/usr/local/go/goroot/src/net/tcpsock.go:246 +0x49 | |
net/http.tcpKeepAliveListener.Accept(0xc42000e038, 0x6baec8, 0xc420088780, 0x6dc7a0, 0xc42007adb0) | |
/usr/local/go/goroot/src/net/http/server.go:3216 +0x2f | |
net/http.(*Server).Serve(0xc42007cdd0, 0x6dc620, 0xc42000e038, 0x0, 0x0) | |
/usr/local/go/goroot/src/net/http/server.go:2770 +0x1a5 | |
net/http.(*Server).ListenAndServe(0xc42007cdd0, 0xc42007cdd0, 0x6bad30) | |
/usr/local/go/goroot/src/net/http/server.go:2711 +0xa9 | |
net/http.ListenAndServe(0x6a7d5d, 0x5, 0x0, 0x0, 0xc42007a840, 0x0) | |
/usr/local/go/goroot/src/net/http/server.go:2969 +0x7a | |
main.main() | |
/home/akaroot/go/src/akaroot/voice-test/main.go:16 +0x67 | |
goroutine 7 [IO wait]: | |
internal/poll.runtime_pollWait(0x7ff4e773fe30, 0x72, 0xc420035e58) | |
/usr/local/go/goroot/src/runtime/netpoll.go:173 +0x57 | |
internal/poll.(*pollDesc).wait(0xc420108098, 0x72, 0xffffffffffffff00, 0x6da720, 0x9ed2e0) | |
/usr/local/go/goroot/src/internal/poll/fd_poll_runtime.go:85 +0x9b | |
internal/poll.(*pollDesc).waitRead(0xc420108098, 0xc42007ae00, 0x1, 0x1) | |
/usr/local/go/goroot/src/internal/poll/fd_poll_runtime.go:90 +0x3d | |
internal/poll.(*FD).Read(0xc420108080, 0xc42007aee1, 0x1, 0x1, 0x0, 0x0, 0x0) | |
/usr/local/go/goroot/src/internal/poll/fd_unix.go:157 +0x17d | |
net.(*netFD).Read(0xc420108080, 0xc42007aee1, 0x1, 0x1, 0xc420068000, 0x0, 0xc420064318) | |
/usr/local/go/goroot/src/net/fd_unix.go:202 +0x4f | |
net.(*conn).Read(0xc42000e048, 0xc42007aee1, 0x1, 0x1, 0x0, 0x0, 0x0) | |
/usr/local/go/goroot/src/net/net.go:176 +0x6a | |
net/http.(*connReader).backgroundRead(0xc42007aed0) | |
/usr/local/go/goroot/src/net/http/server.go:668 +0x5a | |
created by net/http.(*connReader).startBackgroundRead | |
/usr/local/go/goroot/src/net/http/server.go:664 +0xce | |
exit status 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/krig/go-sox" | |
"log" | |
"net/http" | |
"fmt" | |
) | |
const MaxSamples = 2048 | |
var samples [MaxSamples]sox.Sample | |
func main() { | |
http.HandleFunc("/", handler) // set router | |
err := http.ListenAndServe(":9090", nil) // set listen port | |
if err != nil { | |
log.Fatal("ListenAndServe: ", err) | |
} | |
} | |
func handler(w http.ResponseWriter, r *http.Request){ | |
if !sox.Init() { | |
log.Fatal("Failed to initialize SoX") | |
} | |
defer sox.Quit() | |
err := convert("input/input.jpg","output/output.wav", 44100, sox.ENCODING_SIGN2) | |
if err != nil { | |
log.Println(err.Error()) | |
} | |
} | |
func convert(inputFilePath, outputFilePath string, rate float64, encoding int) error { | |
audioInput := sox.OpenRead(inputFilePath) | |
if audioInput == nil { | |
return fmt.Errorf("failed to open input file %s", inputFilePath) | |
} | |
defer audioInput.Release() | |
// Set up the memory buffer for writing | |
outputSignal := sox.NewSignalInfo(rate, 1, 0, 0, nil) | |
outputEncoding := sox.NewEncodingInfo(encoding, uint(0), float64(0), false) | |
out := sox.OpenWrite(outputFilePath, outputSignal, outputEncoding, nil) | |
if out == nil { | |
return fmt.Errorf("failed to open output file for writing %s", outputFilePath) | |
} | |
defer out.Release() | |
// Create an effects chain: Some effects need to know about the | |
// input or output encoding so we provide that information here. | |
chain := sox.CreateEffectsChain(audioInput.Encoding(), out.Encoding()) | |
// Make sure to clean up! | |
defer chain.Release() | |
interm_signal := audioInput.Signal().Copy() | |
e := sox.CreateEffect(sox.FindEffect("input")) | |
e.Options(audioInput) | |
chain.Add(e, interm_signal, audioInput.Signal()) | |
e.Release() | |
if audioInput.Signal().Rate() != out.Signal().Rate() { | |
e = sox.CreateEffect(sox.FindEffect("rate")) | |
e.Options() | |
chain.Add(e, interm_signal, out.Signal()) | |
e.Release() | |
} | |
if audioInput.Signal().Channels() != out.Signal().Channels() { | |
e = sox.CreateEffect(sox.FindEffect("channels")) | |
e.Options() | |
chain.Add(e, interm_signal, out.Signal()) | |
e.Release() | |
} | |
// The last effect audioInput the effect chain must be something that only consumes | |
// samples; audioInput this case, we use the built-audioInput handler that outputs data. | |
e = sox.CreateEffect(sox.FindEffect("output")) | |
e.Options(out) | |
chain.Add(e, interm_signal, audioInput.Signal()) | |
e.Release() | |
// Flow samples through the effects processing chain until EOF is reached. | |
chain.Flow() | |
flow(audioInput, out, samples[:]) | |
return nil | |
} | |
// Flow data from in to out via the samples buffer | |
func flow(in, out *sox.Format, samples []sox.Sample) { | |
n := uint(len(samples)) | |
for numberRead := in.Read(samples, n); numberRead > 0; numberRead = in.Read(samples, n) { | |
out.Write(samples, uint(numberRead)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment