arrays - Unpacking 3-byte/24-bit data chunks with Ruby -


I'm building a pure-ruby WAV file / writing library, I'm learning Ruby Ruby's functionality . It currently works well with 16-bit audio, because I use the string String.unpack ('s *') to draw individual audio samples into the array of signed integers I am capable of wrapping my mind about dealing with 24-bit audio, yet in that case every sample is 3 bytes long. In that case, you would suggest packets / unpack strings, and would I like to change my attitude (using padding or something like that) a lot?

As you used unpack ("s +") , I believe that your sample is in large Andian. Here's a very fast but not practical solution.

  & gt; & Gt; "ABCDEF" .scan (/.../) Map {| S | | (S.reverse + 0.chr). Unpack ("V")} Flatine = & gt; [4276803, 4474182] # = & gt; [0x414243, 0x444546]  
in hex

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -