bookmark_borderCustom Font Example iPhone

An example for using custom font in iPhone.

Initially, I have tried with UIFont for using custom font, but it seems not possible.

Documents from apple:

Create custom font using CGDataProvider:

NSString *fontPath = [[NSBundle mainBundle] pathForResource:@”CUSTOM_FONT” ofType:@”ttf”];
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithFilename([fontPath UTF8String]); CGFontRef customFont = CGFontCreateWithDataProvider(fontDataProvider);

Use the font:

CGContextSetFont(context, customFont);
CGContextSetFontSize(context, 34.0);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGGlyph textToPrint[[mainString length]];
// Loop through the entire length of the text.
for (int i = 0; i < [mainString length]; ++i) { // Store each letter in a Glyph and subtract the MagicNumber to get appropriate value.
textToPrint[i] = [[mainString uppercaseString] characterAtIndex:i] + 332;

//to understand the MagicNumber, I open the font file using FontForge
//found that the font I am using started from location 32
//after I changed the “Encoding->Reencode” to “Glyph Order”
//I found that the “U+0020 space” started from location 3

bookmark_borderSpeech detection example iPhone

This is an example, how to start working on speech detection application for iPhone.

We have two major task:
1. Access the audio data.
2. Implement the logic part.

Task1: Access the audio data:
Download SpeakHere Example code from Apple:

Open “Classes->Play & Record->” and edit the folloding function:

// AudioQueue callback function, called when an input buffers has been filled. void AQRecorder::MyInputBufferHandler(...)

Add the following code to access the audio data:

 //for signed 16-bit little-endian
 SInt16 *buf = (SInt16 *)inBuffer->mAudioData;
 for(int i=0; i< inBuffer->mAudioDataByteSize / 2; i=i+2) {
  printf("n%dn%d ", buf[i], buf[i+1]);

(Please feel free to let me know if I am doing anything wrong…)

Run the application. You will get the raw data in gdb/console/log.
Copy the data in a text file and plot it.

Download gnuplot and AquaTerm

I have copied the data in a text file name “hello.txt” and saved it in my home directory.
Plot this, in gnuplot using the following command:

gnuplot>plot “hello.txt”

Task2: Implement the logic part:

For speech detection purpose we do not need to check all the data. Set some filter to check the data within some range. You can also try with the maximum and minimum value.

As the maximum and minumum value is similar, you can simply check one part.

If you want to detect specific type of speech or sound, analyze the graph by taking some sample.
Understand the logic and implement a coded logic to detect it.

For normal detection purpose take many sample and do R&D youself.

Please note that the mic “Input Volume” may affect your data.

bookmark_borderRadio App Example iPhone

I was working on an application to play audio stream from an online radio. Here is some hints for the developers who want to do similar types of work.

Initially we have two major task:
1. Read stream data.
2. Play the stream data.

From apple developer documentation:

How do I play streamed audio?

To play streamed audio, you connect to a network stream using the CFNetwork interfaces from Core Foundation, such as those in CFHTTPMessage. You then parse the network packets into audio packets using Audio File Stream Services (AudioToolbox/AudioFileStream.h). Finally, you play the audio packets using Audio Queue Services (AudioToolbox/AudioQueue.h). You can also use Audio File Stream Services to parse audio packets from an on-disk file.

Task 1: Working with HTTP stream

Read “CFNetwork Programming Guide” specially the “Communicating with HTTP Servers” part.

Use the callback

if (CFReadStreamSetClient(myReadStream, registeredEvents, myCallBack, &myContext) {...}

A sample callback:

static void myCallBack
(CFReadStreamRef stream, CFStreamEventType type, void *clientCallBackInfo) {
if(type == kCFStreamEventHasBytesAvailable) {
UInt8 buffer[2048];
CFIndex bytesRead = CFReadStreamRead(stream, buffer, sizeof(buffer));

if (bytesRead > 0) {
else if (bytesRead) {
NSString* to_add = [NSString stringWithCString: (char*)buffer length: bytesRead];
NSLog(@"%@", to_add);

Run the application. If you can see the HTML tag in your debug console, then your network stream reading is working fine.

Task 2: Working with audio

Read “Audio File Stream Services Reference” to get basic idea about the streaming audio.

Check the “AudioFileStreamExample” from:

Merge the “AudioFileStreamParseBytes” with the “myCallBack” method.

Download Sample Code:

bookmark_bordernasm in Mac OS X

I was trying to compile a simple assembly program in Mac OS X (Leopard).

I was getting an error message

ld: could not find entry point “_start” (perhaps missing crt1.o) for inferred architecture i386

A simple asm program for FreeBSD and MacOS
(we have to use the stack for system call, from

section     .text
global _start ;must be declared for linker (ld)

int 0x80 ;system call

_start: ;tell linker entry point

push dword len ;message length
push dword msg ;message to write
push dword 1 ;file descriptor (stdout)
mov eax,0x4 ;system call number (sys_write)
call _syscall ;call kernel

;the alternate way to call kernel:
;push eax
;call 7:0

add esp,12 ;clean stack (3 arguments * 4)

push dword 0 ;exit code
mov eax,0x1 ;system call number (sys_exit)
call _syscall ;call kernel

;we do not return from sys_exit,
;there's no need to clean stack
section .data

msg db "Hello, world!",0xa ;our dear string
len equ $ - msg ;length of our dear string

In Mac OS X we should use format macho

nasm -f macho hello.asm

and for the linker (we need to specify the entry point)

ld -e _start -o hello hello.o


bookmark_borderBengali in LaTeX in Mac OS X

I have installed LaTeX for Mac OS from

I was trying to write Bangla in LaTex. Found two ways to write bangla in LaTeX.

Unicode Standard

written by Golam Mortuza Hossain. Here I am just writing how to do this in Mac OS.

First download freefont-ttf-xyz.tar.gz from


which containing

Paste these fonts in your “Macintosh HD/Library/Fonts/”

Now try sample document in TeXShop

% This file is a based on the sample tex file to illustrate use of
% XeTeX in typesetting Bengali document.
% License under GNU FDL by Golam Mortuza Hossain, 2008
fontserifbb=”FreeSerif:script=beng” at 24pt
fontdeffont=”FreeSerif:script=beng” at 14pt

title{bfserifbb সত্যজিৎ রায়}
author{bfserif উইকিপিডিয়া, মুক্ত বিশ্বকোষ থেকে}
deffont %Default font used for the document
সত্যজিৎ রায় (২রা মে, ১৯২১ – ২৩শে এপ্রিল, ১৯৯২) একজন বাঙালী চলচ্চিত্র নির্মাতা ও বিংশ শতাব্দীর অন্যতম শ্রেষ্ঠ চলচ্চিত্র পরিচালক। কলকাতা শহরে সাহিত্য ও শিল্পের জগতে খ্যাতনামা এক বাঙালী পরিবারে তাঁর জন্ম হয়। তিনি কলকাতার প্রেসিডেন্সি কলেজ ও শান্তিনিকেতনে রবীন্দ্রনাথ ঠাকুরের প্রতিষ্ঠিত বিশ্বভারতী বিশ্ববিদ্যালয়ে পড়াশোনা করেন। সত্যজিতের কর্মজীবন একজন বাণিজ্যিক চিত্রকর হিসেবে শুরু হলেও প্রথমে কলকাতায় ফরাসি চলচ্চিত্র নির্মাতা জঁ রনোয়ারের সাথে সাক্ষাৎ ও পরে লন্ডন শহরে সফররত অবস্থায় ইতালীয় নব্য বাস্তবতাবাদী ছবি লাদ্রি দি বিচিক্লেত্তে (ইতালীয় ভাষায় Ladri di biciclette, “সাইকেল চোর”) দেখার পর তিনি চলচ্চিত্র নির্মাণে উদ্বুদ্ধ হন।

Select “XeLaTeX” from drop down menu and click “Typeset” button for Output in TeXShop.



First Bengali typesetting system using LaTeX. Which use a non-standard approach to write bangla.


centerline{bngxxv ra*g*er OShudh}
centerline{bngxviii sukumar ray}

which give output
রোগের ওষুধ
সুকুমার রায়

download bfonts.tar.gz, bsty.tar.gz, bsample.tar.gz from

Installing the font files
cd /usr/local/texlive/2008/texmf-dist/fonts/source
sudo mkdir bangla
extract bfonts.tar.gz in /usr/local/texlive/2008/texmf-dist/fonts/source/bangla/
Installing the macro files for LaTeX
cd /usr/local/texlive/2008/texmf-dist/tex/latex
sudo mkdir bangla
extract bsty.tar.gz /usr/local/texlive/2008/texmf-dist/tex/latex/bangla/
Initializing the files
sudo texhash


bookmark_borderProbhat in MacOS

I have ported the Probhat Layout (a bangla keyboad) in MacOS .

Download link

* Unpack the zip file, there will be two files “Probhat.icns” and “Probhat.keylayout”.
* Paste these two files in “Macintosh HD/Library/Keyboard Layouts/” or “Home/Library/Keyboard Layouts/”, which will install the keyboard layout.

* Go to “System Preferences” > “International” > “Input Menu” scroll down and make sure that “Probhat” is checked.

* Make sure Show input menu in menu bar is checked, default English layout will be highlighted in the menu bar.

* Now click on “Keyboard Shortcuts” and in the “Input Menu” section put your desired keyboard shortcut that will enable you to change the keyboard layout (Our choice was Alt+Space).

* Now while typing in any application, pressing Alt+Space will switch to Probhat Layout and Probhat layout symbol will be highlighted in the menu bar.