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

2011-03-17 Thread stephen barncard
this is part two

I found the below PHP code online that seemed appropriate and tried to
convert it to Livecode but it didn't return useful values.

(not sure if I needed [$num = bindec($bin);] - turns number into string?)


/*

-- original PHP version found online and not tested in PHP

function _bin8dec($bin) {

// function to convert 8bit binary numbers to integers using two's
complement

$num = bindec($bin);

if($num  0xFF) { return false; }

if($num = 0x80) {

return -(($num ^ 0xFF)+1);

} else {

return $num;

}

} ?


*/


function bin8dec pBinary

  // does not crash, but returns useless values

  // function to convert 8bit binary numbers to integers using two's
complement

  --   [  $num = bindec($bin);   ]  not needed - php for convert to
string ?

  if pBinary  0xFF then return false

  if pBinary = 0x80

  then

return -(( pBinary ^ 0xFF)+1);

  else

return pBinary

  end if

end bin8dec


thanks in advance for any help..


sqb


On 17 March 2011 12:00, stephen barncard stephenrevoluti...@barncard.comwrote:

 This isn't that long a message but it appears I've pushed the limit.
 THis is part one.


Stephen Barncard
San Francisco Ca. USA

more about sqb  http://www.google.com/profiles/sbarncar
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


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

2011-03-17 Thread Paul D. DeRocco
 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.)
 
  80 7F 7F 7F 7E 7E 7E 7D 7D 7C 7C 7B 7B 7B 7A 7A
 0010 79 79 78 78 78 78 78 77 77 77 77 77 77 77 77 77
 0020 77 78 78 78 78 79 7A 7A 7B 7B 7C 7D 7D 7E 7F 80
 0030 81 81 83 83 84 85 86 87 88 89 8A 8B 8C 8C 8C 8E
 0040 8E 8F 90 90 90 91 91 91 92 91 91 91 92 91 91 90
 0050 90 90 8E 8E 8D 8C 8B 8A 89 88 87 85 84 83 81 80
 0060 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:
 
  00 FF FF FF FE FE FE FD FD FC FC FB FB FB FA FA
 0010 F9 F9 F8 F8 F8 F8 F8 F7 F7 F7 F7 F7 F7 F7 F7 F7
 0020 F7 F8 F8 F8 F8 F9 FA FA FB FB FC FD FD FE FF 00
 0030 01 01 03 03 04 05 06 07 08 09 0A 0B 0C 0C 0C 0E
 0040 0E 0F 10 10 10 11 11 11 12 11 11 11 12 11 11 10
 0050 10 10 0E 0E 0D 0C 0B 0A 09 08 07 05 04 03 01 00
 0060 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
Paulmailto:pdero...@ix.netcom.com 


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


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

2011-03-17 Thread stephen barncard
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 pdero...@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.)
 
   80 7F 7F 7F 7E 7E 7E 7D 7D 7C 7C 7B 7B 7B 7A 7A
  0010 79 79 78 78 78 78 78 77 77 77 77 77 77 77 77 77
  0020 77 78 78 78 78 79 7A 7A 7B 7B 7C 7D 7D 7E 7F 80
  0030 81 81 83 83 84 85 86 87 88 89 8A 8B 8C 8C 8C 8E
  0040 8E 8F 90 90 90 91 91 91 92 91 91 91 92 91 91 90
  0050 90 90 8E 8E 8D 8C 8B 8A 89 88 87 85 84 83 81 80
  0060 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:
 
   00 FF FF FF FE FE FE FD FD FC FC FB FB FB FA FA
  0010 F9 F9 F8 F8 F8 F8 F8 F7 F7 F7 F7 F7 F7 F7 F7 F7
  0020 F7 F8 F8 F8 F8 F9 FA FA FB FB FC FD FD FE FF 00
  0030 01 01 03 03 04 05 06 07 08 09 0A 0B 0C 0C 0C 0E
  0040 0E 0F 10 10 10 11 11 11 12 11 11 11 12 11 11 10
  0050 10 10 0E 0E 0D 0C 0B 0A 09 08 07 05 04 03 01 00
  0060 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
 Paulmailto:pdero...@ix.netcom.com


 ___
 use-livecode mailing list
 use-livecode@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
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode