Sunday, March 28, 2010

Yii framework

Not so long time ago I have learned php5 Yii framework
It is quite simple and well documented MVC  framework
I like it!

So why I think it will be popular?
because it is easy to use.. and it is free
Here is  few the most important features for me

first of all I pay attention to frameworks localization
only one static function  

Yii::t("section", "string")

It is very important to have only one entry point for all user requests
in this case you can wrap this entry with security patterns and framework itself already did it for you

All requests have the same entry for example

of cause you are able to create more attractive requests like

there is a trick.. all this urls redirect your request to one php file. remove php file entry name like "index.php" is done using .htaccess or if you are able to configure apache yourself it is could be done in *.conf file

You  are able to request data  from database even if you don't know sql and even if you are not sure what database is installed on you web server. I mean code that Yii framework produces is working with any sql database platform (MySQL, PostageSQL, SQLite or other PDO php extention. 
As results of the request it returns associative array and all other low-level stuff framework hides inside.

Widgets and Components
Widgets is a way to reuse you code - very powerful thing

I am not going to describe all Yii features, there is a manual for that

Friday, March 19, 2010

Android Streaming Audio

Android audio framework

I will try to explain as detailed as possible about streaming audio in android. For this purposes in SDK 1.5 has been added AudioRecord and AudioTrack classes. AudioRecord is responsible to get samples from microphone and AudioTrack is responsible for playback samples.

This classes works only with PCM encoded data (it means that they are not encoded at all :)

Play one buffer loop


AudioRecord record = null;
AudioTrack track = null;
record = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000,
    AudioRecord.getMinBufferSize(8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT) * 4

log.d("AudioTrack min buffer size: "
+ AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,

track = new AudioTrack(AudioManager.STREAM_VOICE_CALL, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
Initialization is quite simple. All you have to do is to create AudioRecord and AudioTrack

Start audio player;

Start audio recorder


Main Loop 
while (needMoreAudioData)
{, bufferSize);
     player.write(buffer, bufferSize);

Stop audio player/recorder

Remove player
Because this objects works with system resources developer has to release them when they are not in use. Java garbage collector will not release them automatically because instances hold system handlers.

Hope you have got the idea ...

Now few practical tips

When you call  record.startRecording();  recording is already started! and to reduce latency you have to read that data immediately.

You should realize that android is not a real-time operating system and often call backs come not exactly at certain. You will end-up with increased latency over time unless you apply a sort of throttling algorithm to adjust playback side.