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

Get raw byte buffer for OpenAL #23

Open
bergwerf opened this issue Apr 24, 2020 · 2 comments
Open

Get raw byte buffer for OpenAL #23

bergwerf opened this issue Apr 24, 2020 · 2 comments

Comments

@bergwerf
Copy link

I am trying gomobile with the OpenAL module (https://godoc.org/golang.org/x/mobile/exp/audio/al). I need to pass raw byte data, but it seems this library only provides ints and floats. Am I missing something?

@mattetti
Copy link
Member

I'm not quite sure what you mean by raw byte data, what data are we talking about? I've never used OpenAL but you can take a look at the wav encoder that write PCM data to a wav container/file. https://github.com/go-audio/wav/blob/master/encoder.go#L63

I doubt you are trying to write a wav file to an AL file descriptor but if that's the case, you can use the encoder on the file: https://github.com/go-audio/wav/blob/master/encoder.go#L41

I hope it helps,

  • Matt

@bergwerf
Copy link
Author

The gomobile OpenAL binding expects bytes where 16bit data is divided over two bytes. See: https://pkg.go.dev/golang.org/x/[email protected]/exp/audio/al?tab=doc#Buffer.BufferData

For my 16bit data I used this ad-hoc solution:

byteBuffer := make([]byte, len(intBuffer.Data)*2)
for i := 0; i < len(intBuffer.Data); i++ {
        i32 := intBuffer.Data[i]
        byteBuffer[2*i] = byte(i32)
        byteBuffer[2*i+1] = byte(i32 >> 8)
}

This particular OpenAL bindings appears to only support 8 and 16bit data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants