awk to the rescue

Some days back I got a collection of 100 Greatest Piano Works cd collection. The first thing I did was to rip the CD in flac and preserve a lossless copy of the disks. Then I converted those to ogg files (with oggenc ) so that I could take it in my iPod and listen at any time. The problem occurred at the final moment when I realized that the file names were really long and which would be very difficult to scan through my iPod (with Rockbox). The file name was in this format : %n – %a – %t.ogg  for example : For example :
“17 – Robert Schumann (1810-1856) – THE DAVIDSBÜNDLER DANCES, 18 CHARACTERISTIC PIECES, OP. 6: XIV. Zart und singend – Dolce e cantando.ogg” . The western classical musics this combination is very long most almost all the tracks, and these files with huge file names and lot of files having ‘:’ in the name being refused to copied directly. So I needed to truncate or rename the 100 files in a way so that they are identifiable and also truncated to short names.
I decided to keep only the track name and composers names (%n – %a fields), by renaming the files with some batch file renaming process. Continue reading “awk to the rescue”

Sieve of Eratosthenes : A basic implementation

The Sieve of Eratosthenes is a process to find all primes not exceeding a specific positive integer. The process is simple. First all the numbers within the range is populated in a list.The process strikes out all the numbers in the list which are multiple of some previous number. This strike-out process starts with the integer 2, thus first all the multiple of 2 upto the limit n are striked out. Note that the number 2 itself is not striked out, because it is not a multiple of any integer lesser than it (except 1). Next the just following unstriked integer is selected, which is in this case 3, and then all the multiples of 3 are striked out from the like, and again the next unstriked out integer is selected and the process continues until no such integer remains in the list which is unstriked and a multiple of some integer lesser that it. Note that the next integer to strike out after the ith unstriked integer is i * i , as all the multiples of i less than i are striked in the previous passes. At the end if the process only those numbers will be still unstriked in the list which are not a multiple of some other integer lesser that it, thus only the prime numbers will remain unstriked in the list. At the end of the process the list can be rescanned and the unstriked integers could be found.
Read more about Sieve of Eratosthenes here: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
Read the complete implementation

wcat : A GNU cat implementation

Everybody has used the GNU or UNIX cat program in the command line. It is used to concatenate files and dump it into the standard output, or can simply be redirected to another file. Long ago i started to write my own version of the cat program. I have implemented each and every function which cat supports, and also made it look identical, except some messages. Although this is not a cat clone, and has no connection with the source code of GNU cat. This code was made by inspecting the output behaviour of GNU cat. This is named wcat. I started this because this was the most simple code to write and was intended for the Whitix OS project run by Mathew (http://www.whitix.org/). This is a very good OS development project for the beginners to start with. I could not at present actively participate in this project because of the time limitations here at my end.
Check out the code

What are ID3 Tags all about?


id3_logo

When you play a music file in your favourite music player, or in your portable media player the track name, album, artist, lyrics gets displayed. You can search the songs with artists, album names. Even some of the tracks come with album art too, but there is no image file anywhere. The question generally arises, where does these information come from? The answer is straight forward; this metadata about the audio track is stored inside the audio file itself. The different audio files need different codecs. Different audio format files also have different such metadata systems. For example The Vorbis comments, APE tag, ID3 tags etc.

The most common and popular audio media (although not the best) is the mp3 . Mp3 audio format stores this metadata inside the music file, either at the beginning or at the end or at both locations. The music metadata system used with mp3 is called an ID3 Tag.
We will rip off the ID3 tag and check out what’s inside it in this article. We will discuss about ID3v1.x and ID3v2.x tags.

Continue reading “What are ID3 Tags all about?”

An ID3v1 Tag Parsing Library

id3_logo

ID3 tag is an mp3 audio media file tagging system. The ID3 tags are stored in a pre-defined location in the mp3 media file, either in the start or at the end (or both). There are two major versions of the ID3 tags. ID3v1 and ID3v2. The tag store data about the song, like track name, album name, artist name, genre, track no, year, composer, licensing information, lyrics, even multiple images inside the tag. To get more information about ID3 tag please check the official website of ID3 tag: http://www.id3.org/, also check this article What are ID3 Tags all about?

Continue reading to get the library

Synchronization Safe Integer

Synchronization safe integers are related to ID3v2 tags. ID3v2 tags has a dynamic structure where the length of the tag is variable and inside the tag, there can stay a lot of frames which again can be of dynamic sizes. The size of the tag is stored in the ID3v2 tag header is of length 4 bytes long. These 4 bytes are stored in a special format which is called a synchronization safe integer. Also from ID3v2.4 tags also the frame size bytes which are stored in the frame headers, describing the frame’s length, are stored as 4 byte synchronization safe integer.

Continue reading “Synchronization Safe Integer”

Hero’s Method : Evaluating square root of a real number

A floating point number is given. the task is to evaluate the value of its square root. We will discuss how to find the square root of a real number in this post, and also present a C Language code which does this job. The value of the root will be evaluated with the Hero’s method.
Continue reading “Hero’s Method : Evaluating square root of a real number”

Finding qth real root of a real number

In this post we will see how to find nth roots of a positive real number. We will use the Newton-Raphson method to deduce an iterative formula, and see its convergence.

The task is to find the real qth root of a real number. Let there be a non-negative real number C, of which the real qth root is to be found. Let the square root of C be x. We represent this with x=\sqrt[q]{C} .

Now:
x=\sqrt[q]{C}
\Rightarrow x^{q}=C
\Rightarrow x^{q}-C=0

So we are now to find the roots of the qth order function f(x)=x^{q}-C

Continue reading “Finding qth real root of a real number”

Counting Rectangles in an n X m Checked Board

We have a checked board like a chess board, but instead of 8 x 8 it has a dimension of n x m . The task is to count the number of rectangles of all possible dimensions i x j in that checked board. Also the question arises how many squares of all possible dimensions are there. We will solve this problem by establishing formulas by construction. After this we can calculate the number of rectangles and squares of a Chess Board or any other such checked board.

Continue reading “Counting Rectangles in an n X m Checked Board”