List of usage examples for android.media AudioTrack AudioTrack
private AudioTrack(AudioAttributes attributes, AudioFormat format, int bufferSizeInBytes, int mode, int sessionId, boolean offload) throws IllegalArgumentException
From source file:com.cypress.cysmart.RDKEmulatorView.RemoteControlEmulatorFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { /**/* w w w .j ava2 s . c om*/ * Getting the current orientation of the screen * Loading different view for LandScape and portrait */ int currentOrientation = getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { mParentView = inflater.inflate(R.layout.rdk_emulator_view_landscape, container, false); } else { mParentView = inflater.inflate(R.layout.rdk_emulator_view_portrait, container, false); } mProgressDialog = new ProgressDialog(getActivity()); /** * Getting the ID's of all Emulator view UI elements */ Button mTrackpadView = (Button) mParentView.findViewById(R.id.trackpad_btn); Button mMicrophoneView = (Button) mParentView.findViewById(R.id.microphone_btn); mVolumePlusbtn = (ImageButton) mParentView.findViewById(R.id.volume_plus_btn); mVolumeMinusBtn = (ImageButton) mParentView.findViewById(R.id.volume_minus_btn); mChannelPlusBtn = (ImageButton) mParentView.findViewById(R.id.channel_plus_btn); mChannelMinusBtn = (ImageButton) mParentView.findViewById(R.id.channel_minus_btn); mLeftBtn = (ImageButton) mParentView.findViewById(R.id.left_btn); mRightBtn = (ImageButton) mParentView.findViewById(R.id.right_btn); mBackBtn = (ImageButton) mParentView.findViewById(R.id.back_btn); mGesturebtn = (ImageButton) mParentView.findViewById(R.id.gesture_btn); mExitBtn = (ImageButton) mParentView.findViewById(R.id.exit_btn); mPowerBtn = (ImageButton) mParentView.findViewById(R.id.power_btn); mRecBtn = (ImageButton) mParentView.findViewById(R.id.record_btn); mRecBtn = (ImageButton) mParentView.findViewById(R.id.record_btn); /** * AudioTrack class initialisation as follows * streamType- AudioManager.STREAM_MUSIC, * sampleRateInHz- 16000, * channelConfig- AudioFormat.CHANNEL_OUT_MONO, * audioFormat-AudioFormat.ENCODING_PCM_16BIT, * bufferSizeInBytes-8000, * mode- AudioTrack.MODE_STREAM * */ mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, SAMPLE_RATE, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, BUFFER_SIZE, AudioTrack.MODE_STREAM); /** * TrackPAd button click listner */ mTrackpadView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { TrackpadEmulatorFragment trackpadService = new TrackpadEmulatorFragment(); try { displayView(trackpadService); } catch (Exception e) { e.printStackTrace(); } } }); /** * Microphone Button click listner */ mMicrophoneView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { MicrophoneEmulatorFragment microphoneService = new MicrophoneEmulatorFragment(); microphoneService.create(mservice); displayView(microphoneService); } }); return mParentView; }
From source file:org.noise_planet.noisecapture.CalibrationLinearityActivity.java
private void playNewTrack() { double rms = dbToRms(99 - (splLoop++) * DB_STEP); short[] data = makeWhiteNoiseSignal(44100, rms); double[] fftCenterFreq = FFTSignalProcessing .computeFFTCenterFrequency(AudioProcess.REALTIME_SAMPLE_RATE_LIMITATION); FFTSignalProcessing fftSignalProcessing = new FFTSignalProcessing(44100, fftCenterFreq, 44100); fftSignalProcessing.addSample(data); whiteNoisedB = fftSignalProcessing.computeGlobalLeq(); freqLeqStats.add(new LinearCalibrationResult(fftSignalProcessing.processSample(true, false, false))); LOGGER.info("Emit white noise of " + whiteNoisedB + " dB"); if (audioTrack == null) { audioTrack = new AudioTrack(getAudioOutput(), 44100, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, data.length * (Short.SIZE / 8), AudioTrack.MODE_STATIC); } else {/* w w w . j av a 2 s. c o m*/ try { audioTrack.pause(); audioTrack.flush(); } catch (IllegalStateException ex) { // Ignore } } audioTrack.setLoopPoints(0, audioTrack.write(data, 0, data.length), -1); audioTrack.play(); }