[linux-audio-dev] command line looping

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: [linux-audio-dev] command line looping
From: Karlis (brazyl_AT_cc.baremetal.com)
Date: Sun Apr 07 2002 - 09:55:29 EEST


Looking for ideas. . .

I'm trying to find a command line audio player that will loop files.
I'm attempting to use a stripped-down laptop for playing loops while
busking. The laptop doesn't have a screen or a keyboard, just a keypad
and a sound out. The line out is hooked up to a portable amp. I just
type in 2 numbers on the keypad and it plays (loops) the corresponding
sound file.

Right now the script uses mpg123 for mp3 and ecasound for wav. ecasound
is supposed to loop with the -tl option, but doesn't seem to. mpg123
doesn't loop either. . . what's frustrating is that almost all GUI players
loop, either automatically (xmms, etc) or by command (sweep), and I can't
find anything like this in command line. ..

any help would be appreciated.

Anyway, here's the working (but klunky) script so far, in case it's useful
to someone. . .

---------------------------------------
#!/usr/bin/perl

use POSIX qw(:termios_h);

# Get ready list of audio loop files (just a text file of wav and mp3 loop
#filenames)

open(FILE,"./loops.txt");
my $i=0;my @loops;
while (<FILE>) {
        chomp;
        $loops[$i] = $_;
        $i++;
}

#read input from keyboard (thanks perlmonks for the termio code)

  my $termios = new POSIX::Termios;

  $termios->setlflag(~ICANON); # Turn off canonical mode
  $termios->setcc(VMIN, 1); # Read a min of 1 character
  $termios->setcc(VTIME, 0); # No time-out on reads
  $termios->setattr(0, TCSANOW); # Apply settings to STDIN

 
my $last;
my $buf;
WHILE: while(read(STDIN, $key, 1)) {
        if ($key =~ /^q/) {last WHILE;}
        elsif ($key =~ /\d+/) {
        $last = &killnplay($loops[$key],$last);
        }
}

$termios->finish;
  $termios->setlflag(ICANON); # Turn on canonical mode
  $termios->setattr(0, TCSANOW); # Apply settings to STDIN
exit;

###################################
sub killnplay {
my ($song,$last) = @_;
my @kill = split(/ /,$last);

#kill the last playing sample
if ($last && $kill[0]) {
        system qq~killall -9 $kill[0]~;
}

#choose a player for the file and play it, and return
if ($song =~ /\.mp3$/i) {
        $song = qq~mpg123 $song &~;
        system qq~$song~;
} elsif ($song =~ /\.wav$/i) {
        $song = qq~ecatools_play $song &~;
        system qq~$song~;
}
 
return($song);

---------------------------------------------------

cheers
karlis


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Sun Apr 07 2002 - 12:44:15 EEST