Category: audio related
Author/Contact Info Jakob Nevalainen jakobn@operamail.com
Description: ip-phone is a test version of a perl ip telephony application. It needs lame, Audio::DSP and FIFOs "in.pcm", "out.pcm". The plan is to test it, then integrate the client and server into one app that kills its server when you want to call out(perhaps replacing it with an answering machine). And perhaps to write a GUI to it(And horror horror, a windows wersion). And a phone number servivce so you can call ppl with dynamic ips. The code can be gotten from: http://hem.fyristorg.com/jakobux/ip-phone/
"dsp":

# --
#!/usr/bin/perl
use Audio::DSP;
($buf, $chan, $fmt, $rate) = (4096, 1, 16, 8000);
$dsp = new Audio::DSP(buffer   => $buf,
                      channels => $chan,
                      format   => $fmt,
                      rate     => $rate);


$dsp->init() || die $dsp->errstr();

open(IN,"in.pcm");
open(OUT,">out.pcm");

for($i=0;$i<5;$i++){ print OUT $dsp->dread(4096); }

while(4096==read(IN,$buffer,4096)){
  print OUT $dsp->dread(4096);
  $dsp->dwrite($buffer);
}

$dsp->close();

--END dsp---

"soundc" :

#!/usr/bin/perl -w
use IO::Socket;
$host = shift(@ARGV);
$remote = IO::Socket::INET->new( Proto     => "tcp",
                                     PeerAddr  => $host,
                                     PeerPort  => "9000",
                                               );
$remote->autoflush(1);

system("./dsp &");


if($kidpid=fork()){
  open(WRITE,"|lame --decode --mp3input -f - in.pcm");
  while(4096==read($client,$buffer,4096)){
    print WRITE $buffer;
    }
    kill("TERM",$kidpid);
 
} else {
  open(READ," lame -frx -s 8000 -m m -b 8  out.pcm - |");
  for(;;){
    read(READ,$buffer2,4096);
    print $client $buffer2;
  }

}
close(READ);
close(WRITE);
close $remote;

-- END soundc ---

"soundd" :

#!/usr/bin/perl -w
use IO::Socket;
use Net::hostent;              # for OO version of gethostbyaddr

$PORT = 9000;                  # pick something not in use

$server = IO::Socket::INET->new( Proto     => 'tcp',
                                 LocalPort => $PORT,
                                 Listen    => SOMAXCONN,
                                 Reuse     => 1);

die "can't setup server" unless $server;
print "[Server $0 accepting clients]\n";
while ($client = $server->accept()) {
$client->autoflush(1);
  system("./dsp &");
  if($kidpid=fork()){
    open(WRITE,"|lame --decode --mp3input -f - in.pcm");
    while(4096==read($client,$buffer,4096)){
      print WRITE $buffer;
    }
    kill("TERM",$kidpid);
  } else {
    open(READ," lame -frx -s 8000 -m m -b 8  out.pcm - |");
    for(;;){
     read(READ,$buffer2,4096);
     print $client $buffer2;
    }
  }
  close(READ);
  close(WRITE);
  #close $client;
}

--- END soundd ---
Replies are listed 'Best First'.
Re: ip-phone
by rob_au (Abbot) on Feb 09, 2003 at 00:59 UTC
    It may be interesting to have a look at the 74-Line IP Telephone article which Lincoln D. Stein wrote for the Perl Journal which can be found here. This article has been incorporated into the recently published O'Reilly title Computer Science and Perl Programming.

     

    perl -le 'print+unpack("N",pack("B32","00000000000000000000001000101101"))'

      Thanks, read it and found some interesting other ways to use /dev/dsp
Re: ip-phone
by zentara (Cardinal) on Feb 09, 2003 at 13:39 UTC
    Instead of lame (which has possible patent problems with mp3), how about using "speex" , which is a voice optimized version of oggvorbis. speex

    I've even used speexenc to encode audio wave files, and they are half the size of comparable oggvorbis, and sound excellent.