private AudioTrack initializeKeepSessionIdAudioTrack(int audioSessionId) { int sampleRate = 4000; // Equal to private AudioTrack.MIN_SAMPLE_RATE. int channelConfig = AudioFormat.CHANNEL_OUT_MONO; @C.PcmEncoding int encoding = C.ENCODING_PCM_16BIT; int bufferSize = 2; // Use a two byte buffer, as it is not actually used for playback. return new AudioTrack(C.STREAM_TYPE_DEFAULT, sampleRate, channelConfig, encoding, bufferSize, MODE_STATIC, audioSessionId); }
AndroidAudioDevice (int samplingRate, boolean isMono) { this.isMono = isMono; int minSize = AudioTrack.getMinBufferSize(samplingRate, isMono ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT); track = new AudioTrack(AudioManager.STREAM_MUSIC, samplingRate, isMono ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, minSize, AudioTrack.MODE_STREAM); track.play(); latency = minSize / (isMono ? 1 : 2); }
AndroidAudioDevice (int samplingRate, boolean isMono) { this.isMono = isMono; int minSize = AudioTrack.getMinBufferSize(samplingRate, isMono ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT); track = new AudioTrack(AudioManager.STREAM_MUSIC, samplingRate, isMono ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, minSize, AudioTrack.MODE_STREAM); track.play(); latency = minSize / (isMono ? 1 : 2); }
if (audioSessionId == C.AUDIO_SESSION_ID_UNSET) { audioTrack = new AudioTrack( streamType, outputSampleRate, new AudioTrack( streamType, outputSampleRate,
@TargetApi(21) private AudioTrack createAudioTrackV21() { android.media.AudioAttributes attributes; if (tunneling) { attributes = new android.media.AudioAttributes.Builder() .setContentType(android.media.AudioAttributes.CONTENT_TYPE_MOVIE) .setFlags(android.media.AudioAttributes.FLAG_HW_AV_SYNC) .setUsage(android.media.AudioAttributes.USAGE_MEDIA) .build(); } else { attributes = audioAttributes.getAudioAttributesV21(); } AudioFormat format = new AudioFormat.Builder() .setChannelMask(outputChannelConfig) .setEncoding(outputEncoding) .setSampleRate(outputSampleRate) .build(); int audioSessionId = this.audioSessionId != C.AUDIO_SESSION_ID_UNSET ? this.audioSessionId : AudioManager.AUDIO_SESSION_ID_GENERATE; return new AudioTrack(attributes, format, bufferSize, MODE_STREAM, audioSessionId); }
/** * AudioFormat.CHANNEL_OUT_MONO * AudioFormat.ENCODING_PCM_16BIT * * @param bufferSize user may want to write data larger than minBufferSize, so they should able * to increase it */ public synchronized void init(int sampleRate, int channelConfig, int audioFormat, int bufferSize) { if (mAudioTrack != null) { mAudioTrack.release(); mAudioTrack = null; } int minBufferSize = AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat); mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, channelConfig, audioFormat, Math.max(minBufferSize, bufferSize), AudioTrack.MODE_STREAM); mAudioTrack.play(); }
public int audioTrackInit() { // Log.e(" ffff mediaplayer audiotrackinit start . sampleRateInHz:=" + sampleRateInHz + " channels:=" + channels ); audioTrackRelease(); int channelConfig = channels >= 2 ? AudioFormat.CHANNEL_OUT_STEREO : AudioFormat.CHANNEL_OUT_MONO; try { mAudioTrackBufferSize = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT); mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT, mAudioTrackBufferSize, AudioTrack.MODE_STREAM); } catch (Exception e) { mAudioTrackBufferSize = 0; Log.e("audioTrackInit", e); } return mAudioTrackBufferSize; }
audioTrack = new AudioTrack( AudioManager.STREAM_MUSIC, SAMPLING_RATE,
AudioTrack makeAudioTrack() { return new AudioTrack( STREAM_TYPE, SAMPLE_RATE, CHANNEL_CONFIG, AUDIO_FORMAT, BUF_BYTES, AudioTrack.MODE_STREAM); }
public void init(int sampleRateInHz, int channels, int samples) { Log.d(TAG, sampleRateInHz + ", " + channels + ", " + samples + "=>" + channels * samples); int minBufferSize = AudioTrack.getMinBufferSize(sampleRateInHz, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT); mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRateInHz, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, Math.max(minBufferSize, channels * samples * 2), AudioTrack.MODE_STREAM); }
public AudioRecorder(Integer sampleRate, Integer bufferRate, FileOutputStream file) { Integer bufferSize = AudioTrack.getMinBufferSize(sampleRate, AudioFormat.CHANNEL_OUT_MONO, android.media.AudioFormat.CHANNEL_OUT_MONO) * 2; track = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, AudioFormat.CHANNEL_OUT_MONO, android.media.AudioFormat.ENCODING_PCM_16BIT, bufferSize, AudioTrack.MODE_STREAM); this.file = file; //track.play(); }
private void initializeAndroidAudio(int sampleRate) throws Exception { int minBufferSize = AudioTrack.getMinBufferSize(sampleRate, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT); if (minBufferSize < 0) { throw new Exception("Failed to get minimum buffer size: " + Integer.toString(minBufferSize)); } track = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, minBufferSize, AudioTrack.MODE_STREAM); }
public AudioPlayer(File file) { int sampleRate = SampleRateCalculator.getMaxSupportedSampleRate(); Integer bufferSize = AudioTrack.getMinBufferSize(sampleRate, AudioFormat.CHANNEL_OUT_MONO, android.media.AudioFormat.CHANNEL_OUT_MONO) * 2; track = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize, AudioTrack.MODE_STREAM); this.file = file; }
/** * Prepare the AudioTrack instance * * @param samplingRate the sampling rate of AudioTrack * @return AudioTrack */ private static @NonNull AudioTrack prepareAudioTrack(int samplingRate) { AudioTrack result = new AudioTrack(AudioManager.STREAM_MUSIC, samplingRate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, AudioTrack.getMinBufferSize(samplingRate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT), AudioTrack.MODE_STREAM); result.setStereoVolume(1f, 1f); result.play(); return result; }
/** * Prepare the AudioTrack instance * * @param samplingRate the sampling rate of AudioTrack * @return AudioTrack */ private static @NonNull AudioTrack prepareAudioTrack(int samplingRate) { AudioTrack result = new AudioTrack(AudioManager.STREAM_MUSIC, samplingRate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, AudioTrack.getMinBufferSize(samplingRate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT), AudioTrack.MODE_STREAM); result.setStereoVolume(1f, 1f); result.play(); return result; }
/** * Prepare the AudioTrack instance * * @param samplingRate the sampling rate of AudioTrack * @return AudioTrack */ private static @NonNull AudioTrack prepareAudioTrack(int samplingRate) { AudioTrack result = new AudioTrack(AudioManager.STREAM_MUSIC, samplingRate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, AudioTrack.getMinBufferSize(samplingRate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT), AudioTrack.MODE_STREAM); result.setStereoVolume(1f, 1f); result.play(); return result; } }
private int audioTrackInit(int sampleRateInHz, int channels) { audioTrackRelease(); int channelConfig = channels >= 2 ? AudioFormat.CHANNEL_OUT_STEREO : AudioFormat.CHANNEL_OUT_MONO; try { mAudioTrackBufferSize = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT); mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT, mAudioTrackBufferSize, AudioTrack.MODE_STREAM); } catch (Exception e) { mAudioTrackBufferSize = 0; Log.e("audioTrackInit", e); } return mAudioTrackBufferSize; }
public int audioTrackInit() { // Log.e(" ffff mediaplayer audiotrackinit start . sampleRateInHz:=" + sampleRateInHz + " channels:=" + channels ); audioTrackRelease(); int channelConfig = channels >= 2 ? AudioFormat.CHANNEL_OUT_STEREO : AudioFormat.CHANNEL_OUT_MONO; try { mAudioTrackBufferSize = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT); mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT, mAudioTrackBufferSize, AudioTrack.MODE_STREAM); } catch (Exception e) { mAudioTrackBufferSize = 0; Log.e("audioTrackInit", e); } return mAudioTrackBufferSize; }
public int audioTrackInit() { // Log.e(" ffff mediaplayer audiotrackinit start . sampleRateInHz:=" + sampleRateInHz + " channels:=" + channels ); audioTrackRelease(); int channelConfig = channels >= 2 ? AudioFormat.CHANNEL_OUT_STEREO : AudioFormat.CHANNEL_OUT_MONO; try { mAudioTrackBufferSize = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT); mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT, mAudioTrackBufferSize, AudioTrack.MODE_STREAM); } catch (Exception e) { mAudioTrackBufferSize = 0; Log.e("audioTrackInit", e); } return mAudioTrackBufferSize; }
public int audioTrackInit() { // Log.e(" ffff mediaplayer audiotrackinit start . sampleRateInHz:=" + sampleRateInHz + " channels:=" + channels ); audioTrackRelease(); int channelConfig = channels >= 2 ? AudioFormat.CHANNEL_OUT_STEREO : AudioFormat.CHANNEL_OUT_MONO; try { mAudioTrackBufferSize = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT); mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT, mAudioTrackBufferSize, AudioTrack.MODE_STREAM); } catch (Exception e) { mAudioTrackBufferSize = 0; Log.e("audioTrackInit", e); } return mAudioTrackBufferSize; }