Use []byte instead of unsafe.Pointer
This commit is contained in:
parent
0206cd3cd6
commit
6fc955d098
3 changed files with 13 additions and 12 deletions
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"math"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
@ -48,7 +47,7 @@ func main() {
|
|||
numSamples = samplesLeft
|
||||
}
|
||||
|
||||
raylib.UpdateAudioStream(stream, unsafe.Pointer(&data[totalSamples-samplesLeft]), numSamples)
|
||||
raylib.UpdateAudioStream(stream, data[totalSamples-samplesLeft:], numSamples)
|
||||
|
||||
samplesLeft -= numSamples
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ type Wave struct {
|
|||
// Number of channels (1-mono, 2-stereo)
|
||||
Channels uint32
|
||||
// Buffer data pointer
|
||||
Data unsafe.Pointer
|
||||
data unsafe.Pointer
|
||||
}
|
||||
|
||||
func (w *Wave) cptr() *C.Wave {
|
||||
|
@ -31,8 +31,9 @@ func (w *Wave) cptr() *C.Wave {
|
|||
}
|
||||
|
||||
// NewWave - Returns new Wave
|
||||
func NewWave(sampleCount, sampleRate, sampleSize, channels uint32, data unsafe.Pointer) Wave {
|
||||
return Wave{sampleCount, sampleRate, sampleSize, channels, data}
|
||||
func NewWave(sampleCount, sampleRate, sampleSize, channels uint32, data []byte) Wave {
|
||||
d := unsafe.Pointer(&data[0])
|
||||
return Wave{sampleCount, sampleRate, sampleSize, channels, d}
|
||||
}
|
||||
|
||||
// newWaveFromPointer - Returns new Wave from pointer
|
||||
|
@ -172,9 +173,9 @@ func LoadSoundFromWave(wave Wave) Sound {
|
|||
}
|
||||
|
||||
// UpdateSound - Update sound buffer with new data
|
||||
func UpdateSound(sound Sound, data unsafe.Pointer, samplesCount int32) {
|
||||
func UpdateSound(sound Sound, data []byte, samplesCount int32) {
|
||||
csound := sound.cptr()
|
||||
cdata := (unsafe.Pointer)(unsafe.Pointer(data))
|
||||
cdata := unsafe.Pointer(&data[0])
|
||||
csamplesCount := (C.int)(samplesCount)
|
||||
C.UpdateSound(*csound, cdata, csamplesCount)
|
||||
}
|
||||
|
@ -378,9 +379,9 @@ func InitAudioStream(sampleRate uint32, sampleSize uint32, channels uint32) Audi
|
|||
}
|
||||
|
||||
// UpdateAudioStream - Update audio stream buffers with data
|
||||
func UpdateAudioStream(stream AudioStream, data unsafe.Pointer, samplesCount int32) {
|
||||
func UpdateAudioStream(stream AudioStream, data []float32, samplesCount int32) {
|
||||
cstream := stream.cptr()
|
||||
cdata := (unsafe.Pointer)(unsafe.Pointer(data))
|
||||
cdata := unsafe.Pointer(&data[0])
|
||||
csamplesCount := (C.int)(samplesCount)
|
||||
C.UpdateAudioStream(*cstream, cdata, csamplesCount)
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ const (
|
|||
// NOTE: Data stored in CPU memory (RAM)
|
||||
type Image struct {
|
||||
// Image raw data
|
||||
Data unsafe.Pointer
|
||||
data unsafe.Pointer
|
||||
// Image base width
|
||||
Width int32
|
||||
// Image base height
|
||||
|
@ -118,8 +118,9 @@ func (i *Image) ToImage() image.Image {
|
|||
}
|
||||
|
||||
// NewImage - Returns new Image
|
||||
func NewImage(data unsafe.Pointer, width, height, mipmaps int32, format TextureFormat) *Image {
|
||||
return &Image{data, width, height, mipmaps, format}
|
||||
func NewImage(data []byte, width, height, mipmaps int32, format TextureFormat) *Image {
|
||||
d := unsafe.Pointer(&data[0])
|
||||
return &Image{d, width, height, mipmaps, format}
|
||||
}
|
||||
|
||||
// newImageFromPointer - Returns new Image from pointer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue