You could easily clean this code up.
You could easily make it much shorter and/or faster

I just ignored corner cases, error checking, and other cases that probably don't matter to you.
I just ignored negative numbers !!!

and with all those caveats, try this in your msg box

put "400EAC44000000000000" into hexstring

repeat with i = 1 to 20
  if char i of hexstring is not a number then
     put 10 + chartonum(char i of hexstring) - chartonum("A") into t
     -- put char i of hexstring && t & CR after msg
    put t into v[i]
 else
   put char i of hexstring into v[i]
end if
end repeat


put 0 into t
repeat with i=1 to 4
  put t*16 + v[i] into t
  -- put i && v[i] && t & CR after msg
end repeat
put t into texp

put 0 into t
repeat with i = 5 to 12
  put t*16 + v[i] into t
end repeat
put t into mantissa

put texp && mantissa && mantissa & CR after msg
put texp - 16383 into texp
put mantissa * 2^(texp-31) after msg

Oh, by the way, I also ignored the lower half of the mantissa - i.e. extra precision. That probably doesn't matter for the kind of numbers you'll see for sample rates, etc.

-- Alex.

On 05/02/2011 03:01, stephen barncard wrote:
Still messing with exporting sounds out of Livecode. Working with AIF
files for now.

I can't yet find where Livecode stores the metadata like length,
sample rate and bit depth for imported sound files.

In the meantime, I can grab these values from the incoming aif files
and store them in custom properties ins the soundclip object.

The aiff sample rate is defined in 10 hex bytes of Extended 80-bit
floating point, like so: (big endian)

44100  =

40 0E AC 44 00 00 00 00 00 00<http://www.onicos.com/staff/iz/formats/ieee.c>

48000   =

40 0E BB 80 00 00 00 00 00 00<http://www.onicos.com/staff/iz/formats/ieee.c>

96000   =

40 0F BB 80 00 00 00 00 00 00
  <http://www.onicos.com/staff/iz/formats/ieee.c>

Extended 80-bit floating-point format
<http://www.onicos.com/staff/iz/formats/ieee.c>


I could use some help here.. I want to detect other sample rates. The ones
above were determined by examining them in sound files with known rates.

How would I convert these 80 bit hex floating point numbers to the values
shown and back again?. Baseconvert doesn't work with this many hex
characters. (linked is some C source...)
surely this can be done in Livecode...

thanks in advance...



_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to