6 public class SDLAudioManager
7 {
16 }
18 // Audio
20 /**
21 * This method is called by SDL using JNI.
22 */
23 public static int audioOpen(int sampleRate, boolean is16Bit, boolean isStereo, int desiredFrames) {
24 int channelConfig = isStereo ? AudioFormat.CHANNEL_CONFIGURATION_STEREO : AudioFormat.CHANNEL_CONFIGURATION_MONO;
28 Log.v(TAG, "SDL audio: wanted " + (isStereo ? "stereo" : "mono") + " " + (is16Bit ? "16-bit" : "8-bit") + " " + (sampleRate / 1000f) + "kHz, " + desiredFrames + " frames buffer");
30 // Let the user pick a larger buffer if they really want -- but ye
31 // gods they probably shouldn't, the minimums are horrifyingly high
32 // latency already
33 desiredFrames = Math.max(desiredFrames, (AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat) + frameSize - 1) / frameSize);
39 // Instantiating AudioTrack can "succeed" without an exception and the track may still be invalid
40 // Ref: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/media/java/android/media/AudioTrack.java
41 // Ref: http://developer.android.com/reference/android/media/AudioTrack.html#getState()
47 }
50 }
52 Log.v(TAG, "SDL audio: got " + ((mAudioTrack.getChannelCount() >= 2) ? "stereo" : "mono") + " " + ((mAudioTrack.getAudioFormat() == AudioFormat.ENCODING_PCM_16BIT) ? "16-bit" : "8-bit") + " " + (mAudioTrack.getSampleRate() / 1000f) + "kHz, " + desiredFrames + " frames buffer");
55 }
57 /**
58 * This method is called by SDL using JNI.
59 */
64 }
74 // Nom nom
75 }
79 }
80 }
81 }
83 /**
84 * This method is called by SDL using JNI.
85 */
90 }
100 // Nom nom
101 }
105 }
106 }
107 }
109 /**
110 * This method is called by SDL using JNI.
111 */
112 public static int captureOpen(int sampleRate, boolean is16Bit, boolean isStereo, int desiredFrames) {
113 int channelConfig = isStereo ? AudioFormat.CHANNEL_CONFIGURATION_STEREO : AudioFormat.CHANNEL_CONFIGURATION_MONO;
117 Log.v(TAG, "SDL capture: wanted " + (isStereo ? "stereo" : "mono") + " " + (is16Bit ? "16-bit" : "8-bit") + " " + (sampleRate / 1000f) + "kHz, " + desiredFrames + " frames buffer");
119 // Let the user pick a larger buffer if they really want -- but ye
120 // gods they probably shouldn't, the minimums are horrifyingly high
121 // latency already
122 desiredFrames = Math.max(desiredFrames, (AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat) + frameSize - 1) / frameSize);
128 // see notes about AudioTrack state in audioOpen(), above. Probably also applies here.
134 }
137 }
139 Log.v(TAG, "SDL capture: got " + ((mAudioRecord.getChannelCount() >= 2) ? "stereo" : "mono") + " " + ((mAudioRecord.getAudioFormat() == AudioFormat.ENCODING_PCM_16BIT) ? "16-bit" : "8-bit") + " " + (mAudioRecord.getSampleRate() / 1000f) + "kHz, " + desiredFrames + " frames buffer");
142 }
144 /** This method is called by SDL using JNI. */
146 // !!! FIXME: this is available in API Level 23. Until then, we always block. :(
147 //return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING);
149 }
151 /** This method is called by SDL using JNI. */
153 // !!! FIXME: this is available in API Level 23. Until then, we always block. :(
154 //return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING);
156 }
159 /** This method is called by SDL using JNI. */
165 }
166 }
168 /** This method is called by SDL using JNI. */
174 }
175 }
178 }