AudioTrack 的问题
你好,我写了一个程序(在Android NDK上),它通过Java中的JNI提供音频缓冲区。不稳定的问题。有时 AudioTrack 会完美地再现缓冲区,有时会出现以下消息:
08-18 15:13:00.745: INFO/AudioTrack(12457): AudioTrack::setstreamType[3]channels[12]format[1]sampleRate [44100] 08-18 15:13:00.749:INFO/AudioPolicyManager(2381):setOutputDevice()输出1设备2延迟Ms 0力:0 08-18 15:13:04.183:信息/音频硬件ALSA(2381):输出待机已调用!关闭 PCM 设备。
Java 代码如下:
final int bufSize = AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT);
track = new AudioTrack(AudioManager.STREAM_MUSIC, 44100,AudioFormat.CHANNEL_CONFIGURATION_STEREO,AudioFormat.ENCODING_PCM_16BIT, bufSize, AudioTrack.MODE_STREAM);
track.play();
int byt = track.write(buf, 0, length);
此错误可能是什么问题?
Hello I wrote a program (on Android NDK), which gives audio buffer through JNI in Java. The problem of instability. Sometimes AudioTrack perfectly reproduces the buffer, and sometimes there are these messages:
08-18 15:13:00.745: INFO/AudioTrack(12457): AudioTrack::set streamType[3] channels[12] format[1] sampleRate[44100]
08-18 15:13:00.749: INFO/AudioPolicyManager(2381): setOutputDevice() output 1 device 2 delayMs 0 force:0
08-18 15:13:04.183: INFO/AudioHardwareALSA(2381): Output standby called!!. Turn off PCM device.
Code in Java like this:
final int bufSize = AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT);
track = new AudioTrack(AudioManager.STREAM_MUSIC, 44100,AudioFormat.CHANNEL_CONFIGURATION_STEREO,AudioFormat.ENCODING_PCM_16BIT, bufSize, AudioTrack.MODE_STREAM);
track.play();
int byt = track.write(buf, 0, length);
In what may be a problem with this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在调用
track.play
之前,您必须先调用track.write
并填充最小 bufSize。You have to call
track.write
andf fill the minimum bufSize first beforetrack.play
is called.