超强Android 回放与录音同时进行
Superpowered Android PlayBack & Record Simultaneously
我正在使用 Superpowered Android C++ 库开发混音器,我在录制时遇到播放器问题,播放器不播放,只有录音机在录制。下面是代码,谁能指导我哪里放错了东西
bool processRecording(short int *input, unsigned int numberOfSamples) {
pthread_mutex_lock(&mutex);
if (askRecording) {
unsigned int data = 0;
SuperpoweredShortIntToFloat(input, stereoBufferRecording, numberOfSamples);
data = recorder->process(stereoBufferRecording, NULL, numberOfSamples);
playerA->process( musicBuffer, false, numberOfSamples, 0.5f );
SuperpoweredShortIntToFloat(input, stereoBufferRecording, numberOfSamples);
SuperpoweredFloatToShortInt(musicBuffer, input, numberOfSamples);
pthread_mutex_unlock(&mutex);
return true;
}
pthread_mutex_unlock(&mutex);
return false;
}
有没有人知道如何把它放在正确的位置?
在 @Gabor 建议的更改之后,以下是代码片段
bool processRecording(short int *input, unsigned int numberOfSamples) {
pthread_mutex_lock(&mutex);
if (askRecording) {
unsigned int data = 0;
SuperpoweredShortIntToFloat(input, stereoBufferRecording, numberOfSamples);
playerA->process( musicBuffer, false, numberOfSamples, 1.0f );
//=====================================================================================
// ================== Mixing Two Buffer ==================
mixerInputs[0] = musicBuffer;
mixerInputs[1] = stereoBufferRecording;
mixerInputs[2] = NULL;
mixerInputs[3] = NULL;
mixerOutputs[0] = outputBuffer;
mixerOutputs[1] = NULL;
float inputLevels[] = { 0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
float outputLevels[] = { 1.0f, 1.0f };
__android_log_print(ANDROID_LOG_INFO, "NativeSuperpoweredRecorder ", " processRecording 2>>");
mixerBackend->process(mixerInputs, mixerOutputs, inputLevels, outputLevels, NULL, NULL, numberOfSamples);
//=====================================================================================
data = recorder->process(mixerOutputs[0], NULL, numberOfSamples);
SuperpoweredFloatToShortInt(musicBuffer, input, numberOfSamples);
pthread_mutex_unlock(&mutex);
return true;
}
pthread_mutex_unlock(&mutex);
return false; }
这是您在代码中所做的:
输入->stereoBufferRecording->录音机
输入->stereoBufferRecording->?
播放器->musicBuffer->输入
当 askRecording 为 false 时,播放器根本没有播放。
我猜 "input" 也是去往 "output" 的同一个缓冲区?
我正在使用 Superpowered Android C++ 库开发混音器,我在录制时遇到播放器问题,播放器不播放,只有录音机在录制。下面是代码,谁能指导我哪里放错了东西
bool processRecording(short int *input, unsigned int numberOfSamples) {
pthread_mutex_lock(&mutex);
if (askRecording) {
unsigned int data = 0;
SuperpoweredShortIntToFloat(input, stereoBufferRecording, numberOfSamples);
data = recorder->process(stereoBufferRecording, NULL, numberOfSamples);
playerA->process( musicBuffer, false, numberOfSamples, 0.5f );
SuperpoweredShortIntToFloat(input, stereoBufferRecording, numberOfSamples);
SuperpoweredFloatToShortInt(musicBuffer, input, numberOfSamples);
pthread_mutex_unlock(&mutex);
return true;
}
pthread_mutex_unlock(&mutex);
return false;
}
有没有人知道如何把它放在正确的位置?
在 @Gabor 建议的更改之后,以下是代码片段
bool processRecording(short int *input, unsigned int numberOfSamples) {
pthread_mutex_lock(&mutex);
if (askRecording) {
unsigned int data = 0;
SuperpoweredShortIntToFloat(input, stereoBufferRecording, numberOfSamples);
playerA->process( musicBuffer, false, numberOfSamples, 1.0f );
//=====================================================================================
// ================== Mixing Two Buffer ==================
mixerInputs[0] = musicBuffer;
mixerInputs[1] = stereoBufferRecording;
mixerInputs[2] = NULL;
mixerInputs[3] = NULL;
mixerOutputs[0] = outputBuffer;
mixerOutputs[1] = NULL;
float inputLevels[] = { 0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
float outputLevels[] = { 1.0f, 1.0f };
__android_log_print(ANDROID_LOG_INFO, "NativeSuperpoweredRecorder ", " processRecording 2>>");
mixerBackend->process(mixerInputs, mixerOutputs, inputLevels, outputLevels, NULL, NULL, numberOfSamples);
//=====================================================================================
data = recorder->process(mixerOutputs[0], NULL, numberOfSamples);
SuperpoweredFloatToShortInt(musicBuffer, input, numberOfSamples);
pthread_mutex_unlock(&mutex);
return true;
}
pthread_mutex_unlock(&mutex);
return false; }
这是您在代码中所做的:
输入->stereoBufferRecording->录音机
输入->stereoBufferRecording->?
播放器->musicBuffer->输入
当 askRecording 为 false 时,播放器根本没有播放。
我猜 "input" 也是去往 "output" 的同一个缓冲区?