build wave mem array

For general discussion related FlowStone
Post Reply
Logado
Posts: 62
Joined: Tue Jan 06, 2015 5:42 pm

build wave mem array

Post by Logado »

Hi everyone, i am new to DSP programming.
Try to read wave data and build memory array like this.
Image
i used ruby lib https://github.com/jstrait/wavefile from load wave data.
Now i have this values
Image

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.
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: build wave mem array

Post 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.
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: build wave mem array

Post 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))
Logado
Posts: 62
Joined: Tue Jan 06, 2015 5:42 pm

Re: build wave mem array

Post by Logado »

Thanks for the detailed
Logado
Posts: 62
Joined: Tue Jan 06, 2015 5:42 pm

Re: build wave mem array

Post by Logado »

new problem. I now have the correct array but sound wrong.
Why this
Image
and this
Image
gives a different sound :?
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: build wave mem array

Post 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.
Post Reply