Saturday, November 21, 2009

virtual FM tuner using shell scripting

this is the virtual fm tuner.
simple shell scripting
but, be connected to the internet
till now, i have just added Nepali FMS.
and, obviously thanks to Satyendra Raj Pandey for this FM idea.

to download the file click here

else, the code is here

#! /bin/sh
commonCommand()
{
common1='[playlist]'
common2='NumberOfEntries=1'
}
quit ()
{
clear
echo "*************************"
printf "SIMPLE FM TUNER V1.0\nDeveloped by\nPUNJ POKHAREL\npunj33@gmail.com\npunj33.blogspot.com\n*************************\n\n"
printf "\nPlease feel free to edit, distribute and contribute. Its totally open source\n\n"
printf "It can be made a whole lot better. So, share your ideas\n\n"
echo "THANK YOU FOR USING SIMPLE FM TUNER V1.0"
printf "\n\n"
echo "Press any Enter to exit"
read nothing
# i tried to kill extracting PID but kill the whole totem seems easy
# a=`ps -ef|grep 'totem fm.log'|grep -v 'grep'`
# b=`echo $a|awk '{print $3}'
# kill -9 totem

if [ $counter -ge 1 ]
then
killall vlc 2> /dev/null
else
killall totem 2> /dev/null
fi
clear
break;
}
choose()
{
case $choice in
1)fm='File1=http://67.202.67.18:8208/;stream.mp3ls';;
2)fm='File1=mms://64.62.166.162/hitsfm';;
3)fm='File1=mms://64.62.166.162/ujyaalofm';;
4)fm='File1=mms://64.62.166.162/sagarmatha_fm' ;;
5)fm='File1=mms://64.62.166.162/nepalfm' ;;
6)fm='File1=mms://64.62.166.162/maitrifm';;
7)quit ;;
esac
}
tune()
{
printf "$common1\n$common2\n$fm" > fm.log
counter=`whatis cvlc|grep 1|wc -l`
if [ $counter -ge 1 ]
then
killall vlc 2> /dev/null &
cvlc fm.log 2> /dev/null &
else
totem fm.log 2> /dev/null &
fi
printf "TUNING "
for i in 1 2 3 4 5
do
printf "."
sleep 0.255
done
echo
}
while [ 0 ]
do
clear
printf "********Welcome to a SIMPLE FM TUNER V1.0*********\n\n"
echo "Please enter your FM station. Press its symbol no. correctly \n"
printf "1. Kantipur FM \n2. Hits FM\n3. Ujjyalo FM\n4. Sagarmatha FM\n5. Nepal FM \n6. Maitri FM\n7. Quit\n\n"

read choice
if [ $choice -ge 8 ]
then
echo "WRONG CHOICE YOU MORON"
echo "Press any key to continue"
read nothing123
else

commonCommand
choose
tune
fi
done

Monday, November 16, 2009

divide by n counter using verilog

module divideC(clk,nfreq);
input clk;
output reg nfreq;
reg[2:0] counter;
initial
begin
nfreq=1'b1; //when it goes to if[line no. 12] for the first time, it jumps to line no 15. so need clk as zero first.
counter=3'b111;//so that it starts from 000 for all waves
end
always @ (clk)
begin
if (counter<=3'b011) begin //000-011=4. plus one signal due to increament. so total 5 . so divide by 5 signals.
counter<=counter+1;
end else begin
counter<=3'b0;
nfreq<= ~nfreq;
end
end
endmodule


module divideC_tb;
reg clk;
wire nfreq;
divideC test_bench(clk,nfreq);
always
#1 clk = ~clk;
initial
begin
clk=1'b0;
#50 $finish;
end
initial
begin
$display("time\t\tnFreq");
$monitor("%g\t%b",$time,nfreq);
end
initial
begin
$dumpfile("wave.vcd");
$dumpvars(0,divideC_tb);
end
endmodule

Sunday, July 26, 2009

concordance using perl

yes i finally did it. it consumed a bit long time but felt good that i did it using perl. seems a portent.
its PERL program for concordance
what is concordance can be found on http://www.concordancesoftware.co.uk/
thought the disadvantage of the program is, the output is slightly distorted (i.e the word doesnt come in the middle) if the input word lies in less than half of the sentence with prescribed lenth. if length given is 12 then the word doesnt come in the middle if the word is within the first few words.
but it may be avoided as other words will be in different places

#################(c) PUNJ ###########
#! /usr/bin/perl
open (file, "source.txt");
$string = $ARGV[0];
print "Enter the no. of characters to be printed\n";
$noLines = ;
while ($lines = ) {
chomp $lines;
@array = split (/$string/,$lines);

$test = ($lines =~ s/($string)/\1/g);
if ($test ge 1) {
$countFirst = ($array[0] =~ s/(.)/\1/g);
$countSecond = ($array[1] =~ s/(.)/\1/g);
$countThird = ($string =~ s/(.)/\1/g);



$total = $noLines - $countThird;
$each = int($total / 2);


$third = substr($array[1], 0, $each);
$first = substr($array[0], -$each);

print "\n**\n$first $string $third\n**\n";
}
}
close(file);
###########################