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

Incorrect conversion of Float to Int #14

Open
dh1tw opened this issue Jan 21, 2018 · 1 comment
Open

Incorrect conversion of Float to Int #14

dh1tw opened this issue Jan 21, 2018 · 1 comment

Comments

@dh1tw
Copy link

dh1tw commented Jan 21, 2018

Hi,

I tried to convert a Float32Buffer to an IntBuffer, resulting in silence. Problem is, that the current implementation has a flaw:

newB.Data[i] = int(buf.Data[i])

newB.Data[i] = int(buf.Data[i])

Float audio samples use the value range of -1....0....1 casting them just to int won't do the job. For a proper conversion, the bit depth of the integer (8/16/32/64) must be known. Here is a good stack overflow article how to do it right.

Problem is, that within a Float32Buffer, the bit depth is not available :-(

@mattetti
Copy link
Member

mattetti commented Feb 6, 2018

@dh1tw there is a transform for that https://github.com/go-audio/transforms/blob/master/pcm_scale.go#L27 It does expect that you kept around the original bit depth. you can see that the PCMBuffer uses SourceBitDepth to track that. The Float32Buffer also does have that field: https://github.com/go-audio/audio/blob/master/float_buffer.go#L85

I still do need to go and clean up the other types but I'm thinking about entirely dropping Floats and only keep float32s.

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