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"; }