Page 1 of 1
build wave mem array
Posted: Tue Jan 06, 2015 5:59 pm
by Logado
Hi everyone, i am new to DSP programming.
Try to read wave data and build memory array like this.

i used ruby lib
https://github.com/jstrait/wavefile from load wave data.
Now i have this values

FS get values like like
0.000946
0.007080
0.001190
ruby values differ too much

i dont understand how convert, please help
ps. sorry from my english.
Re: build wave mem array
Posted: Tue Jan 06, 2015 7:09 pm
by KG_is_back
Flowstone internally uses 32bit float representation. In this format, wave is made of decimal values in <-1,1> range.
You have apparently loaded file that is in integer format. To convert from integer to float, all you have to do is to divide the value by the maximal size in that format. For 24bit int that is 2^23 = 8 388 608.
As you can see 7936/ 8 388 608 = 0.000946
When you are doing this in ruby, make sure ruby is doing the math in float numbers - not integers, because you'll get zeros all the time.
Re: build wave mem array
Posted: Tue Jan 06, 2015 7:25 pm
by MyCo
Use this from the Lib-examples... it should do the conversion internally
Code: Select all
# Sample data will be returned as 32-bit floating point samples,
# regardless of the actual sample format in the file.
Reader.new("some_file.wav", Format.new(:mono, :float_32, 44100))
Re: build wave mem array
Posted: Tue Jan 06, 2015 8:14 pm
by Logado
Thanks for the detailed
Re: build wave mem array
Posted: Thu Jan 08, 2015 1:47 pm
by Logado
new problem. I now have the correct array but sound wrong.
Why this

and this

gives a different sound

Re: build wave mem array
Posted: Thu Jan 08, 2015 4:05 pm
by KG_is_back
float array to mem creates a mono wave file. mem to float array simply lists the samples in succession. If the file is stereo, then the array will be consisted of left and right channel values next to each other - giving twice as long float array as the original file was.