Hi everybody... I've got an MS SideWinder Game Voice headset-mic (much unlike it's software, MS' hardware is good, although made by Logitech, Plantronics, etc..), which is really nice, and I wanted to hack together a crude "conferencing" package (just for the hell of it)... I got the little Game Voice module working, but then I found out none of my sound cards support recording under OpenBSD, so I reached a dead end there. In the meantime, here's the Game Voice... BSD users might find that the script tries to find the device name from dmesg's output... all others might have to supply the device name as a command line argument... PS. this is my first code post, so if you have any gripes, let 'em rip...
#!/usr/bin/perl use constant B1 => 4; use constant B2 => 8; use constant B3 => 16; use constant B4 => 32; use constant ALL => 1; use constant TEAM => 2; use constant COMM => 64; use constant MUTE => 128; use constant OFF => 0; my $state; my $device; if(@ARGV){ $device = $ARGV[0]; }else{ $device = "/dev/" . getDeviceName(); } sysopen(DATA, $device, O_RDONLY | O_NODELAY | O_BINARY) or die "could +not open $device!\n"; while(1){ my $buf; if(sysread(DATA, $buf, 1)){ my @ascii = map { ord } split //, $buf; foreach (@ascii){ my $code = getCode($_); print "read: $code\n"; } } } close(DATA); sub getCode{ my $code = shift; if($code == OFF){$state = OFF; return "off";} if($code == ALL){$state = ALL; return "all";} if($code == TEAM){$state = TEAM; return "team";} if($code == COMM){$state = COMM; return "command";} if($code == MUTE){$state = MUTE; return "mic mute";} my $binarystring = unpack('b*', pack("n",$code)); my @dest; if($binarystring =~ m/.*(\d)(\d)(\d)(\d)\d(\d)/){ if($5){push @dest, "mic mute";}else{ if($1){push @dest, "1";} if($2){push @dest, "2";} if($3){push @dest, "3";} if($4){push @dest, "4";} } } my $ret = ""; foreach (@dest){ $ret = $ret . $_ . " "; } $state = $code; return $ret; } sub getDeviceName{ my $uhidev = undef; my $uhid = undef; my @dmesg = `dmesg`; foreach (@dmesg){ if($_ =~ m/(.*):\sMicrosoft\sSideWinder\sGame\sVoice.*/){ $uhidev = $1; } } if($uhidev){ foreach (@dmesg){ if($_ =~ m/(.*)\sat\s$uhidev:/){ $uhid = $1; } } return $uhid; } die "could not find a GameVoice device!\n"; }

In reply to Playing with a GameVoice by kko

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.