Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bunch of small fixes and improvements #29

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,17 @@ func goDataCallback(pDevice *C.ma_device, pOutput, pInput unsafe.Pointer, frameC
deviceMutex.Unlock()

if callback != nil {
inputSamples := []byte(nil)
outputSamples := []byte(nil)
var inputSamples, outputSamples []byte
if pOutput != nil {
sampleCount := uint32(frameCount) * uint32(pDevice.playback.channels)
sizeInBytes := uint32(C.ma_get_bytes_per_sample(pDevice.playback.format))
outputSamples = (*[1 << 30]byte)(pOutput)[0 : sampleCount*sizeInBytes]
outputSamples = unsafe.Slice((*byte)(pOutput), sampleCount * sizeInBytes)
}

if pInput != nil {
sampleCount := uint32(frameCount) * uint32(pDevice.capture.channels)
sizeInBytes := uint32(C.ma_get_bytes_per_sample(pDevice.capture.format))
inputSamples = (*[1 << 30]byte)(pInput)[0 : sampleCount*sizeInBytes]
inputSamples = unsafe.Slice((*byte)(pInput), sampleCount * sizeInBytes)
}

callback(outputSamples, inputSamples, uint32(frameCount))
Expand Down
5 changes: 4 additions & 1 deletion device_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ type DeviceInfo struct {

// Name returns the name of the device.
func (d *DeviceInfo) Name() string {
return string(d.name[:])
// find the first null byte in d.name
var end int
for end = 0; end < len(d.name) && d.name[end] != 0; end++ {}
return string(d.name[:end])
}

// String returns string.
Expand Down
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module github.com/gen2brain/malgo

go 1.17

require github.com/stretchr/testify v1.7.0

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading