-
Can't start engine on Android. I started off experimenting with miniaudio on Android, so I know it works. I shifted into the iOS side to get that platform working, but ended up further developing in iOS for a few months and now I need to get things working with Android again. Everything I've tried so far hasn't worked, but before I start ripping things out, if anyone sees something obvious in the logs, please let me know. Otherwise, I'll go down the path of elimination. Same problem on all androids (pixel: 3a,xl, samsung: a7, s8) Settings // configure device
ma_device_config deviceConfig;
deviceConfig = ma_device_config_init(ma_device_type_duplex);
// deviceConfig.sampleRate = 44100;
deviceConfig.periodSizeInFrames= 512; // 192; 256; //512;//256;
deviceConfig.capture.pDeviceID = NULL;
deviceConfig.capture.format = DEVICE_FORMAT;
deviceConfig.capture.channels = DEVICE_CHANNELS;
deviceConfig.capture.shareMode = ma_share_mode_exclusive; //ma_share_mode_exclusive; //ma_share_mode_shared;
deviceConfig.playback.shareMode = ma_share_mode_exclusive; //ma_share_mode_exclusive;
deviceConfig.playback.pDeviceID = NULL;
deviceConfig.playback.format = DEVICE_FORMAT;
deviceConfig.playback.channels = DEVICE_CHANNELS;
deviceConfig.dataCallback = data_callback;
deviceConfig.pUserData = &encoder;
// init device
if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) {
printf(" Failed to initialize the device.");
__android_log_print(ANDROID_LOG_DEBUG, "loglevel: flutter", "Failed to initialize the device.");
return -1; // Failed to initialize the device.
}
// setup encoder
ma_encoder_config encoderConfig;
char outputFilen[256];
snprintf(outputFilen, sizeof(outputFilen), "%s/%s", path,"output.wav");
// char * outputFile = "/var/mobile/Containers/Data/Application/53DDA03D-79DF-437F-82C5-FBB89D3750E3/Documents/output2.wav";
encoderConfig = ma_encoder_config_init(ma_encoding_format_wav, ma_format_f32, 2, device.sampleRate);
if (ma_encoder_init_file(outputFilen, &encoderConfig, &encoder) != MA_SUCCESS) {
printf("Failed to initialize output file.\n");
__android_log_print(ANDROID_LOG_DEBUG, "loglevel: flutter", "Failed to initialize output file.");
return -1;
}
// configure engine
ma_engine_config engineConfig;
engineConfig = ma_engine_config_init();
engineConfig.pDevice = &device;
engineConfig.noAutoStart = MA_TRUE;
/* The engine needs to be initialized first. */
result = ma_engine_init(&engineConfig, &g_engine);
if (result != MA_SUCCESS) {
printf("Failed to initialize audio engine.");
__android_log_print(ANDROID_LOG_DEBUG, "loglevel: flutter", "Failed to initialize audio engine.");
return -1;
}
ma_uint32 channels;
ma_uint32 sampleRate;
channels = ma_engine_get_channels(&g_engine);
sampleRate = ma_engine_get_sample_rate(&g_engine);
// start engine:
result = ma_engine_start(&g_engine);
if (result != MA_SUCCESS) {
printf("WARNING: Failed to start engine.\n");
__android_log_print(ANDROID_LOG_DEBUG, "loglevel: flutter", "WARNING: Failed to start engine.\n");
}
Logs D/miniaudio(22019): DEBUG: Failed to initialize WASAPI backend.
D/miniaudio(22019): DEBUG: Failed to initialize DirectSound backend.
D/miniaudio(22019): DEBUG: Failed to initialize WinMM backend.
D/miniaudio(22019): DEBUG: Failed to initialize Core Audio backend.
D/miniaudio(22019): DEBUG: Failed to initialize sndio backend.
D/miniaudio(22019): DEBUG: Failed to initialize audio(4) backend.
D/miniaudio(22019): DEBUG: Failed to initialize OSS backend.
D/miniaudio(22019): DEBUG: Failed to initialize PulseAudio backend.
D/miniaudio(22019): DEBUG: Failed to initialize ALSA backend.
D/miniaudio(22019): DEBUG: Failed to initialize JACK backend.
D/miniaudio(22019): DEBUG: Attempting to initialize AAudio backend...
D/miniaudio(22019): DEBUG: Loading library: libaaudio.so
D/miniaudio(22019): DEBUG: Loading symbol: AAudio_createStreamBuilder
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_delete
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_setDeviceId
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_setDirection
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_setSharingMode
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_setFormat
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_setChannelCount
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_setSampleRate
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_setBufferCapacityInFrames
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_setFramesPerDataCallback
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_setDataCallback
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_setErrorCallback
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_setPerformanceMode
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_setUsage
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_setContentType
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_setInputPreset
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStreamBuilder_openStream
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStream_close
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStream_getState
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStream_waitForStateChange
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStream_getFormat
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStream_getChannelCount
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStream_getSampleRate
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStream_getBufferCapacityInFrames
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStream_getFramesPerDataCallback
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStream_getFramesPerBurst
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStream_requestStart
D/miniaudio(22019): DEBUG: Loading symbol: AAudioStream_requestStop
D/miniaudio(22019): DEBUG: System Architecture:
D/miniaudio(22019): DEBUG: Endian: LE
D/miniaudio(22019): DEBUG: SSE2: NO
D/miniaudio(22019): DEBUG: AVX2: NO
D/miniaudio(22019): DEBUG: NEON: YES
I/AAudio (22019): AAudioStreamBuilder_openStream() called ----------------------------------------
I/AudioStreamBuilder(22019): rate = 0, channels = 2, channelMask = 0x80000003, format = 5, sharing = SH, dir = INPUT
I/AudioStreamBuilder(22019): device = 0, sessionId = -1, perfMode = 12, callback: ON with frames = 512
I/AudioStreamBuilder(22019): usage = 0, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
I/AudioStreamBuilder(22019): privacy sensitive = false
I/AudioStreamBuilder(22019): opPackageName = (null)
I/AudioStreamBuilder(22019): attributionTag = (null)
D/example.playap(22019): PlayerBase::PlayerBase()
D/AudioStreamInternal_Client(22019): open() original HW burst = 96, minMicros = 2000 => SW burst = 96
D/AAudioStream(22019): setState(s#1) from 0 to 2
I/AAudio (22019): AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#1 ----------------
I/AAudio (22019): AAudioStreamBuilder_openStream() called ----------------------------------------
I/AudioStreamBuilder(22019): rate = 0, channels = 2, channelMask = 0x80000003, format = 5, sharing = SH, dir = OUTPUT
I/AudioStreamBuilder(22019): device = 0, sessionId = -1, perfMode = 12, callback: ON with frames = 512
I/AudioStreamBuilder(22019): usage = 0, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
I/AudioStreamBuilder(22019): privacy sensitive = false
I/AudioStreamBuilder(22019): opPackageName = (null)
I/AudioStreamBuilder(22019): attributionTag = (null)
D/example.playap(22019): PlayerBase::PlayerBase()
D/AudioStreamInternal_Client(22019): open() original HW burst = 96, minMicros = 2000 => SW burst = 96
D/AAudioStream(22019): setState(s#2) from 0 to 2
I/AAudioFlowGraph(22019): configure() source format = 0x00000005, channels = 2, sink format = 0x00000005, channels = 2
I/AAudio (22019): AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#2 ----------------
D/miniaudio(22019): INFO: [AAudio]
D/miniaudio(22019): INFO: Default Playback Device (Capture)
D/miniaudio(22019): INFO: Format: 32-bit IEEE Floating Point -> 32-bit IEEE Floating Point
D/miniaudio(22019): INFO: Channels: 2 -> 2
D/miniaudio(22019): INFO: Sample Rate: 48000 -> 48000
D/miniaudio(22019): INFO: Buffer Size: 512*3 (1536)
D/miniaudio(22019): INFO: Conversion:
D/miniaudio(22019): INFO: Pre Format Conversion: NO
D/miniaudio(22019): INFO: Post Format Conversion: NO
D/miniaudio(22019): INFO: Channel Routing: NO
D/miniaudio(22019): INFO: Resampling: NO
D/miniaudio(22019): INFO: Passthrough: YES
D/miniaudio(22019): INFO: Channel Map In: {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}
D/miniaudio(22019): INFO: Channel Map Out: {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}
D/miniaudio(22019): INFO: Default Capture Device (Playback)
D/miniaudio(22019): INFO: Format: 32-bit IEEE Floating Point -> 32-bit IEEE Floating Point
D/miniaudio(22019): INFO: Channels: 2 -> 2
D/miniaudio(22019): INFO: Sample Rate: 48000 -> 48000
D/miniaudio(22019): INFO: Buffer Size: 512*3 (1536)
D/miniaudio(22019): INFO: Conversion:
D/miniaudio(22019): INFO: Pre Format Conversion: NO
D/miniaudio(22019): INFO: Post Format Conversion: NO
D/miniaudio(22019): INFO: Channel Routing: NO
D/miniaudio(22019): INFO: Resampling: NO
D/miniaudio(22019): INFO: Passthrough: YES
D/miniaudio(22019): INFO: Channel Map In: {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}
D/miniaudio(22019): INFO: Channel Map Out: {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}
D/AAudio (22019): AAudioStream_requestStart(s#1) called --------------
D/AAudioStream(22019): setState(s#1) from 2 to 3
D/MediaCodec(22019): keep callback message for reclaim
I/CCodecConfig(22019): query failed after returning 19 values (BAD_INDEX)
W/Codec2Client(22019): query -- param skipped: index = 1342179345.
W/Codec2Client(22019): query -- param skipped: index = 2415921170.
W/Codec2Client(22019): query -- param skipped: index = 1610614798.
D/AAudioStream(22019): setState(s#1) from 3 to 2
D/AAudio (22019): AAudioStream_requestStart(s#1) returned -898 ---------
D/loglevel: flutter(26903): WARNING: Failed to start engine. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
What happens when you use shared mode instead of exclusive mode? |
Beta Was this translation helpful? Give feedback.
-
Update: It wasn't the C vs C++ compiler, both yielded the same problem. It was the Android targetSdkVersion. I changed it the build.gradle to 22, which is an older version. I'm using Flutter and it provides the value for the targetSdkVersion as a variable in the build.gradle. I haven't touched any of the build configs, so maybe a Flutter update caused the update to the targetSdkVersion. My next step is to see which targetSdkVersion does not work. Update 2: It looks like the Android targetSdkVersion of 33, which is the latest is causing the problem. It maybe something to do with how this SDK version is reading permissions to record or modify audio. Update 3: Changed back 33, rebuilt and it is still working. Cleaned the build with 33 and it is still working. So it's not clear as to what the issue was. |
Beta Was this translation helpful? Give feedback.
-
It looks like from your last post that's its falling back to the null backend. Check that you've enabled the microphone permission for your app. |
Beta Was this translation helpful? Give feedback.
The problem is currently resolved as a stated earlier, and it wasn't a miniaudio issue.
I think the problem has to do with how certain Android targetSdkVersions allow runtime permissions or not. I think my permissions were being ignored because the app was installed with a new Sdk version over a previous version of the app where the user prompt for permissions was set many months ago (on multiple devices) and Android did not re-prompt for permissions until I manually changed the SDK version and did a clean build and install. I also think this has something to do with it too: https://stackoverflow.com/questions/45163008/android-failed-to-finalize-session-26-new-target-sdk-22-doesnt-support…