The following pure Perl code runs at least 2000 times faster than required to just keep up with one 1200 baud midi channel in one direction. Possibly fast enough?

use strict; use warnings; use Benchmark qw(cmpthese); my @data28 = map {int (rand () * 256)} 1..28; printf "%02x ", $_ for @data28; print "\n"; my @xlate = thereAndBack (@data28); printf "%02x ", $_ for @xlate; print "\n\n"; my @data280 = map {int (rand () * 256)} 1..280; my @data2800 = map {int (rand () * 256)} 1..2800; cmpthese (-1, { data28 => sub {thereAndBack (@data28)}, data280 => sub {thereAndBack (@data280)}, data2800 => sub {thereAndBack (@data2800)}, } ); sub thereAndBack { return fromKarma (toKarma (@_)); } sub toKarma { die "Blocks must be multiples of 8 bytes" if @_ % 7; my @raw = @_; my @karma; while (@raw) { my @block = splice @raw, 0, 7; my $extra = 0; for my $byte (@block) { $extra |= $byte & 0x80; $byte &= 0x7F; $extra >>= 1; } push @karma, ($extra, @block); } return @karma; } sub fromKarma { die "Blocks must be multiples of 8 bytes" if @_ % 8; my @karma = @_; my @raw; while (@karma) { my @block = splice @karma, 0, 8; my $extra = shift @block; for my $byte (reverse @block) { $extra <<= 1; $byte |= $extra & 0x80; } push @raw, @block; } return @raw; }

Prints:

37 8b a0 23 ef 46 68 f8 a1 75 71 de aa eb 0e ee 08 54 c7 77 9f 0b ee d +7 d3 f4 34 69 37 8b a0 23 ef 46 68 f8 a1 75 71 de aa eb 0e ee 08 54 c7 77 9f 0b ee d +7 d3 f4 34 69 Rate data2800 data280 data28 data2800 124/s -- -90% -98% data280 1228/s 888% -- -85% data28 8200/s 6496% 568% --

Note that there is some per packet overhead so there is some advantage in translating larger blocks.


DWIM is Perl's answer to Gödel

In reply to Re: Converting 7 & 8-bit values by GrandFather
in thread Converting 7 & 8-bit values by fluffy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.