我正在为ExoPlayer(使用kotlin / Java)编写一个自定义AudioProcessor,它将传入的音频数据,将其传递到Steam Audio API(在C ++中),使用iplApplyBinauralEffect
进行处理并将其传递回ExoPlayer 。当ExoPlayer从queueInput
提供的ByteBuffer需要转换为Steam期望的float *(IPLfloat32)时,就会出现问题。如何将ByteBuffer转换为Steam可以处理的float *?
ByteBuffer表示它是小端的,所以我转换为大端的,但是它仍然返回大量且很小的值。
The docs for Steam Audio API are here
and the docs for ExoPlayer are here
音频缓冲区IPLAudioBuffer is described here
(从AudioProcessor子类传递)
public ByteBuffer queueInput(ByteBuffer inputBuffer, ByteBuffer buffer, int position, int length) {
//inputBuffer.order(ByteOrder.BIG_ENDIAN);
FloatBuffer floatBuffer = inputBuffer.order(ByteOrder.BIG_ENDIAN).asFloatBuffer();
float[] input = new float[floatBuffer.limit()];
floatBuffer.get(input);
// get rendered output
float[] convertedArray = queueInput(playerIndex, input, floatBuffer.limit());
buffer = ByteBuffer.allocate(inputBuffer.limit() * 2);
FloatBuffer outputFloatBuffer = buffer.asFloatBuffer();
outputFloatBuffer.put(convertedArray);
buffer.rewind();
return buffer;
}
(通过jni)
queueInput(JNIEnv *env, jobject instance, jint playerIndex, jfloatArray bytes, jint len) {
jfloat *input = env->GetFloatArrayElements(bytes, nullptr);
int inputaudio = engine->getOutput(static_cast<unsigned int>(playerIndex), input, len, input);
jfloatArray result;
result = env->NewFloatArray(inputaudio);
env->SetFloatArrayRegion(result, 0, inputaudio, input);
free(input);
env->ReleaseFloatArrayElements(bytes, input, JNI_COMMIT);
return result;
}
(传递给SteamPlayer)
int SteamPlayer::getOutput(float *input, int len, float *output) {
std::vector<float> outputaudioframe(static_cast<unsigned int>(2 * framesize));
std::vector<float> outputaudio;
int numFrames = len / framesize;
IPLAudioBuffer inbuffer{ stereo, framesize, input };
inbuffer.format.numSpeakers = 2;
inbuffer.format.speakerDirections = &inDirections;
IPLAudioBuffer outbuffer{stereo, framesize, outputaudioframe.data()};
outbuffer.format.numSpeakers = 2;
outDirections.x = x;
outDirections.y = y;
outDirections.z = z;
outbuffer.format.speakerDirections = &outDirections;
for (auto i = 0; i < numFrames; ++i) {
iplApplyBinauralEffect(effect, renderer, inbuffer, outDirections, IPL_HRTFINTERPOLATION_NEAREST, outbuffer);
std::copy(std::begin(outputaudioframe), std::end(outputaudioframe), std::back_inserter(outputaudio));
inbuffer.interleavedBuffer += framesize;
}
for (int i = 0; i < outputaudio.size(); ++i) {
outputaudio[i] *= 32767;
}
std::memcpy(output, outputaudio.data(), outputaudio.size());
return outputaudio.size();
}
这是“ convertedArray”行之前的一些传入数据的屏幕截图
任何帮助将不胜感激。