当前位置:网站首页>Golang calls sdl2, plays PCM audio, and reports an error signal arrived during external code execution.
Golang calls sdl2, plays PCM audio, and reports an error signal arrived during external code execution.
2022-06-22 06:52:00 【Fuda scaffold constructor's daily question】
golang call sdl2, Play pcm Audio , Report errors signal arrived during external code execution.
win10 x64 The next test was successful , Success is not guaranteed under other operating systems .
It's using syscall The way , No cgo The way .
See address
stay go1.16.15 Compile and execute , The following error will be reported . Switch to go1.18 I won't make a mistake .
Exception 0xc0000005 0x0 0xc000442000 0x7ff96da8db50
PC=0x7ff96da8db50
signal arrived during external code execution
syscall.Syscall6(0x7ff96daa7440, 0x4, 0x20d6354a0a0, 0xc000442000, 0x1000, 0x10, 0x0, 0x0, 0x0, 0x0, …)
D:/Program Files/Go/go1.16.15/src/runtime/syscall_windows.go:347 +0xf2
syscall.(*Proc).Call(0xc000599b40, 0xc0001207c0, 0x4, 0x4, 0x20, 0xa6ffa0, 0x20d6354a001, 0xc0001207c0)
D:/Program Files/Go/go1.16.15/src/syscall/dll_windows.go:188 +0x385
syscall.(*LazyProc).Call(0xc00007fc50, 0xc0001207c0, 0x4, 0x4, 0x3, 0x3, 0x20d6354a0a0, 0x0)
D:/Program Files/Go/go1.16.15/src/syscall/dll_windows.go:339 +0x78
github.com/moonfdd/sdl2-go/sdl.SDL_MixAudio(0x20d6354a0a0, 0xc000442000, 0x1000001000)
D:/mysetup/gopath/src/sdl2-go/sdl/SDL_audio.go:1185 +0xf1
main.fill_audio_pcm(0xc00010ff48, 0x20d6354a0a0, 0x1000, 0x0)
D:/mysetup/gopath/src/sdl2-go/examples/a06-sdl-pcm/main1.go:33 +0x125
goroutine 1 [chan receive]:
main.main()
D:/mysetup/gopath/src/sdl2-go/examples/a06-sdl-pcm/main1.go:66 +0x288
rax 0x20d6354a0a0
rbx 0xc0000086e0
rcx 0x20d6354a0a0
rdi 0xecaa4c3000
rsi 0xc0000439c0
rbp 0xc000043960
rsp 0xecabbffb50
r8 0x8010
r9 0x20d6354b0a0
r10 0x10
r11 0x4
r12 0xa7b800
r13 0x0
r14 0x0
r15 0x2030001
rip 0x7ff96da8db50
rflags 0x10206
cs 0x33
fs 0x53
gs 0x2b
golang The code is as follows :
package main
import (
"fmt"
"github.com/moonfdd/sdl2-go/sdl"
"github.com/moonfdd/sdl2-go/sdlcommon"
"io/ioutil"
"sync"
"syscall"
"unsafe"
)
var o sync.Once
// Audio device callback function
func fill_audio_pcm(udata sdlcommon.FVoidP, stream *sdlcommon.FUint8T, len1 sdlcommon.FInt) uintptr {
info := (*Info)(unsafe.Pointer(udata))
if info.isStop {
return 0
}
if info.Start >= info.Len {
info.isStop = true
o.Do(func() {
ch <- struct{
}{
}
})
return 0
}
sdl.SDL_memset(uintptr(unsafe.Pointer(stream)), 0, uint64(len1))
if len1 > int32(info.Len-info.Start) {
fmt.Println(" Insufficient len", len1, info.Len-info.Start)
len1 = int32(info.Len - info.Start)
}
sdl.SDL_MixAudio(stream, &info.Data[info.Start], uint32(len1), sdl.SDL_MIX_MAXVOLUME/8)
info.Start += int(len1)
return 0
}
var ch = make(chan struct{
}, 1)
func main() {
sdlcommon.SetSDL2Path("SDL2.dll")
var spec sdl.SDL_AudioSpec
sdl.SDL_Init(sdl.SDL_INIT_AUDIO)
spec.Freq = 44100
spec.Format = sdl.AUDIO_S16SYS // Sample point format
spec.Channels = 2 // 2 passageway
spec.Silence = 0
spec.Userdata = uintptr(0)
spec.Samples = 1024 // 23.2ms -> 46.4ms Number of samples per read , How often a callback and samples
spec.Callback = syscall.NewCallback(fill_audio_pcm) // Callback function
fileData, err := ioutil.ReadFile("44100_16bit_2ch.pcm")
if err != nil {
fmt.Println(" Failed to read file ", err)
return
}
info := new(Info)
info.Data = fileData
info.Len = len(fileData)
spec.Userdata = uintptr(unsafe.Pointer(info))
if sdl.SDL_OpenAudio(&spec, nil) != 0 {
fmt.Println(" Failed to open audio device ")
return
}
sdl.SDL_PauseAudio(0)
<-ch
fmt.Println(" close ")
sdl.SDL_CloseAudio()
sdl.SDL_Quit()
}
type Info struct {
Data []byte
Len int
Start int
isStop bool
}
The results are as follows :
边栏推荐
- golang調用sdl2,播放pcm音頻,報錯signal arrived during external code execution。
- MySQL ifnull processing n/a
- Introduction to 51 single chip microcomputer - LED light
- [5g NR] UE registration management status
- 2022-06-21:golang选择题,以下golang代码输出什么?A:3;B:4;C:100;D:编译失败。 package main import ( “fmt“ ) func
- KV260的PMOD接口介绍
- 【openairinterface5g】项目目录结构
- ERROR: cannot verify nih. At's certificate, issued by "/c=us/o=let's encrypt/cn=r3", WGet reports an error
- 6. install the SSH connection tool (used to connect the server of our lab)
- PIP for source changing and accelerated downloading
猜你喜欢
![[openairinterface5g] rrcsetuprequest for RRC NR resolution](/img/de/34e71154941f977546362f10a19929.jpg)
[openairinterface5g] rrcsetuprequest for RRC NR resolution

6. 安装ssh连接工具(用于我们连接实验室的服务器)
![[5g NR] ng setup of ngap protocol](/img/aa/bbe4b345374d2cf2ab3bfde5e94d7c.png)
[5g NR] ng setup of ngap protocol

5g-guti detailed explanation

golang調用sdl2,播放pcm音頻,報錯signal arrived during external code execution。

2022-06-21:golang选择题,以下golang代码输出什么?A:3;B:4;C:100;D:编译失败。 package main import ( “fmt“ ) func

SQL injection vulnerability (XII) cookie injection

OpenGL - Draw Triangle

ForkJoinPool

Leetcode the shortest path of three (eight) charts per week
随机推荐
-Bash: telnet: command not found solution
Anaconda introduction, installation and use nanny level tutorial
MySQL Niuke brush questions
Introduction to 51 Single Chip Microcomputer -- the use of Proteus 8 professional
Test ofnatural clusters via s-dbscan a self tuning version of DBSCAN
仙人掌之歌——进军To C直播(3)
C技能树评测——用户至上做精品
QT connect to Alibaba cloud using mqtt protocol
一个算子在深度学习框架中的旅程
安装boost
六月集训(第22天) —— 有序集合
Training penetration range 02 | 3-star VH LLL target | vulnhub range node1
How to learn 32-bit MCU
JS中对数组进行去重的几种方法
Chrome 安装 driver
5G终端标识SUPI,SUCI及IMSI解析
Using Monte Carlo method to calculate pi
iframe框架,,原生js路由
[M32] single chip microcomputer SVN setting ignore file
2021-05-12