Wednesday, April 25, 2007

As accessing binary data (either writing and reading, basically the reading part of it) was tedious with PERL.
I thought C++ will help me with it. Initially, I was having to deal with the last data element being stored twice. This is now resolved....

The sample code is as:

// writing and reading a binary data
//
#include
#include
using namespace std;

// gives nice explaination on reading and writing a binary file
// ref: http://www.gamedev.net/reference/articles/article1127.asp
// http://courses.cs.vt.edu/~cs2604/spring06/binio.html
//
int main() {

// data to be written to a file
//
float arr[4] = {10.234, 1.212, 0.2, 342};

ofstream outfile("test1.raw", ios::out | ios::binary);

cout << "writing to a file " << i =" 0;" j =" arr[i];"> float data1[4];
and have --> myfile.read( (char *) &data1, sizeof(data1));
to access the data..

Tuesday, April 24, 2007

My idea was to access binary data using PERL. Specifically, if the data is of variable length.
For example, I have a data stream: 1 12 123 12 34. With PERL, can I write this data to a file? The answer is sure, I can. Actually writing the above variable length data is easy. All you have to do is open the file in binary mode and dump the data.

But, retrieving the data is an issue. I am not able to get hold of it...

Here is the code:

#! /usr/bin/perl

# to read and store binary files
# ref: --> http://www.herongyang.com/perl/binary.html

# gives problem with variable length data..

# part 1) to write binary data to a file
# this works correct.

@floatvalues = (23.3, 3.2, 4.3, 5.4);
$out = "test.raw";
open(OUT, "> $out");
binmode(OUT);
foreach $value (@floatvalues) {
print OUT "$value\n";
print "$value ";
}
print "\n";
close(OUT);

# part 2) to read binary data from a file
# reading is a trouble. As read function has a parameter identifying the data
# width.

$IN = "test.raw";
open(IN, "$IN");

while (read(IN, $value, 3)) {
print "$value \n";
}

close(IN);


How to overcome this?

Monday, April 16, 2007

Some how the conversion from little Endian wave file (windows wav format) to the Big Endian raw format (Sun unix box) was not done correctly by using the following two commands:
- to start with we need to remember that the initial wav file was converted to big endian one and we start from here. This file is 44100 Hz sampled.
Then,
1. sox for downsampling and,
2. dd for byte swapping.

This experiment failed.

Hence, the results for Sphinx experiments were the way they were (very low speech recognition accuracy).
After which the steps for conversion were changed.
The three step process:
1. The existing raw file was first converted to the wav format (again using Sox) then,
2. downsampled (sox) and,
3. then dd for byte swapping.

This worked as the recognition rate drastically improved from 3% to 90% under all conditions (neutral, cognitive load, physical load).

Lessons learned:
1. Know thy tools
2. Beware of finding what you are looking for.