Posts

Showing posts from 2012

Text-to-Speech converter

Image
A speech recognition application will typically perform the following basic operations:  Initialize the speech recognizer.  Create a speech recognition grammar.  Load the grammar into the speech recognizer. Register for speech recognition event notification. Create a handler for the speech recognition event. Create a new project in Visual Studio 2010 via select the  File Menu  > New Project Browse to other languagues Select visual basic and windows application enter Name as TextToSpeechVB. when the project is created you have to add a reference to the System.Speech.dll under .NET Tab. Now design the form in following manner. 1. ComboBox control(cmbInstalled) - to list all available installed voices 2. Button Control(btnStart) - To starting the Text-to-Speech 3. Button Control(btnEnd) - To stop the Text-to-Speech 4. Track Bar control(btnRate) - to control the Text-to-Speech speed rate. 5. Trach Bar Control( btnVolume)- to control the Text-to-Spee

Memory allocation/deallocation routines malloc() and free()

Image
According to my declaration, allocate the 50000 block of array. If memory block is available on the array, the program allocates a block from the array according to specify size.    Here I used the array data structure to implement the heap. In this code taken large contiguous buffer which used to allocate all the spaces associate with the NewMalloc() function. There doesn't allocate the same region of memory to two different NewMalloc() . Initially all 50000 bytes are free in this array. NewMalloc()              It takes one integer argument which represents the size and return a pointer to a contiguous region of that many bytes.              Now call to NewMalloc(60) . There we expect to allocate the first 60 bytes and return a pointer to the caller. Actually in the array allocates 68-bytes for that region. Because I maintain a meta data that keeps track of what space is allocated and what space is free. In meta data I hold the size of the block and availability of t

simple shell in C

This shell is called mosh (My Own Shell). When invoke, it should be able to read a command typed on its prompt ($) and execute it in a new process. It should also have a shell variable similar to PATH in bash. Shell variables are set as follows: PATH=/usr/bin:/bin The executable for the command is searched in the directories in the path and the first one found should be executed. mosh should also be able to handle pipes (not more than one pipe) similar to bash. Implementation in C #include <stdio.h> #include <unistd.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> #define INPUT_SIZE 512 #define BUF_SIZE 10 char** split_String(char *input_ptr,char *buffer[BUF_SIZE],int *n_args); /** *Main function of the shell */ int main(){     char input[INPUT_SIZE];     char *buffer[BUF_SIZE];     char *pipe_forw[BUF_SIZE];     char *ext_array[BUF_SIZE];     char **buf;     char *input_ptr;     int status_1,status_2;     in

Remort Shell

The client program running on the client computer should connect to the server program running on the server computer. Then the client program should prompt for commands from the user, make them run on the server computer and print results back on the client computer's screen. This command-result sequence should run in a loop so that a number of commands can get run on the server. When the user enters the text "exit" on the client program the system should terminate. Implementation in C client.c /* compile Command : gcc -o client client.c                   ./client */ #include  <sys/types.h> #include  <sys/socket.h> #include  <sys/un.h> #include  <stdio.h> #include  <netinet/in.h> #include  <netdb.h> #include <stdlib.h> #define  PORT  1030    /* addr to connect */ #define  HOST  "localhost" #define BUFSIZE 256 /*#define  HOST  "10.16.48.56"*/ main() {     char buffer[BUFSIZE];  

Simple pipe implementation

#include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(){     int pfds[2], status;     char *com1[]={"ls","-a",NULL};     char *com2[]={"sort",NULL};     switch(fork()){         case -1:              printf("Error has been occured");             exit(1);         case 0:             break;//Run the child         default:             wait(&status);//Parent is waiting until child exit             return (status);          }     if(pipe(pfds)<0)         exit(1);     switch(fork()){         case -1:             exit(1);         case 0:             close(1);//Close the stdout             dup(pfds[1]);//Duplicate the pipe write end             close(pfds[0]);//Close pipe read end             close(pfds[1]);//Close pipe write end             execvp(com1[0], com1);//Execute the command             exit(1);         default:             close(0);//Close the stdin             dup(pfds[0]);

Simple Boot Loader in Assembly

Terminal Commands: nasm boot1.asm -f bin -o boot1.bin dd if=boot1.bin bs=512 of=myhd.img qemu myhd.img Help for boot1.asm: 'INT 0x10' is a BIOS video interrupt. All video related calls are made through this interrupt. To use this interrupt, we need to set the values of some registers as follows.     AL => With ASCII value of character to display     AH => With 0x0E ;           Teletype mode (This will tell bios that we want to print one character on screen)     BL => With Text Attribute (This will be the fore ground and background color             of character to be displayed. 0x07 in our case.)     BH => With Page Number (0x00 for most of the cases)     Once all the registers are filled with appropriate values, we can call interrupt. Implementation in Assembly [BITS 16]                        ;Tells the assembler that its a 16 bit code [ORG 0x7c00]                 ;Origin, tell the assembler that where the code will                        

Posix Thread example

Get a file name from the command line to the main function and create that file. When SIGPWR is received, each thread should write the following line to the created file. The sum from ``low'' to ``i'' is ``myresult''. Also in the main function, before the threads are created, print the process id of the parent process so that you can send SIGPWR to it using the ``kill'' function from another terminal. Implementation in C #include <stdio.h> #include <pthread.h> #include <signal.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #define ARRAYSIZE 1000 #define THREADS 10 #define TRUE 1 #define FALSE 0 void *slave(void *myid); void pwrhandler(int signal); //Signal handling function for PWR signal /* shared data */ int data[ARRAYSIZE]; /* Array of numbers to sum */ int sum = 0; pthread_mutex_t mutex; /* mutually exclusive lock variable */ int wsize;          /* size of work for e