public double getAmplitude() { if (mRecorder != null && started) { return (mRecorder.getMaxAmplitude() / 2700.0); } else { return 0; } }
public void run() { // int vuSize = 10 * mMediaRecorder.getMaxAmplitude() / 32768; int ratio = mr.getMaxAmplitude() / BASE; int db = (int) (20 * Math.log10(Math.abs(ratio))); int value = db / RATIO; if (value < 0) value = 0; if (soundAmplitudeListen != null) soundAmplitudeListen.amplitude(ratio, db, value); mHandler.postDelayed(mUpdateMicStatusTimer, postDelayed); }
/** * Returns the largest amplitude sampled since the last call to this method. * * @return returns the largest amplitude since the last call, or 0 when not in recording state. */ public int getMaxAmplitude() { if (state == State.RECORDING) { try { return mRecorder.getMaxAmplitude(); } catch (IllegalStateException e) { return 0; } } else { return 0; } }
public double getAmplitude() { if (recorder != null) { try { return (recorder.getMaxAmplitude()); } catch (Exception e) { return 0; } } else { return 0; } }
private void updateMicStatus() { if (System.currentTimeMillis() - lastUpdate >= 1000) { if (onRecordTimeChangeListener != null) { onRecordTimeChangeListener.onRecordTimeCallback( (System.currentTimeMillis() - startTime) / 1000); } lastUpdate = System.currentTimeMillis(); } if (recorder != null) { double ratio = (double) recorder.getMaxAmplitude() / BASE; double db = 0; // 分贝 if (ratio > 1) db = 20 * Math.log10(ratio); mRadius = (float) db; invalidate(); mHandler.postDelayed(mUpdateMicStatusTimer, SPACE); } }
/** * Returns the largest amplitude sampled since the last call to this method. * * @return returns the largest amplitude since the last call, or 0 when not in recording state. */ public int getMaxAmplitude() { if (state == State.RECORDING) { if (rUncompressed) { int result = cAmplitude; cAmplitude = 0; return result; } else { try { return mediaRecorder.getMaxAmplitude(); } catch (IllegalStateException e) { return 0; } } } else { return 0; } }
public void button2Click(View v) throws IOException, IllegalStateException { MediaRecorder recorder; recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile("/dev/null"); try { recorder.prepare(); Log.d(LOG_TAG, "RECORDER Ok "); } catch (IOException e) { Log.d(LOG_TAG, "Error WITH RECORDER " + e); e.printStackTrace(); } recorder.start(); Log.d(LOG_TAG, "Start "); for (int i = 0; i < 20; i++) { // System.err.println("current amplitude is:"+recorder.getMaxAmplitude()); // System.err.println("current amplitude is:"+recorder.getMaxAmplitude()); // textView1.setText("current MIC amplitude is:"+"_"+recorder.getMaxAmplitude()); maxAmplitude = recorder.getMaxAmplitude(); Log.d(LOG_TAG, "MaxAmplitude = " + maxAmplitude); if (maxAmplitude > 20000) { sp.play(soundCuckoo, 1, 1, 0, 1, 1); try { Thread.sleep(2000); } catch (Exception e) { Log.d(LOG_TAG, "Error " + e); } } try { Thread.sleep(1000); } catch (Exception e) { Log.d(LOG_TAG, "Error " + e); } } try { recorder.stop(); } catch (Exception e) { Log.d(LOG_TAG, "Error " + e); } recorder.reset(); recorder.release(); }
private void updateMicStatus() { if (mMediaRecorder == null) { return; } if (mRvRecord == null) { return; } int m = mMediaRecorder.getMaxAmplitude(); int x = (6 * m / 32768); // 通过这种算法计算出的音量大小在1-7之间 switch (x) { case 1: mRvRecord.setmClipSize(330); mRvRecord.invalidate(); break; case 2: mRvRecord.setmClipSize(210); mRvRecord.invalidate(); break; case 3: mRvRecord.setmClipSize(190); mRvRecord.invalidate(); break; case 4: mRvRecord.setmClipSize(100); mRvRecord.invalidate(); break; case 5: mRvRecord.setmClipSize(60); mRvRecord.invalidate(); break; case 6: mRvRecord.setmClipSize(30); mRvRecord.invalidate(); break; case 7: mRvRecord.setmClipSize(0); mRvRecord.invalidate(); break; default: mRvRecord.setmClipSize(500); mRvRecord.invalidate(); break; } }
@Override protected Void doInBackground(MediaRecorder... params) { /*开始录音*/ MediaRecorder tmpMediaRecorder = params[0]; tmpMediaRecorder.start(); tmpMediaRecorder.setOnInfoListener( new OnInfoListener() { @Override public void onInfo(MediaRecorder mr, int what, int extra) { // TODO Auto-generated method stub if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) { isMonitorRun = false; } } }); /*开始监控*/ isMonitorRun = true; while (isMonitorRun) { int sVolumeValue = tmpMediaRecorder.getMaxAmplitude(); if (sVolumeValue > 0) { mVolumeSize = 1000 * sVolumeValue / 32768; mHandler.postAtTime( new Runnable() { @Override public void run() { // TODO Auto-generated method stub mViewVolume.setText(mVolumeSize + ""); } }, 500); } } /*停止录音*/ tmpMediaRecorder.stop(); tmpMediaRecorder.release(); tmpMediaRecorder = null; mCountDownTimer.cancel(); // 停止计时 return null; }
public void run() { int amplitude = mRecorder.getMaxAmplitude(); String debugTxt = ""; debugTxt = scaleGrayGradiance(amplitude, R.drawable.gray, 25000, 320, 350); // txv_debug.setTag(debugTxt); }
public double getAmplitude() { if (mRecorder != null) return (mRecorder.getMaxAmplitude() / 2700.0); else return 0; }
/** * M: get the current amplitude of MediaRecorder, used by VUMeter * * @return the amplitude value */ public int getMaxAmplitude() { synchronized (this) { if (null == mRecorder) { return 0; } return (SoundRecorderService.STATE_RECORDING != mCurrentState) ? 0 : mRecorder.getMaxAmplitude(); } }