Skip to content

Commit

Permalink
AndroidAudioForJSyn: update AudioTrack constructor
Browse files Browse the repository at this point in the history
Use Builders instead of the old deprecated APIs.

Author: lespin
  • Loading branch information
philburk committed Nov 24, 2024
1 parent 490d0b5 commit 627af82
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions android/com/jsyn/devices/android/AndroidAudioForJSyn.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.jsyn.devices.android;
import java.util.ArrayList;

import android.media.AudioAttributes;
import android.os.Process;
import android.media.AudioFormat;
import android.media.AudioManager;
Expand Down Expand Up @@ -87,10 +89,21 @@ public void start() {
// LOGGER.debug("Audio minBufferSize = " + minBufferSize);
bufferSize = (3 * (minBufferSize / 2)) & ~3;
// LOGGER.debug("Audio bufferSize = " + bufferSize);
audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, frameRate,
AudioFormat.CHANNEL_OUT_STEREO,
AudioFormat.ENCODING_PCM_FLOAT, bufferSize,
AudioTrack.MODE_STREAM);
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.build();
AudioFormat audioFormat = new AudioFormat.Builder()
.setSampleRate(frameRate)
.setEncoding(AudioFormat.ENCODING_PCM_FLOAT)
.setChannelMask(AudioFormat.CHANNEL_OUT_STEREO)
.build();
audioTrack = new AudioTrack(
audioAttributes,
audioFormat,
bufferSize,
AudioTrack.MODE_STREAM,
0);
audioTrack.play();
}
/** Grossly inefficient. Call the array version instead. */
Expand Down

0 comments on commit 627af82

Please sign in to comment.