Orchisama Das INTERNSHIP REPORT - Stanford University

Transcription

Orchisama DasAugust 2015INTERNSHIP REPORTDEVELOPMENT OF AN ANDROID APPLICATION TOCAPTURE AND ANALYSE THE COMMUNITY NOISEPROBLEM, THE “RANCHLANDS’ HUM”BY – ORCHISAMA DAS, RESEARCH INTERN, BACHELOR OF ENGINEERINGIN INSTRUMENTATION AND ELECTRONICS, JADAVPUR UNIVERSITY,INDIA.SUPERVISOR – DR. MIKE SMITH, PROFESSOR, ELECTRICAL ANDCOMPUTER ENGINEERING, SCHULICH SCHOOL OF ENGINEERING,UNIVERSITY OF CALGARY, CANADA.

Orchisama DasAugust 2015INTRODUCTION - WHAT IS THE HUM?The Hum is a worldwide phenomenon associated with widespread reports of a sporadic, low frequencynoise, which is very often labelled as disturbing. It can cause sleeplessness, depression and vibro –acoustic diseases in humans [1]. Hums have been reported in various parts of the world such as Bristol,UK and Taos, Mexico [2]. Rarely has the source of a hum been detected. An exception was in Windsor,Ontario where the source was traced to a steelworks on the industrial zone of Zug Island. Other possiblecauses of the hum are - mechanical devices from industries, vibrations of the earth and resonance of thepiping system in our homes.In 2008, residents in Calgary, Canada started complaining about a low frequency noise around 40Hz,which came to be known as the ―Ranchlands‘ Hum‖. The nuisance was described by one resident assounding like the Gsharp note on the piano that is three octaves below Middle C, approximately 46Hz. Itcould have an intensity that ranged from ‗barely audible‘ to ‗conversation stopping‘ on differentoccasions. The mystery behind this Hum is still unsolved. Dr. Smith‘s team has been working ondetecting its source since 2009, assisted by an acoustics firm called Patching Associates AcousticalEngineering Ltd.WHY AN ANDROID APP?Patching Associates was lending some very high-end, expensive industrial equipment to residents inCalgary to allow them to record the hum. However, they only had a limited number of equipment, anddistributing them to a large number of homes in Calgary was not feasible. Developing a cell phoneapplication to capture this data seemed to be the cheapest and best option because everybody has accessto a smart-phone. The lowest frequency sound that can be recorded with a cell phone microphone isquestionable. Hence, we could attach external microphones into our phone‘s earphone jack to pick up lowfrequency noise.In [1], Smith et.al describe a few acoustical metrics which can be easily run on cell phones with lowcomputational power. It enables users to identify the key frequencies present in the Hum, which tells uswhether there are multiple sources of the Hum. A network of cell-phones can be distributed across thecommunity and used as a ―sound-source locator‖. Future plans also include setting up a cloud storageonline and uploading data to it from our cell phone app. Features that are currently present and that can beadded to the app in future are given in [3]. Noise cancellation using home-theater systems to generate anopposite phase signal which will cancel out the hum on superposition is another project Dr. Smith isworking on.

Orchisama DasAugust 2015THE ‘SOUND RECORDING AND ANALYSIS’ APPLICATIONVERSION 1 FEATURESThe application was initially developed by Adrien Gaspard, Mike Smith and Nicolas Lepine. A keyfeature of this application is the ability to capture and playback sound, so that the user knows that he isnot imagining the Hum, but it actually exists. They went on to do some signal processing with therecorded signal, such as computing its Fourier Transform by doing an FFT to find out which frequenciesare present in the signal. Adrien used the GraphView library to plot the time domain and frequencydomain information of the captured sound signal. This version of the app is to be released soon. All thecode and explanation required to build this app on your cell phone is listed in five parts in Circuit CellarMagazine Articles [4] to be released over the months of July to November, 2015.This version does the bare minimum to give us information about the recorded noise. However, somedesired features are missing, the most important being the ability to store data, so that one can comparebetween two different recordings. The Hum frequency may be changing with time, and this feature isabsolutely necessary to track all its changing signal content. Another disadvantage of this version is thatit is slow. While dealing with GBs of recorded data, this becomes an undesirable feature. These issues aretaken care of in version 2.VERSION 2 FEATURESThis version has been developed by myself, Dr. Smith and Adrien Gaspard. It handles the issues of speedand storage associated with the previous version by storing all the data in a SQLite database [5]. SQLite isthe most widely deployed software library to implement databases on Android. SQLite also has theadvantage of being embedded into every Android device, meaning that no setup procedure is required. Ashort tutorial on working with SQLite in android can be found in [6]. The database stores datapermanently. It will not be lost if the application is closed or if it crashes. It also makes data managementfaster. The last version was slow because we were passing all the data we wanted to plot in our graphsusing an array. In this version, we just read it from the database, and the speed improves significantly.Having our data in a database also allows us to go back and look at a recording from any day, andcompare it with other recordings. We allow the user to look at the results of any captured sound from alist of all captured sounds, and compare it with others.We do some more signal processing with the data. We implement the acoustical metrics defined in [1] toidentify the strongest frequencies in the signal after doing its FFT. The strongest peaks in the signal aretermed as Percentage Worse Case frequencies. These signals stand out from the background noise. Ratio

Orchisama DasAugust 2015Background Noise frequencies contains the frequencies which were overshadowed by the presence of ahigher level of background noise, say during daytime. We then plot histograms of these metrics to findout which frequency occurs the most (likely to be the Hum frequency) using the same GraphView library.The code for calculating the metrics, plotting histograms, and building the UI is explained in theupcoming sections.WORKING WITH ANDROID STUDIOThe IDE we have worked with for developing this app is Android Studio. Android Studio is the newofficial IDE for Android. Version 1 was developed in Eclipse. However, the Application ProgrammingInterface (APIs) released in future will not be available for Eclipse. To get the latest updates, one mustswitch to Android Studio.Android Studio needs to be downloaded from ml#top .Once the .exe file for your windows system (32 bit or 64 bit) has finished dowloading, click on it to run it.In case you don‘t have Java Development Kit (JDK) on your computer, you will be asked to 0.html. Download and runit to install the latest version of JDK. Then proceed to install Android Studio.After installation has finished, you may be prompted to ―Start a New Android Project‖. Double click onit, a ―configure your new project‖ window appears. You are required to give the application a name, let‘scall it ‗Sound Record Analyse‘. Click on ―Next‖, a ―Target Android Devices‖ window appears. Leavethe parameters as they are by default, which is the box ―Phone and Tablet‖ checked, with a minimumSDK of ―API 15: Android 4.0.3 (IceCreamSandwich). Click on ―Next‖ and when offered to ―Add anactivity to Mobile, select ―Blank Activity‖ and click on ―Next‖. Customize the Activity by giving theActivity Name the name ―MainActivity‖, the layout Name ―activity main‖, the title ―MainActivity‖ andthe Menu Resource Name ―menu main‖. You can finally press ―Finish‖.Once installation of Android Studio is complete, you need to download and install the SoftwareDevelopment Kits (SDKs), which can be done by starting the SDK Manager in Android Studio (an iconpresent in the top right hand corner of the screen).

Orchisama DasAugust 2015The list of SDKs to be installed is given in Fig 1. After the SDKs have finished installing, we are ready tocreate our application in Android Studio.Fig 1 – List of SDKs to be installedCODE BEHIND THE APPLICATIONEach new screen that pops up in an android app is called an ‗Activity‘. Each activity is associated with a.xml file which defines the layout (the buttons and the text you see on the screen). The first activity whichgets executed whenever we run the app is the Main Activity (much like the main method in a Java class).From this activity we usually start other activities. In this app we have three most important activities –StartDSP where we capture the sound and analyse it and store the result in a database, DisplayGraphwhere we plot the FFT graph and histograms, and PickHistory in which we create a list of all soundsrecorded so far and let the user choose one so that we can plot its results. In two other activities,MySQLiteDatabaseContract and MySQLiteDatabaseHelper we create the database to store our resultsand write the functions associated with managing it. There are some other xml files in the values folder,such as strings.xml and ints.xml which contain the constants used in many of the activities.

Orchisama DasAugust 2015GOING THROUGH ALL THE ACTIVITIES ONE BY ONE MySQLiteDatabaseContractA database is usually composed of tables, which are in turn composed of many columns known as fields.This class contains the names of all columns and tables we want to put in our database. A classTableEntry implements an interface called ‗BaseColumns‟. In TableEntry we define the names of thetables and columns as String variables. The following is the structure of our database – A table called analysis data stores the result of the analysis – i.e, the Percentage Worse Case andRatio Background Noise frequencies. It has the following fields – ―nameID‖, ―dateTime‖ whichstores the date and time of recorded sound, ―comments‖ which stores any description entered bythe user, ―maximum signal frequency‖ which stores the frequency with the maximum strength,―percentage worse case‖ and ―ratio background noise‖ frequencies. Another table fft data stores the frequency domain information after doing FFT on the signal. Ithas the following fields – ―impulseno‖, which stores the FFT magnitude values of each impulse(we record sound as a number of impulses of 5s each), ―date‖ which stores the date and time ofrecorded sound, same as in analysis data, ―xvals‖ which has the frequency bins, ―yvals‖ whichhas the average of the magnitude spectrum of all impulses and ―comments fft‖ which also storesthe description entered by the user, same as in analysis data.package com.example.orchisamadas.sound record analyse;import android.provider.BaseColumns;public final class MySQLiteDatabaseContract{public MySQLiteDatabaseContract(){}public static abstract class TableEntry implements BaseColumns{//this table stores the analysis resultspublic static final String TABLE NAME "analysis data";public static final String COLUMN NAME "nameID";public static final String COLUMN DATE "dateTime";public static final String COLUMN MAX SIGNAL "maximum signal frequency";public static final String COLUMN PERCENTAGE WORSE CASE "percentage worse Case";public static final String COLUMN RATIO BACKGROUND NOSE "ratio background noise";public static final String COLUMN COMMENT "comments";//this table stores the FFT resultspublic static final String TABLE NAME FFT "fft data";public static final String COLUMN NAME DATE "date";public static final String COLUMN NAME XVALS "xvals";public static final String COLUMN NAME YVALS "yvals";public static final String COLUMN NAME IMPULSE "impulseno";public static final String COLUMN NAME COMMENT "comments fft";}}Listing 1 – MySQLiteDatabaseContract.java

Orchisama DasAugust 2015 MySQLiteDatabaseHelperThis is a child class of SQLiteOpenHelper [7] which contains basic database management functions likeonCreate(), onUpgrade() and onOpen() to create, upgrade and open the database. In this class, functionsare written/overridden to create, delete and upgrade our database called ―SoundAnalysisResults.db‖.package com.example.orchisamadas.sound record analyse;import android.content.Context;import android.database.sqlite.SQLiteDatabase;import android.database.sqlite.SQLiteOpenHelper;import com.example.orchisamadas.sound record analyse.MySQLiteDatabaseContract.TableEntry;public class MySQLiteDatabaseHelper extends SQLiteOpenHelper{public static final String NAME "SoundAnalysisResults.db";public static final int VERSION 1;public static Context mContext;public MySQLiteDatabaseHelper(Context context){super(context,NAME,null,VERSION);mContext context;}@Overridepublic void onCreate(SQLiteDatabase db) {//this table stores analysis resultsString create "CREATE TABLE IF NOT EXISTS " TableEntry.TABLE NAME " (" TableEntry. ID " INTEGER PRIMARY KEY AUTOINCREMENT, " TableEntry.COLUMN NAME " TEXT, " TableEntry.COLUMN COMMENT " TEXT, " TableEntry.COLUMN DATE " TEXT, " TableEntry.COLUMN MAX SIGNAL " REAL, " TableEntry.COLUMN PERCENTAGE WORSE CASE " REAL, " TableEntry.COLUMN RATIO BACKGROUND NOSE " REAL)";db.execSQL(create);//this table stores FFT resultscreate "CREATE TABLE IF NOT EXISTS " TableEntry.TABLE NAME FFT " (" TableEntry. ID " INTEGER PRIMARY KEY AUTOINCREMENT, " TableEntry.COLUMN NAME DATE " TEXT, " TableEntry.COLUMN NAME COMMENT " TEXT, " TableEntry.COLUMN NAME XVALS " BLOB, " TableEntry.COLUMN NAME YVALS " BLOB";int numImpulses mContext.getResources().getInteger(R.integer.num impulses);for(int k 0; k numImpulses; k )create create ", " TableEntry.COLUMN NAME IMPULSE Integer.toString(k) " BLOB)";db.execSQL(create);}public void deleteAllEntries(SQLiteDatabase db,String tableName){db.delete(tableName, null, null);}public void verridepublic void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion) {if (newVersion turn;}}Listing 2 – MySQLiteDatabaseHelper.java

Orchisama DasAugust 2015The onCreate() method is executed first. This creates the two tables in our database – analysis data andfft data. The String ‗create‘ contains the SQL command for creating a table (if it does not previouslyexist), with the given fields. TableEntry. ID has the unique row ID for each row of a column. It is autoincremented. As expected, the other columns are of type ‗TEXT‘ (to store strings) and ‗REAL‘ (to storefloating point numbers). Another data type ‗BLOB‘ is used to store the result for fft data. This is becauseSQLite databases cannot store arrays of double. Instead, they use Binary Large Object, BLOBs, which area collection of binary data stored as a single entity. As mentioned before, sound is recorded in a numberof impulses of 5s each. The FFT magnitude values of each impulse is stored in a separate column – calledimpulse0, impulse1, and so on. The column ‗yvals‘ stores the average of FFT magnitude values of all theimpulses.The other methods, deleteAllEntries() deletes a particular table of the database and deleteDatabase()deletes the entire database itself. onUpgrade() method is called whenever the database version isincreased. We may want to do so if we want to change the structure of the database, i.e., add new tables orcolumns to existing tables. It simply deletes the old database and creates a new one. MainActivityThis is the first activity that gets executed when we launch the application. We must first write its layout.The layout is written in activity main.xml file (listing 3A). It is a simple layout that contains threebuttons, placed one below another - Record New Data, View Frequency Graphs and View AnalysisResults. (We refer to the buttons by their ids, the text to be written in them is given in the strings.xml file,which I will add at the end of this document.) Pressing ‗Record New Data‟ will start the activityStartDSP which captures sound and analyses it. ‗View Frequency Graphs‟ will show us the FFT results(gotoGraphFFT) and ‗View Analysis Results‟ will show us the histograms (gotoHistogram).The MainActivity (listing 3B) contains calls to other activities using something called an intent. AnAndroid intent is an abstract description of an operation to be performed. It can be usedwith startActivity to launch an Activity. We launch the activities, StartDSP or DisplayGraph dependingon the button pressed by the user. We can use a Bundle to pass some values to the activity we are starting.In this case, DisplayGraph will either plot FFT or a histogram depending on the button pressed. Pressing‗View Frequency Graphs‘ will display the FFT graph whereas pressing ‗View Analysis Results‘ willdisplay the analysis histogram. The information regarding which button has been pressed needs to beconveyed to the DisplayGraph activity by the MainActivity by using a bundle.

Orchisama DasAugust 2015 RelativeLayoutxmlns:android tools "http://schemas.android.com/tools"android:layout width "fill parent"android:layout height "fill parent" Buttonandroid:id "@ id/btnStartDSP"android:layout width "wrap content"android:layout height "wrap content"android:layout marginTop "40dp"android:layout centerVertical "false"android:layout centerHorizontal "true"android:text "@string/start dsp"android:onClick "StartDSP"/ Buttonandroid:id "@ id/graph FFT"android:layout width "wrap content"android:layout height "wrap content"android:layout below "@ id/btnStartDSP"android:layout centerHorizontal "true"android:text "@string/graph FFT"android:onClick "gotoGraphFFT" / Buttonandroid:id "@ id/graph histogram"android:layout width "wrap content"android:layout height "wrap content"android:layout below "@ id/graph FFT"android:layout centerHorizontal "true"android:text "@string/graph histogram"android:onClick "gotoHistogram" / /RelativeLayout Listing 3A – activity main.xmlpackage com.example.orchisamadas.sound record analyse;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.ActionBarActivity;import android.view.View;public class MainActivity extends ActionBarActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) (R.layout.activity main);}public void StartDSP(View v){Fig 2 – MainActivity screen

Orchisama DasAugust 2015Intent intent new }/*Starts the activity DisplayGraph to view previous graphsWe can either view previous FFT graphs or previous analysis histogramsdepending on which button is pressed */public void gotoGraphFFT(View v){Bundle bundle new Bundle();bundle.putString("button pressed", "1");Intent intent new Intent(this, Activity(intent);}public void gotoHistogram(View v){Bundle bundle new Bundle();bundle.putString("button pressed", "2");Intent intent new Intent(this, Activity(intent);}}Listing 3B – MainActivity.java StartDSP ActivityIn this activity, we capture sound and do signal processing on it – obtain the frequency spectrum by doingan FFT [8] and then calculate the metrics described in [1]. I will first describe sound capture, followed bythe analysis method and storage in database. Listing 4 gives the layout for StartDSP activity.In the onCreate() method, we create a media player object called ‗boo‘. It is basically a chirp that goesfrom 50Hz to 1000Hz in a duration of 5s (Chirp 50 1000Hz.wav). We let the user have the option ofplaying this chirp in case he wants to excite a room resonance. We must create a folder called ‗raw‘ in the‗res‘ directory containing ‗boo.wav‘.Next we open the database, ―SoundAnlysisResults.db‖ so that we can write data into it.onOptionsSelectedMenu() lets us add a menu at the top right hand corner of the screen. I just want to adda play button here so that on pressing it, the user can play ‗boo.wav‘. The layout for this menu is given inmenu start dsp.xml (listing 5B). The method ‗startPlaying()‘ is executed when the user when userpresses the play button on the menu. The chirp must be stored in the phone‘s memory/SD card beforeplaying it (create ‗MySounds‘ folder in the phone‘s storage directory from your computer and pasteChirp 50 1000Hz.wav in it).

Orchisama DasAugust 2015 RelativeLayoutxmlns:android s:tools nd "@drawable/dsp"android:layout width "fill parent"android:layout height "fill parent"tools:context " {relativePackage}. {activityClass}" TextViewandroid:id "@ id/remaining impulses"android:layout width "wrap content"android:layout height "wrap content"android:layout centerHorizontal "true"android:layout centerVertical "true"/ TextViewandroid:id "@ id/textViewTime"android:layout width "wrap content"android:layout height "wrap content"android:layout above "@id/remaining impulses"android:layout marginBottom "17dp"android:textSize "25sp"android:layout centerHorizontal "true"android:layout centerVertical "true"/ ImageButtonandroid:id "@ id/playback"android:layout width "wrap content"android:layout height "wrap content"android:layout centerHorizontal "true"android:layout centerVertical "true"android:layout above "@id/textViewTime"android:src "@drawable/ic play arrow black 24dp"android:visibility "invisible"/ EditTextandroid:id "@ id/Addcomment"android:layout centerHorizontal "true"android:layout centerVertical "true"android:layout width "wrap content"android:layout height "wrap content"android:layout alignParentStart "true"android:layout alignParentLeft "true"android:hint "Comment"android:layout marginLeft "20dp" / ImageButtonandroid:id "@ id/Enter"android:layout centerHorizontal "true"android:layout centerVertical "true"android:layout width "wrap content"android:layout height "wrap content"

Orchisama DasAugust 2015android:layout alignParentRight "true"android:layout alignParentEnd "true"android:layout marginRight "20dp"android:src "@drawable/ic done black 24dp" / ProgressBarandroid:id "@ id/computation progress"style layout width "wrap content"android:layout height "wrap content"android:layout centerVertical "true"android:layout centerHorizontal "true"android:indeterminate "false"android:max "100"android:progress "0"android:visibility "invisible"/ TextViewandroid:id "@ id/analysing"android:layout width "wrap content"android:layout height "wrap content"android:layout centerHorizontal "true"android:layout centerVertical "true"android:layout above "@id/computation progress"android:visibility "invisible"/ Buttonandroid:id "@ id/btnDisplayGraph"android:layout width "wrap content"android:layout height "wrap content"android:layout centerVertical "true"android:layout centerHorizontal "true"android:layout below "@id/computation progress"android:text "@string/view fft result"android:onClick "DisplayGraph"android:visibility "invisible"/ Buttonandroid:id "@ id/btnDisplayHistogram"android:layout width "wrap content"android:layout height "wrap content"android:layout centerVertical "true"android:layout centerHorizontal "true"android:layout below "@id/btnDisplayGraph"android:text "@string/view analysis result"android:onClick "DisplayGraph"android:visibility "invisible"/ /RelativeLayout Listing 4 – activity start dsp.xmlFig 3 – StartDSP layouts

Orchisama DasAugust 2015package com.example.orchisamadas.sound record analyse;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.nio.ByteBuffer;import java.util.ArrayList;import java.util.Collections;import java.util.Date;import java.util.HashSet;import java.util.List;import java.util.Set;import java.util.concurrent.TimeUnit;import android.content.ContentValues;import android.content.Context;import android.content.Intent;import android.database.sqlite.SQLiteDatabase;import android.media.AudioFormat;import android.media.AudioManager;import android.media.AudioRecord;import android.media.AudioTrack;import android.media.MediaPlayer;import android.media.MediaRecorder.AudioSource;import android.os.AsyncTask;import android.os.Bundle;import android.os.CountDownTimer;import android.os.Environment;import android.support.v7.app.ActionBarActivity;import android.text.format.DateFormat;import android.util.Log;import android.view.MenuItem;import android.view.View;import android.view.inputmethod.InputMethodManager;import android.widget.Button;import android.widget.EditText;import android.widget.ImageButton;import android.widget.ProgressBar;import android.widget.TextView;import android.widget.Toast;import com.example.orchisamadas.sound record analyse.MySQLiteDatabaseContract.TableEntry;public class StartDSP extends ActionBarActivity {TextView TextHandleRemainingImpulses;AudioRecord recorder;CaptureAudio captureAudio;TextView textViewTime;String title;EditText comment;

Orchisama DasAugust 2015ImageButton done;final CounterClass timer new CounterClass(5000, 1000);private static final double REFSPL 0.00002;private MediaPlayer mPlayer null;private MediaPlayer mediaPlayer;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);mediaPlayer MediaPlayer.create(this, R.raw.boo);setContentView(R.layout.activity start dsp);MySQLiteDatabaseHelper databaseHelper new MySQLiteDatabaseHelper(StartDSP.this);//open or create databaseSQLiteDatabase db eDirectory() File.separator databaseHelper.NAME, MODE PRIVATE, null);databaseHelper.onCreate(db);}//play chirp when play button is pressed.public boolean onOptionsItemSelected(MenuItem item){//Handle presses on the action bar itemsswitch(item.getItemId()){case R.id.GenerateChirp:startPlaying();return true;default:return super.onOptionsItemSelected(item);}}public void startPlaying(){mPlayer new t.getExternalStorageDirectory().getAbsolutePath() "/MySounds/Chirp 50 tch(IOException e){}}@Overrideprotected void onStart(){super.onStart();//allow user to enter titlecomment (EditText) findViewById(R.id.Addcomment);done (ImageButton) his, "Add a small description of the noise you're hearing",Toast.LENGTH SHORT).show();done.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {title comment.getText().toString();if(title null)title " ";//close virtual keyboardInputMethodManager inputManager (InputMethodManager)getSystemService(Context.INPUT METHOD urrentFocus().getWindowToken(),

Orchisama DasAugust 2015InputMethodManager.HIDE NOT ALWAYS);Toast.makeText(StartDSP.this, "Description saved", Toast.LENGTH ainingImpulses (TextView)findViewById(R.id.remaining esources().getString(R.string.remaining impulse leadtext) er.num impulses)));textViewTime udio new CaptureAudio(); captureAudio.execute();}});}@Overrideprotected void onPause(){if(captureAudio ! nish();}//countdown timer to show recording time remainingpublic class CounterClass extends CountDownTimer {public CounterClass(long millisInFuture, long countDownInterval) {super(millisInFuture, countDownInterval);}@Overridepublic void onFinish() {textViewTime.setText("Captured");}@Overridepublic void onTick(long millisUntilFinished) {long millis millisUntilFinished;String hms String.format("%02d", TimeUnit.MILLISECONDS.toSeconds(millis) ViewTime.setText(hms);}}Listing 5A – StartDSP.java setting up sound recording menu xmlns:android app ls "http://schemas.android.com/tools"tools:context "com.example.orchisamadas.sound record analyse.StartDSP" itemandroid:id "@ id/GenerateChirp"android:icon "@drawable/ic play arrow black 24dp"app:showAsAction "always"android:title "@string/audio play"/ /menu Listing 5B – menu start dsp.xml

Orchisama DasAugust 2015The onStart() method is executed first. We let the user input a comment about the sound he is about tocapture, which we save in a String called ‗title‘. To do so, we add an EditText widget beside a TextViewwidget, as given in listing 4. Once the user finishes inserting the description, we display the informationabout recording time and number of impulses remaining. We then call the CaptureAudio class (listing5C) to start recording.CounterClass generates a timer to countdown from 5s whenever we are recording an impulse. In thelayout file activity start dsp.xml (listing 4) we add a TextView widget, ‗textViewTime‘ which shows therecording time remaining. We modify ‗textViewTime‘ in CounterClass every second to show thecountdown. On finishing recording all impluses, ‗textViewTime‘ shows the text ‗Captured‘.

Each new screen that pops up in an android app is called an ‗Activity‘. Each activity is associated with a .xml file which defines the layout (the buttons and the text you see on the screen). The first activity which gets executed whenever we run the app is the M