signed 8 bit to "sign and magnitude" handler needed [PART ONE]

stephen barncard stephenREVOLUTION2 at barncard.com
Thu Mar 17 15:41:08 EDT 2011


That's the magic formula. Looks like it could be fast too.
Thanks, Paul...



function bin8decU pBinary

      return (pBinary+ 0x80) bitAnd 0xFF

end bin8decU


function convertBlock pBlock

      repeat for each character tCH in pBlock

            put bin8decU(tCH) after tOut

      end repeat

      return tOut

end convertBlock



sqb

On 17 March 2011 12:15, Paul D. DeRocco <pderocco at ix.netcom.com> wrote:

> > From: stephen barncard
> >
> > Continuing on the "exporting aiff files from audioclips"
> > quest, I discovered that 'some' (about 10%) of the exported
> > files data would not play correctly. They sounded distorted
> > and loud at full scale. Digging in further, I discovered that
> > 8 bit AIFF files are not signed (due to their history), but
> > instead are ( I think ) "sign and magnitude" 8 bit.
> >
> > So I need to convert the data for just the 8 bit files.
> >
> > I know this is dumb ass simple, but I've been staring at
> > these numbers for too ling and need some fresh eyes. I am
> > *seeking a handler in Livecode* to convert numbers between
> > 0-255 (what I think is) two's compliment 8 bit to (what I
> > think is) "sign and magnitude" numbers between 0-255.
> >
> > that is, I need to convert a number series that looks like
> > below (word wrap is inevitable.)
> >
> > 00000000 80 7F 7F 7F 7E 7E 7E 7D 7D 7C 7C 7B 7B 7B 7A 7A
> > 00000010 79 79 78 78 78 78 78 77 77 77 77 77 77 77 77 77
> > 00000020 77 78 78 78 78 79 7A 7A 7B 7B 7C 7D 7D 7E 7F 80
> > 00000030 81 81 83 83 84 85 86 87 88 89 8A 8B 8C 8C 8C 8E
> > 00000040 8E 8F 90 90 90 91 91 91 92 91 91 91 92 91 91 90
> > 00000050 90 90 8E 8E 8D 8C 8B 8A 89 88 87 85 84 83 81 80
> > 00000060 7F 7D 7B 7A 79 77 76 75 73 72 71 6F 6F 6D 6C 6B
> >
> > (this is the same sine wave going above and below center in
> > both lists)
> >
> > to be converted to numbers that look like this:
> >
> > 00000000 00 FF FF FF FE FE FE FD FD FC FC FB FB FB FA FA
> > 00000010 F9 F9 F8 F8 F8 F8 F8 F7 F7 F7 F7 F7 F7 F7 F7 F7
> > 00000020 F7 F8 F8 F8 F8 F9 FA FA FB FB FC FD FD FE FF 00
> > 00000030 01 01 03 03 04 05 06 07 08 09 0A 0B 0C 0C 0C 0E
> > 00000040 0E 0F 10 10 10 11 11 11 12 11 11 11 12 11 11 10
> > 00000050 10 10 0E 0E 0D 0C 0B 0A 09 08 07 05 04 03 01 00
> > 00000060 FF FD FB FA F9 F7 F6 F5 F3 F2 F1 EF EF ED EC EB
> >
> > (this is a SSND chunk dump from an audio file that plays correctly.)
> >
> > (part two will show the PHP code I tried to convert but failed)
>
> Looks like offset binary to me, so x - 128 is the two's complement version.
> If you need to represent the latter as unsigned bytes, the easiest way is
> probably (x + 128) bitAnd 255.
>
> --
>
> Ciao,               Paul D. DeRocco
> Paul                mailto:pderocco at ix.netcom.com
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



-- 



Stephen Barncard
San Francisco Ca. USA

more about sqb  <http://www.google.com/profiles/sbarncar>



More information about the use-livecode mailing list