Я хочу записать звук с помощью Superpowered SDK на моём корневом устройстве Android Q.
Поскольку Google наложил некоторые ограничения на запись аудио на Android Q, поэтому я пытаюсь перенести Superpowered SDK Android Пример в Linux исполняемый файл что я могу работать в системном пространстве, обходя ограничение Android Apps. Пожалуйста, дайте мне знать, если я ошибаюсь.
Для этого я создал простой проект с основным классом следующим образом:
#include <string>
#include <OpenSource/SuperpoweredAndroidAudioIO.h>
#include <Superpowered.h>
#include <SuperpoweredSimple.h>
#include <SuperpoweredRecorder.h>
#include <unistd.h>
#include <iostream>
#include <chrono>
#include <thread>
static SuperpoweredAndroidAudioIO *audioIO;
static Superpowered::Recorder *recorder;
// This is called periodically by the audio I/O.
static bool audioProcessing(
void *clientdata, // custom pointer
short int *audio, // buffer of interleaved samples
int numberOfFrames, // number of frames to process
int samplerate // current sample rate in Hz
)
{
std::cout << "------- Processing Audio...numberOfFrames:" << numberOfFrames << " audio:" << *audio << std::endl;
float floatBuffer[numberOfFrames * 2];
Superpowered::ShortIntToFloat(audio, floatBuffer, (unsigned int)numberOfFrames);
recorder->recordInterleaved(floatBuffer, (unsigned int)numberOfFrames);
return false;
}
// StartAudio - Start audio engine.
void startAudio(
unsigned int samplerate,
int buffersize,
const char *temp,
const char *dest)
{
Superpowered::Initialize(
"ExampleLicenseKey-WillExpire-OnNextUpdate",
false, // enableAudioAnalysis (using SuperpoweredAnalyzer, SuperpoweredLiveAnalyzer, SuperpoweredWaveform or SuperpoweredBandpassFilterbank)
false, // enableFFTAndFrequencyDomain (using SuperpoweredFrequencyDomain, SuperpoweredFFTComplex, SuperpoweredFFTReal or SuperpoweredPolarFFT)
false, // enableAudioTimeStretching (using SuperpoweredTimeStretching)
false, // enableAudioEffects (using any SuperpoweredFX class)
false, // enableAudioPlayerAndDecoder (using SuperpoweredAdvancedAudioPlayer or SuperpoweredDecoder)
false, // enableCryptographics (using Superpowered::RSAPublicKey, Superpowered::RSAPrivateKey, Superpowered::hasher or Superpowered::AES)
false // enableNetworking (using Superpowered::httpRequest)
);
// Initialize the recorder with a temporary file path.
recorder = new Superpowered::Recorder(temp);
// Start a new recording.
recorder->prepare(
dest, // destination path
samplerate, // sample rate in Hz
true, // apply fade in/fade out
1 // minimum length of the recording in seconds
);
std::cout << "Initializing audioIO..\n";
// Initialize audio engine with audio callback function.
audioIO = new SuperpoweredAndroidAudioIO(
samplerate, // native sampe rate
buffersize, // native buffer size
true, // enableInput
false, // enableOutput
audioProcessing, // process callback function
nullptr // clientData
);
}
// StopAudio - Stop audio engine and free audio buffer.
void stopRecording()
{
std::this_thread::sleep_for(std::chrono::seconds(60));
recorder->stop();
std::cout << "Deleting IO\n";
delete audioIO;
// Wait until the recorder finished writing everything to disk.
// It's better to do this asynchronously, but we're just blocking (sleeping) now.
std::cout << "Finishing..\n";
while (!recorder->isFinished())
usleep(100000);
// __android_log_print(ANDROID_LOG_DEBUG, "Recorder", "Finished recording.");
std::cout << "Deleting Recorder\n";
delete recorder;
}
// onBackground - Put audio processing to sleep if no audio is playing.
void onBackground()
{
audioIO->onBackground();
}
// onForeground - Resume audio processing.
void onForeground()
{
audioIO->onForeground();
}
int main(int, char **)
{
std::cout << "Hello, AudioRecorder!\n";
unsigned int samplerate = 48000;
int buffersize = 192;
const char *temp = "/system/recording/temp.wav";
const char *dest = "/system/recording/final.wav";
std::cout << "Starting recording::"
<< "\n\tsamplerate:" << samplerate
<< "\n\tbuffersize:" << buffersize
<< "\n\ttemp:" << temp
<< "\n\tdest:" << dest
<< std::endl;
startAudio(samplerate, buffersize, temp, dest);
onForeground();
std::cout << "Starting thread to stop recording...\n";
std::thread stopThread(&stopRecording); // thread starts running
std::cout << "Stoping recording...\n";
stopThread.join(); // main thread waits for the thread t to finish
std::cout << "Returning from main\n";
return 0;
}
Я пытаюсь записать 1 минутный звук с кодом выше. Но я не могу вызвать функцию audioProcessing
. Когда я запускаю приведенный выше код, я получаю следующий вывод:
OnePlus7Pro:/system # ./xbin/audio_recorder
Hello, AudioRecorder!
Starting recording::
samplerate:48000
buffersize:192
temp:/system/recording/temp.wav
dest:/system/recording/final.wav
Initializing audioIO..
Starting thread to stop recording...
Stoping recording...
Deleting IO
Finishing..
^C
130|OnePlus7Pro:/system # cd recording
OnePlus7Pro:/system/recording # ls -l
total 0
-rw-r--r-- 1 root root 0 2020-01-08 12:34 temp.wav
-rw-r--r-- 1 root root 0 2020-01-08 12:34 temp.wav.txt
После «Finishing ..» он не печатает «Deleting Recorder», поэтому в коде есть какая-то проблема, но я не получаю это.
Я Android Разработчик и новичок в C ++. Кто-нибудь может мне помочь?