love2d / love-android

Android build setup for LÖVE.
https://love2d.org
Other
209 stars 73 forks source link

Can't start microphone recording #188

Closed slime73 closed 2 years ago

slime73 commented 4 years ago

Original report by Igor Gvaldov (Bitbucket: [Игорь Гвалдов](https://bitbucket.org/Игорь Гвалдов), ).


RecordingDevice:start() always returns false (Microphone permission granted).

Phone: Mi A1

Firmware: LOS 16.0 (Android 9)

Love2D version: 11.3 (APK file downloaded from the main repo)

What am I doing wrong?

--------- beginning of main
--------- beginning of system
12-04 06:07:52.963 17114 17138 D openal  : AL lib: alc_initconfig: Initializing library v1.19.1-6761218e51699f46bf25c377e65b3e9ea5e434b9 openal-soft-1.19.1
12-04 06:07:52.963 17114 17138 D openal  : AL lib: alc_initconfig: Supported backends: opensl, null, wave
12-04 06:07:52.964 17114 17138 D openal  : AL lib: ReadALConfig: Loading config /etc/openal/alsoft.conf...
12-04 06:07:52.964 17114 17138 D openal  : AL lib: ReadALConfig: Loading config /etc/xdg/alsoft.conf...
12-04 06:07:52.964 17114 17138 D openal  : AL lib: GetProcBinary: Got path: /system/bin
12-04 06:07:52.964 17114 17138 D openal  : AL lib: ReadALConfig: Loading config /system/bin/alsoft.conf...
12-04 06:07:52.964 17114 17138 D openal  : AL lib: GetConfigValue: Key disable-cpu-exts not found
12-04 06:07:52.964 17114 17138 D openal  : AL lib: FillCPUCaps: Got features string:fp asimd evtstrm aes pmull sha1 sha2 crc32
12-04 06:07:52.964 17114 17138 D openal  : 
12-04 06:07:52.964 17114 17138 D openal  : AL lib: FillCPUCaps: Extensions: -NEON
12-04 06:07:52.964 17114 17138 D openal  : AL lib: GetConfigValue: Key rt-prio not found
12-04 06:07:52.964 17114 17138 D openal  : AL lib: GetConfigValue: Key resampler not found
12-04 06:07:52.964 17114 17138 D openal  : AL lib: GetConfigValue: Key trap-al-error not found
12-04 06:07:52.964 17114 17138 D openal  : AL lib: GetConfigValue: Key trap-alc-error not found
12-04 06:07:52.964 17114 17138 D openal  : AL lib: GetConfigValue: Key reverb/boost not found
12-04 06:07:52.964 17114 17138 D openal  : AL lib: GetConfigValue: Key drivers not found
12-04 06:07:52.964 17114 17138 D openal  : AL lib: alc_initconfig: Initialized backend "opensl"
12-04 06:07:52.964 17114 17138 D openal  : AL lib: alc_initconfig: Added "opensl" for playback
12-04 06:07:52.964 17114 17138 D openal  : AL lib: alc_initconfig: Added "opensl" for capture
12-04 06:07:52.964 17114 17138 D openal  : AL lib: GetConfigValue: Key excludefx not found
12-04 06:07:52.965 17114 17138 D openal  : AL lib: GetConfigValue: Key default-reverb not found
12-04 06:07:52.965 17114 17138 D openal  : AL lib: GetConfigValue: Key channels not found
12-04 06:07:52.965 17114 17138 D openal  : AL lib: GetConfigValue: Key sample-type not found
12-04 06:07:52.965 17114 17138 D openal  : AL lib: GetConfigValue: Key frequency not found
12-04 06:07:52.965 17114 17138 D openal  : AL lib: GetConfigValue: Key periods not found
12-04 06:07:52.965 17114 17138 D openal  : AL lib: GetConfigValue: Key period_size not found
12-04 06:07:52.965 17114 17138 D openal  : AL lib: GetConfigValue: Key sources not found
12-04 06:07:52.965 17114 17138 D openal  : AL lib: GetConfigValue: Key slots not found
12-04 06:07:52.965 17114 17138 D openal  : AL lib: GetConfigValue: Key sends not found
12-04 06:07:52.967 17114 17138 D openal  : AL lib: GetConfigValue: Key ambi-format not found
12-04 06:07:52.967 17114 17138 D openal  : AL lib: alcOpenDevice: Created device 0x75e24b5000, "OpenSL"
12-04 06:07:52.968 17114 17138 D openal  : AL lib: UpdateDeviceParams: ALC_MAX_AUXILIARY_SENDS = 64
12-04 06:07:52.968 17114 17138 D openal  : AL lib: GetConfigValue: Key frequency not found
12-04 06:07:52.968 17114 17138 D openal  : AL lib: GetConfigValue: Key sources not found
12-04 06:07:52.968 17114 17138 D openal  : AL lib: GetConfigValue: Key sends not found
12-04 06:07:52.968 17114 17138 D openal  : AL lib: GetConfigValue: Key hrtf not found
12-04 06:07:52.968 17114 17138 D openal  : AL lib: UpdateDeviceParams: Pre-reset: Stereo, Float, 44100hz, 1024 update size x3
12-04 06:07:52.972 17114 17138 I libOpenSLES: Emulating old channel mask behavior (ignoring positional mask 0x3, using default mask 0x3 based on channel count of 2)
12-04 06:07:52.978 17114 17138 D openal  : AL lib: UpdateDeviceParams: Post-reset: Stereo, Signed Short, 44100hz, 1024 update size x3
12-04 06:07:52.978 17114 17138 D openal  : AL lib: GetConfigValue: Key stereo-mode not found
12-04 06:07:52.978 17114 17138 D openal  : AL lib: aluInitRenderer: HRTF disabled
12-04 06:07:52.978 17114 17138 D openal  : AL lib: GetConfigValue: Key cf_level not found
12-04 06:07:52.978 17114 17138 D openal  : AL lib: aluInitRenderer: BS2B disabled
12-04 06:07:52.978 17114 17138 D openal  : AL lib: GetConfigValue: Key stereo-encoding not found
12-04 06:07:52.978 17114 17138 D openal  : AL lib: aluInitRenderer: UHJ disabled
12-04 06:07:52.978 17114 17138 D openal  : AL lib: UpdateDeviceParams: Channel config, Dry: 2, FOA: 0, Real: 0
12-04 06:07:52.978 17114 17138 D openal  : AL lib: UpdateDeviceParams: Allocating 2 channels, 16384 bytes
12-04 06:07:52.978 17114 17138 D openal  : AL lib: UpdateDeviceParams: Max sources: 256 (255 + 1), effect slots: 64, sends: 16
12-04 06:07:52.978 17114 17138 D openal  : AL lib: GetConfigValue: Key dither not found
12-04 06:07:52.978 17114 17138 D openal  : AL lib: GetConfigValue: Key dither-depth not found
12-04 06:07:52.978 17114 17138 D openal  : AL lib: UpdateDeviceParams: Dithering enabled (16-bit, 32768)
12-04 06:07:52.978 17114 17138 D openal  : AL lib: GetConfigValue: Key output-limiter not found
12-04 06:07:52.978 17114 17138 D openal  : AL lib: UpdateDeviceParams: Output limiter enabled
12-04 06:07:52.978 17114 17138 D openal  : AL lib: UpdateDeviceParams: Fixed device latency: 997732ns
12-04 06:07:52.993 17114 17138 D openal  : AL lib: GetConfigValue: Key volume-adjust not found
12-04 06:07:52.993 17114 17138 D openal  : AL lib: alcCreateContext: Created context 0x75e246a280
12-04 06:07:53.102 17114 17138 D openal  : AL lib: alcCaptureOpenDevice: Capture format: Mono, Signed Short, 8000hz, 10000 update size x1
12-04 06:07:53.102 17114 17138 W libOpenSLES: Conversion from OpenSL ES positional channel mask 0x4 to Android mask 0 loses channels
12-04 06:07:53.102 17114 17138 I libOpenSLES: Emulating old channel mask behavior (ignoring positional mask 0x4, using default mask 0x10 based on channel count of 1)
12-04 06:07:53.113 17114 17138 W libOpenSLES: Leaving BufferQueue::Enqueue (SL_RESULT_BUFFER_INSUFFICIENT)
12-04 06:07:53.113 17114 17138 E openal  : AL lib: ALCopenslCapture_open: bufferQueue->Enqueue: Buffer insufficient
12-04 06:07:53.118 17114 17138 D openal  : AL lib: FreeDevice: 0x75cc8e7000
12-04 06:07:53.118 17114 17138 W openal  : AL lib: alcSetError: Error generated on device 0x0, code 0xa004

-- main.lua
function love.load()
  local mic_list = love.audio.getRecordingDevices()
  if #mic_list > 0 then
    local mic = mic_list[1] -- There is only one device in mic_list
    print(mic:getName()) -- OpenSL
    print(mic:start(8000)) -- false
  else
    errror('No recording devices found')
  end
end

-- conf.lua
function love.conf(t)
  t.audio.mic = true
end

slime73 commented 4 years ago

Original comment by Miku AuahDark (Bitbucket: AuahDark, ).


My device is Mi A1 (stock ROM Android 9) and I can confirm it works. You may want to check this forum posts for more information: https://love2d.org/forums/viewtopic.php?f=4&t=88151&p=231799#p231799

jmiskovic commented 4 years ago

The linked method of searching for correct recording parameters works for me. The buffer length is especially sensitive. On Pixel 2 I can record in mono with 48000 sample rate and 16 bit depth, and buffer length of 16384 is the only one accepted.

When using the getData() to collect multiple recordings and join them, I can record longer lengths of sound, but there is a glitch in joined recording. I could also reproduce same glitch with code provided on forum, across two phones. The glitch sounds as if one buffer is dropped. It always occurs around 0.4 seconds from start of recording, which should be on collected buffer number 8. On desktop the glitch is not reproducible. Any idea how to fix it?

Also, I think Love2D documentation incorrectly states that ring buffer is used for recording and that new data overwrites old data. In all my experiments with single buffer recording (without getData) the resulting recording contains only beginning of recorded sound and everything after buffer is filled is lost.

MikuAuahDark commented 4 years ago

but there is a glitch in joined recording. I could also reproduce same glitch with code provided on forum, across two phones. The glitch sounds as if one buffer is dropped. It always occurs around 0.4 seconds from start of recording, which should be on collected buffer number 8.

Can you provide minimal main.lua which reproduces the issue?

MikuAuahDark commented 3 years ago

While I was testing the new OpenAL-soft update, I can reproduce the "glitch" issue. However I'm not sure if it's LOVE, OpenAL-soft, or even OpenSLES fault.

jmiskovic commented 3 years ago

In my app (source here) I implemented a workaround for this.

I start recording in advance and discard samples in background. Only when user presses and holds the MIC button are the samples actually captured. This works without the mentioned glitch, but with a different downside. It's not possible to sync the rolling buffer with button press. This means the captured sound will often have samples from even before the button was pressed.

MikuAuahDark commented 3 years ago

I'd see if I can find and compile a recording example program from OpenAL-soft. If it turns out to have issues too, then I'd report it to OpenAL-soft instead.

MikuAuahDark commented 3 years ago

I ended up reporting the problems to upstream: kcat/openal-soft#517

jmiskovic commented 3 years ago

Thank you for your effort!

MikuAuahDark commented 2 years ago

Fixed in LOVE 12.0. efbf3f5500008d46d965e3003ea62a04e450cd53 love2d/megasource@b9964119f5af9942590328076b75830f3e6adb22.