Android mobile phone Mic on sound perception

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Making making this time made a Android mobile phone using mic to capture the environment volume small Dongdong, multi query, all kinds of research, now put these together with the kids to share things, such as insufficient or error, but also hope it give advice.

Making making making Android can achieve the recording function of AudioRecord and MediaRecorder, where AudioRecord is the Mic read the audio stream, while recording and analysis of flow data; and the MediaRecorder is able to directly to Mic data stored in the file, and can perform code (such as AMR, MP3 etc.).

Making making making first, will your application add authority (whether you are using the AudioRecord or MediaRecorder):

                 <uses-permission android:name="android.permission.RECORD_AUDIO" />

Making making making then, separately introduced the usage.


        1, The new recording sampling class, interface:

             public class MicSensor implements AudioRecord.OnRecordPositionUpdateListener

        2, On the AudioRecord initialization:

             public AudioRecord (int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes)

             audioSource: Making making making making making making making audio source (for example: MediaRecorder.AudioSource.MIC making specified for Mic audio source)

             sampleRateInHz: Making making making making the default sampling frequency, the unit Hz. (commonly used such as 44100Hz, 22050Hz, 16000Hz, 11025Hz, 8000Hz, some people say 44100Hz is the guarantee in all Android mobile phone manufacturers can use sampling frequency, but the individual in the Samsung i9000 but otherwise, by testing the 8000Hz seems to be more reliable) making

            channelConfig: Making making making making making describes audio channel set. (I use AudioFormat.CHANNEL_CONFIGURATION_MONO)

            audioFormat: Making making making making making making audio data format support. (this seems to track, PCM recording 16bit should be double track, the so-called 8bit PCM recording is mono. AudioFormat.ENCODING_PCM_16BIT, AudioFormat.ENCODING_PCM_8BIT)

           bufferSizeInBytes: Making making making in the recording process, the total number of audio data is written to the buffer (byte). New audio data will be read from the buffer is less than this value. GetMinBufferSize (int, int, int) minimum buffer to return the AudioRecord instance created after the success of the. Set the value of getMinBufferSize is smaller than () will lead to initialization failed.

       3, Initialization after the success can start recording making audioRecord.startRecording()

       4, Write the thread class recording data into the buffer, analysis

             short[] buffer = new short[bufferSize];              //Short type corresponds to 16bit audio data formats, byte type corresponding to the 8bit
   , 0, bufferSize);            //The return value is a int data type length value

      5, According to the data in the buffer of some description:

Making making making making making such data is read in time domain data, used to calculate directly without any practical significance. The time domain data needs to be converted into frequency domain data, to resort to computing.

Making making making making making frequency (frequency domain) refers to the analysis of the function or signal, the frequency analysis and the relevant part, and not related to time part.

Making making making making making function or signal can be through a mathematical operator between time domain and frequency domain conversion. For example, Fu Liye transform can be a time domain signal into amplitude and phase corresponding to different frequency, the spectrum is a time-domain signal in frequency domain, and the inverse Fu Liye transform can be converted back to the time domain signal spectrum.

Graphics making making making making making signal in time domain can show how signal change with time, and the signal in the frequency domain graph (commonly known as the spectrum) can display the frequency at which the signal distribution and the proportion of. The frequency domain representation of each frequency in size, phase will also have each frequency, the amplitude and phase information can be sine wave frequency given the magnitude and phase angle, adding later can restore the original signal.

The complex array of making making making making making Fu Liye change is obtained by a two-dimensional array, the real and imaginary parts of the square and logarithmic, multiplied by 10 is approximately equal to the volume of the DB we usually said.


Making making making making relative to AudioRecord, MediaRecorder provides a simpler API.

[java] view plaincopy  

  1.               mediaRecorder = new MediaRecorder();  
  2. mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);  
  3. mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);  
  4. mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);  
  5. mediaRecorder.setOutputFile("/dev/null");    

Each attribute making making making making set mediaRecorder, then thread calls for making mediaRecorder.getMaxAmplitude();

Making making making making making get is the maximum amplitude of direct instantaneous, logarithmic and then multiplied by 10 to characterize the DB.

Making making making making making finally need to explain, Android mobile phone manufacturers customized hardware is not the same, only "characterization" values so obtained by mic, and cannot take over when the real basis. Although they are intelligent mobile phone, but also is the mobile phone, the robot is not! Ha-ha. . .

Making making making making making right, each mobile phone mic conversion in the acoustic signal and have done to the capacitor protection, not by the external environment is too noisy and prone to damage. So the ultrasound and sound, we do not easily accept voice, mobile phone will not hear.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Debra at December 14, 2013 - 3:45 AM