Tuesday, December 7, 2010

Fix android activity screen orientation

In your activity class insert code:
    @Override
    public void onConfigurationChanged(Configuration newConfig)
    { super.onConfigurationChanged(newConfig);
    }

In your manifest activity tag, declare attribute:
 android:screenOrientation="portrait"

Thursday, December 2, 2010

Predator sound in android

Configure AudioRecord input as stereo and AudioTrack output as mono. You will get sound as if a predator's listening.

Monday, November 1, 2010

Problems solved while Making CPP app work on eclipse CDT with cygwin

On Windows.
Using libsndfile to decode wav file to raw pcm.

Problem1: Linking to the external library  libsndfile.
Extracting/installing libsndfile gave me the header and DLL.

In Eclipse, Set [Project->Properties->C/C++ General->"Paths and Symbols"->include] and  [Libraries] to the .h and .dll files respectively.(F:\libsnd\includes\libsndfile-1.h and F:\libsnd\libsndfile-1.dll)
Result: While linking "File not found: libsndfile-1.h"

Solution:
Added folder containing libsndfile-1.dll (F:\libsnd\) to [Project->Properties->C/C++ General->"Paths and Symbols"->Library Paths] and added "sndfile-1" to [Libraries] {"libsndfile-1.dll" - ["lib", ".dll"]}

Solved.

Problem2: Now EXE is generated but on "Run" throws "multiple target patterns. Stop." in some ".d" file

http://dev.eclipse.org/newslists/news.eclipse.tools.cdt/msg12202.html : The ":" in path to header file is detected as a new target.

Solution: 
Changed "F:\libsnd\includes\libsndfile-1.h" to "/cygdrive/f/libsnd/includes/libsndfile-1.h" in [Project->Properties->C/C++ General->"Paths and Symbols"->include]

Solved.

Problem3: While debugging it says "gdb unknown target exception"


Add path to DLL file in environment variable "PATH". Restart eclipse.
Or Copy the dll to the project folder

Tried editing the path variable.

Solved.



Tuesday, September 28, 2010

Digital Audio Processing notes - from basics to who knows

http://en.wikipedia.org/wiki/Amplifier - basically wanted to check why gain can't be increased to infinity without affecting the information in audio(quality).
The gain of an amplifier is the ratio of output to input power or amplitude, and is usually measured in decibels.
The bandwidth of an amplifier is the range of frequencies for which the amplifier gives "satisfactory performance". The definition of "satisfactory performance" may be different for different applications. However, a common and well-accepted metric is the half power points (i.e. frequency where the power goes down by half its peak value) on the output vs. frequency curve.
In ultra high fidelity amplifier design, the amp's frequency response should extend considerably beyond this (one or more octaves either side) and might have −3 dB points < 10 and > 65 kHz.
Professional touring amplifiers often have input and/or output filtering to sharply limit frequency response beyond 20 Hz-20 kHz; too much of the amplifier's potential output power would otherwise be wasted on infrasonic and ultrasonic frequencies, and the danger of AM radio interference would increase. 
Modern switching amplifiers need steep low pass filtering at the output to get rid of high frequency switching noise and harmonics.
Efficiency is a measure of how much of the power source is usefully applied to the amplifier's output.
Commercially available Class D switching amplifiers have reported efficiencies as high as 90%.
An ideal amplifier would be a totally linear device, but real amplifiers are only linear within limits.
When the signal drive to the amplifier is increased, the output also increases until a point is reached where some part of the amplifier becomes saturated and cannot produce any more output; this is called clipping, and results in distortion.
Noise is an undesirable but inevitable product of the electronic devices and components


http://en.wikipedia.org/wiki/Switching_amplifier - Class D amplifier or switching amplifier is an electronic amplifier where all power devices (usually MOSFETs) are operated as binary switches. They are either fully on or fully off. Ideally, zero time is spent transitioning between those two states.


http://www.audiosonica.com/en/course/post/2/Index- cool. got it from wikiversity. study sound effects concepts from here.
http://en.wikiversity.org/wiki/Getting_started_with_sound_recording
http://en.wikiaudio.org/Main_Page - on it.
http://en.wikibooks.org/wiki/Reaktor/Links/DSP
http://www.musicdsp.org/showmany.php -source codes :))) couldn't be better
http://www.digitalfilter.com/enindex.html
search "digital audio processing" on wikibooks
http://www.halfbakery.com/idea/Noise_20Cancelling_20Voice_20Amplifier -One would not want these voice wavelengths amplified, for fear of deafening the user by amplifiying noise components (eg: cymbals) which happened to be in that wavelength as well. The NCVA improves the signal of voice sounds by adding a low background of white noise at these same voice frequencies. This will not make voices louder, but will make them sharper. That's stochastic resonance.

http://www.freepatentsonline.com/4506379.html
http://www.freepatentsonline.com/4506379.pdf

http://members.misty.com/don/hivoice.html -interesting.How to Get More Apparent Voice Audio Power with Less Amplifier Power! Some about some "formants"
http://www.cs.cmu.edu/~music/icm/slides/week_10.pdf -Introduction to Computer Music. Week 10 - The Human Voice. More "formants"
http://users.otenet.gr/~athsam/speetch_filter.htm -for electronicians

Sunday, August 29, 2010

Custom Adapter with a Listview

http://developerlife.com/tutorials/?p=327

API demos notes

1. SharedPreferences : http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/PersistentState.html
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/RedirectEnter.html - follow the classes in the source for advanced SharedPreferences ops.
eg: preferences.edit().remove("text").commit();

2. TextView.BufferType.EDITABLE - This allows us to later extend the text buffer : http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/ReceiveResult.html

3. Example of removing yourself from the history stack after forwarding to another activity(just call finish) : http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/Forwarding.html

4. Translucent activity - android:theme="@style/Theme.Transparent" in the activity declaration in manifest : http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/TranslucentActivity.html

5. Translucent+BLUR background -

    // Have the system blur any windows behind this one.
       getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
       WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Also in manifest - android:theme="@style/Theme.Transparent"> :  http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/TranslucentBlurActivity.html

6. Services : later

7.

Monday, August 9, 2010

Android error: "audiorecord Could not get audio input for record source 1"

http://comments.gmane.org/gmane.comp.handhelds.android.devel/84064 - says: "I was trying to start recording
from 2 separate threads at the same time causing a conflict."

http://langtagsandroid.langtags.com/blog/?p=605 -  says: Everytime you get an error instantiating AudioRecord it doesn´t release it´s resources the way it should so you won´t be able to request it again unless you restart your phone (or close and reopen
the emulator).
This solution (restarting emulator) worked for me

Android AudioTrack-AudioRecord native API usage and recommendations

http://markmail.org/message/ikt3yvfag6pfr342#query:android%20audiotrack%20native%20api+page:1+mid:ikt3yvfag6pfr342+state:results

Sunday, August 8, 2010

Android: Horizontal Progress Bar

<ProgressBar
android:id="@+id/ProgressBar01"
android:layout_height="wrap_content"
android:layout_width="250px"
style="?android:attr/progressBarStyleHorizontal">
</ProgressBar>

Thursday, July 15, 2010

Low Level Android app fundamentals: Rookie/Novice/fresher...

APPLICATION COMPONENTS:
1. Activity(ACT)

activity, window(W), view(V)
Activity.setContentView()



2. Service(SVC)-

3.  Broadcast Receiver(BR)- 

4. Content Provider(CP)- 
ContentProvider(CP) and ContentResolver(CR)

ACTIVATING COMPONENTS USING INTENT

ACT:

SVC:

BR:
onReceive()









SHUTTING DOWN COMPONENTS


ACT:
finish()
finishActivity(). (startActivityForResult())


SVC:
stopSelf() 
Context.stopService().







THE MANIFEST FILE












INTENT FILTERS




ACTIVITIES AND TASKS





The principal Intent flags are:



FLAG_ACTIVITY_NEW_TASK
FLAG_ACTIVITY_CLEAR_TOP
FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
FLAG_ACTIVITY_SINGLE_TOP
The principal <activity> attributes are:
taskAffinity
launchMode
allowTaskReparenting
clearTaskOnLaunch
alwaysRetainTaskState
finishOnTaskLaunch 






High Level Android app fundamentals: Rookie/Novice/fresher...

http://developer.android.com/guide/topics/fundamentals.html - nothing better

Wednesday, July 14, 2010

Clean URLs with Drupal-UrlRewriteFilter-Quercus-Jboss

http://www.brianshowalter.com/blog/running_drupal_on_quercus - There's a nice RewriteRule-RewriteMatch combo classes for UrlRewriteFilter posted at this blog.
But it's designed  for tomcat and didn't work on following JBoss configuration right away.
The JBoss config:
1. JBoss-4.2.2
2. Deploying the Quercus web-app(with Drupal inside) as exploded war (Folder name= "myapp.war").
3. Quercus 403
4. Drupal-6.17.
5. UrlRewriteFilter-320
Steps that worked for me:
1. Follow  the above blog at brianshowalter.com.
2. Download UrlRewriteFilter source code from http://code.google.com/p/urlrewritefilter/
(http://code.google.com/p/urlrewritefilter/downloads/detail?name=urlrewritefilter-3.2.0-src.zip&can=2&q=)
3. You must have already downloaded drupalrewrite_0.1 in step1.
4. Couldn't find a link for posting comments on above blog. Hence posting the modified source code here. Kindly setup UrlRewriteFilter and drupalrewrite_0.1 sources with all required libs in eclipse etc. and copy the compiled classes to your myapp.war/WEB-INF/classes.
5. Checkout updated sources for drupalrewrite from http://drupalrewritefilter.googlecode.com (http://code.google.com/p/drupalrewritefilter/source/checkout) and compile/jar and copy to WEB-INF/lib(jar) or WEB-INF/classes(class) as you wish.
6. Good to go.

Thank you.

Monday, June 21, 2010

Removing HTML tags from a String using Regex

result = data.replaceAll("\\\\n","<br/>"). //replace \n with <br/>, 
replaceAll("\\\\", ""). //remove stray "\"s
replaceAll("\\\"", "\\\\\""). // and escape double quotes
replaceAll("<[\\p{Alnum}\\p{Space}\\.\\-=/:\\\"\\\\;]*>"," "). //remove all opening html tags
replaceAll("</[\\p{Alnum}]*>"," "); //remove all closing html tags

Tuesday, June 15, 2010

High Level Hadoop MapReduce: Rookie/Novice/fresher...

MapReduce borrows a lot from functional programming(Lisp/ML/Scheme). Func. prog. expects to process lists of data frequently, hence they have a lot of inbuilt iterator-mechanisms and higher-level functions called list-comprehensions that are operators over lists. Two of these operators are map and reduce. Like map operator, Mapper takes a record (assumed to be a key-value pair) but can emit multiple key-value pairs(map operator does only one). A characteristic of MapRed paradigm is that mapper should be processing individual records in isolation of one-another.(One Record = up to you- depends on the class that loads the data from the block into mapper as k-v pair records).
Reducer takes a key and list of values and can emit none, one or multiple key-value pairs.

It's a general notion to ignore the key that's input to a map task. They could be byte offset to a chunk of data.

People also skip mapper or more often reducer, if it suffices for the app.
Reducers don't start until all mappers complete. They run on the same nodes as mappers(after mappers complete).
All values with same keys are collected from all mappers(that emitted that key) and sent to same reducer. This involves network communication. If multiples keys are processed by one reducer, they are presented to it in sorted order(No assumptions about the values of those keys). This is called "sort and shuffle" phase handled by the underlying framework. A single reduce task processes single key(it takes one key and list of values as input).

Within sort and shuffle, there can be a user-defined combine task that's run on the mapper's intermediate results. If app-logic allows it could be same as reducer code(eg: if reducer is commutative and associative). Combining phase is disabled by default. It runs on the mapper machine. It's solely for reducing network data-load and load on reducer. Don't perform any data-specific operation in combine phase. It may run zero, one or more times.(depends on size of data). Example is the word-count map reduce jobs. Mapper emits [, 1] . Combiner aggragates that mapper's results to [, n](no. of times the word occurred in the input blocks local to that machine). Then comes the reducers(mappers die).

Thank You.

Friday, June 11, 2010

Hibernate JDBCConnectionException: could not execute query- Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:

"org.quartz.JobExecutionException: could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query [See nested exception: org.springframework.dao.DataAccessResourceFailureException: could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query]
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 13,768,115 milliseconds ago.  The last packet sent successfully to the server was 13,768,115 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem."

This problem occurred in a Grails application having a cron job that requests some data from an external server, processes it and persists some results. However the data is very large and the app requires 2+ Hrs. to process all of it before persisting a small result. The jdbc connection remains idle during this time.
Setting 'autoReconnect=true' or max_idle_time is certainly not a reliable solution for this.

What worked for me:
http://sacharya.com/grails-dbcp-stale-connections/: This was my exact problem. It says "By default, DBCP holds the pooled connections open for infinite time. But a database connection is essentially a socket connection, and it doesn’t come for free. The host OS, database host, and firewall have to allocate a certain amount of memory and other resources for each socket connection. It makes sense to those devices not to hold onto idle connections for ever. So the idea is to make sure that you don’t have stale connections in your pool that would otherwise be silently dropped by OS or firewall."

Modified my Datasource.groovy for working out this solution.
Had to use the following syntax from: http://stackoverflow.com/questions/376544/grails-mysql-maxpoolsize
Modified my Datasource.groovy:

dataSource {
    pooled = true
    dbCreate = "update"
    url = "jdbc:mysql://localhost/yourDB"
    driverClassName = "com.mysql.jdbc.Driver"
    username = "yourUser"
    password = "yourPassword"
    properties {
        maxActive = 50
        maxIdle = 25
        minIdle = 5
        initialSize = 5
        minEvictableIdleTimeMillis = 60000
        timeBetweenEvictionRunsMillis = 60000
        maxWait = 10000     
    }   }


Other relevant links:

http://drglennn.blogspot.com/2009/05/javasqlsqlexception-communication-link.html
http://commons.apache.org/dbcp/configuration.html
http://www.grails.org/DataSources+New
http://www.grails.org/1.2+Release+Notes