Closed CodElixer closed 2 years ago
Hmm, that's a really weird issue. To make sure I'm understanding, you're saying that the files are always 20 seconds, but sometimes it's:
Is that correct?
After work today, I'll make a debug build for you to try out that will not do any encoding/compression and just output a raw .wav
file. Those output files will be the exact audio that the Android system provides to BCR. Hopefully there will be no issue there, but if the overlapping still happens, then it might not be fixable because Android itself is producing bad audio.
Hmm, that's a really weird issue. To make sure I'm understanding, you're saying that the files are always 20 seconds, but sometimes it's:
- 7 seconds of good audio + 13 seconds overlapped
- 11 seconds of good audio + 9 seconds overlapped
- 20 seconds of good audio
Is that correct?
After work today, I'll make a debug build for you to try out that will not do any encoding/compression and just output a raw
.wav
file. Those output files will be the exact audio that the Android system provides to BCR. Hopefully there will be no issue there, but if the overlapping still happens, then it might not be fixable because Android itself is producing bad audio.
Yes, I'm always recording for 20 seconds, so originally file should be of 20 seconds long. But sometimes the output files are:
For 7 seconds long output file, Remaining 13 seconds of audio overlapping in between 6th to 7th second of the output file.
For 11 seconds long output file, Remaining 9 seconds of audio overlapping in between 10th to 11th second of the output file.
So, This is the issue.
Could you give these 2 debug builds a try?
.wav
fileHopefully the overlapping doesn't occur in the wav files. If it still happens, there's nothing BCR can do to fix it--the raw audio from Android is already broken.
Could you give these 2 debug builds a try?
Both the r2 and r3 files are working fine!
- Output from 2nd file(BCR-1.4.r3.gaa21633-debug-dump_raw_wave_16kHz) is having less size in comparison of 1st file.
Output from 1st File (BCR-1.4.r2) https://easyupload.io/cesv9b
Output from 2nd file (BCR-1.4.r3 16kHz) https://easyupload.io/cv2i9w
Dump file from latest BCR v1.5 with default MPA format, 64 kbps Bitrate. https://easyupload.io/qahsaw
Here you can see the audio distortion at last 20th second!
That's good news! So it seems like call recording words, but encoding/compression is broken on your device.
Can you try running this apk? CodecDump.zip (It's a regular apk that can be directly installed--not a magisk module.)
It should print out something like this: Screenshot_20220528-161832
Can you copy and paste (or upload) that full text here?
On my device, there are:
c2.android.aac.encoder
c2.android.opus.encoder
c2.android.flac.encoder
I wonder if the ROM you're running has additional/different encoders that might be broken.
Yeah sure, here you go CodecDump.txt
Hmm, so it uses the same encoders as on my Google Pixel. I wonder why it might be broken.
Hmm, so it uses the same encoders as on my Google Pixel. I wonder why it might be broken.
Does it(The CodecDump file) changes according to the ROM you're using? Because My device is Xiaomi's Poco F1 and Running Pixel Experience custom ROM based on Pixel 6 Pro device!
Does it(The CodecDump file) changes according to the ROM you're using?
I haven't tried anything besides the stock ROM and pure AOSP. Same codecs in those two.
Just incase you needed, Here's the dump file from Poco F1's Stock Android 10 ROM.
Do you know if the overlapping issue happens in that stock ROM also?
So far, I'm not having any luck troubleshooting what the problem might be. I can't reproduce it on my Pixel and don't have any other devices to test on. I'm adding WAV as a supported output type in version 1.6 so at least you can have something working while we try to fix this.
Do you know if the overlapping issue happens in that stock ROM also?
On stock ROM, There was Xiaomi's Default call recorder which was using mp3 codec and saving the files in format like "contact name/number(number)_YYYYMMDDTTMMSS.mp3", example: Complaint Helpline(198)_20220409180752.mp3 There the recording was working flawlessly because it was by default supported by the ROM itself.
So far, I'm not having any luck troubleshooting what the problem might be. I can't reproduce it on my Pixel and don't have any other devices to test on. I'm adding WAV as a supported output type in version 1.6 so at least you can have something working while we try to fix this.
Yeah, No issues!👍🏻 Just wanted to let you know that the .wav ui is missing from the format selection buttons. It's still working but not showing there, There might be the issue with the width, sharing you the screenshot of the issue. And also if you could add that 16kHz option too in upcoming version for wav file that'll take some less space.
Hmm, that's a really weird issue. To make sure I'm understanding, you're saying that the files are always 20 seconds, but sometimes it's:
- 7 seconds of good audio + 13 seconds overlapped
- 11 seconds of good audio + 9 seconds overlapped
- 20 seconds of good audio
Is that correct?
After work today, I'll make a debug build for you to try out that will not do any encoding/compression and just output a raw
.wav
file. Those output files will be the exact audio that the Android system provides to BCR. Hopefully there will be no issue there, but if the overlapping still happens, then it might not be fixable because Android itself is producing bad audio.
Have this issue. M4A/AAC glitches at like 5-10 seconds in to recording after few seconds it becomes clear and continue to record. When glitches the seek bar on player moves backwards. OGG/Opus has the same issue. Device:Poco f1 ROM: Pixel Experience+ a12
Just wanted to let you know that the .wav ui is missing from the format selection buttons. It's still working but not showing there, There might be the issue with the width, sharing you the screenshot of the issue.
Oops! I'll find a way to fix that (probably allow the buttons to be on multiple rows).
I'll let you know later about how the BCR is working on stock ROM.
:+1:
On stock ROM, There was Xiaomi's Default call recorder which was using mp3 codec and saving the files in format like "contact name/number(number)_YYYYMMDDTTMMSS.mp3", example: Complaint Helpline(198)_20220409180752.mp3 There the recording was working flawlessly because it was by default supported by the ROM itself.
Oh, that's interesting. Can you link to a download of the stock ROM? Maybe I can figure out what the stock recorder does differently.
Oh, that's interesting. Can you link to a download of the stock ROM? Maybe I can figure out what the stock recorder does differently.
Here is the link for Official Stock ROM. There you'll find two types:
Hope this helps :)
It looks like that MIUI ROM has different recording methods depending on the output format:
AudioRecord
API.wav
header manuallyAudioRecord
APIMediaRecorder
APISo, it seems like MIUI doesn't use the MediaCodec
API at all (which is what BCR uses for encoding). That must be where the overlapping issue is happening.
By the way, a random thought I had: does MIUI have a battery power save mode? If it has a power save mode, does it make any difference for when the overlapping occurs?
So, it seems like MIUI doesn't use the
MediaCodec
API at all (which is what BCR uses for encoding). That must be where the overlapping issue is happening.
Oh! Then it seems might be using Android's AudioRecord
API and Encoding using the LAME library.
And this might be patent encumbered in some countries.
By the way, a random thought I had: does MIUI have a battery power save mode? If it has a power save mode, does it make any difference for when the overlapping occurs?
Yes, I agree MIUI Power Save mode is aggressive. But when I was on MIUI Stock ROM then atleast call recording was working irrespective of Battery Power Save On/Off. There I wasn't using any external call recorder as it was internally supported.
But now I'm permanently moved to Pixel ROM (Android:12L) and here Google Dialer's default call recording is also working without any issues which is also recording in wav form!
Just incase, This is the link of the Pixel ROM that I'm using.
Can you give the test build in #59 a try? I think I may have found the issue :slightly_smiling_face:
Can you give the test build in #59 a try? I think I may have found the issue :slightly_smiling_face:
Whoa mate!! It's working perfectly.
Debugged All formats with native sample bitrate and flac with 8 level of compression and as of now it's seems working without any issues!!🎉
Awesome, thanks for testing and being patient with me while troubleshooting this issue!
It turns out it was a BCR bug and pretty easy to fix :D I'll release version 1.8 with this fix in a little bit.
Version 1.8 has been released!
Awesome, thanks for testing and being patient with me while troubleshooting this issue!
No issues, Any time :)
It turns out it was a BCR bug and pretty easy to fix :D I'll release version 1.8 with this fix in a little bit.
Cheers!🎉
Just wondering why there's size difference between both the files?
Version 1.8 has been released!
Recording files for 20 seconds but the total duration is only of 18 seconds and the overlapping/glittering can be heard between 16th to 18th second.
I'd kept OGG format with default bitrate and sample rate.
Also tested for flac and here the duration was only of 8 seconds.
Crap :( Hmm, I wonder why. It should be the same, except a release build instead of a debug build. Do you have the same issue with these?
Just wondering why there's size difference between both the files?
The release builds remove code that's unused by the app, mostly things from the Materal Design library.
Crap :( Hmm, I wonder why. It should be the same, except a release build instead of a debug build. Do you have the same issue with these?
Will let you know shortly but now when I moved back to 1.7 debug file and checked with OGG & Flac codec with default sample rate and bitrate then the issues was occuring there too during 6 to 11 second! 🫤
Mentioned the Original recording length as well as the issue between duration in File name itself. https://easyupload.io/jos4lj
I'll take a look a bit more tomorrow. I'll probably make a debug build that creates a log file with some more information.
I wonder why it's no longer working even after you reverted to BCR-1.7.r4.g39767d3-debug.zip
. That's very strange.
I'll take a look a bit more tomorrow. I'll probably make a debug build that creates a log file with some more information.
Yeah sure! No hurry, It seems this issue will take some time 🧘🏻.
I wonder why it's no longer working even after you reverted to
BCR-1.7.r4.g39767d3-debug.zip
. That's very strange.
Yes, It's strange! Also tried turning off WiFi as WiFi call was always enabled, but no success on 1.7 debug.
I split out BCR's encoding step into a separate test app to make it a bit easier to test. Can you give this apk a try? MediaCodecAudioEncodeTest.zip
It should look something like this: Screenshot_20220601-131928
Can you try selecting a good .wav
file and use this test app to convert to .flac
? Does it still have overlapping audio?
EDIT: Please also try this BCR debug build with flac + native sample rate. Nothing was changed with the encoding code, I just added a bunch of things for debugging. BCR-1.8.r2.g6eda631-debug.zip
It should hopefully produce 3 files in the output directory:
<filename>.flac
- Encoded recording (with overlapping)<filename>.raw.wav
- WAV recording (without overlapping)<filename>.txt
- Log file with debug information (the phone number, caller name, etc. should be automatically removed, but please verify :slightly_smiling_face:)Can you upload those?
Can you upload those?
Hi! I'm sharing you all the output files in a single zip. You'll get 3 zip files inside the main zip, each will be having ReadMe.txt please read those txt files for description of the issues.
Hope this helps:)
Hi Andrew,
Problem seems resolved in BCR-1.8.r2.g6eda631!
I also install BCR-1.8.r2.g6eda631-debug.zip on my Poco F2 Pro (K30 Pro) and debug files are here: https://easyupload.io/m/l3whhz
But the main message, i have no error in OGG file (default settings)!
it is only 2 minutes 11 sec but no error! ill do longer tests now.
what did you change since official 1.8 ?
Best Regards, Robert
37 minutes long call with OGG 48kbps, 8000Hz has no error at all! So i think you solved the issue with conversion. :) Thank you very much.
Thank you both for testing!
So from previous tests, we know that recording part was not the problem because the .wav
(no encoding/compression) works fine. This is done via Android's AudioRecord
API.
Then, what I suspected was Android's MediaCodec
API, which handles the Opus/AAC/FLAC encoding, but that turned out not to be the case either. I made a test app to only perform the .wav
to .flac
conversion. From @YASHKRAJ's upload, I compared the wav and flac:
The top is the .wav
, the middle is the .flac
, and the bottom is the .flac
subtracted from the .wav
. Since it's empty, the audio in the two files are identical.
So, by itself, there's no problem in the recording and no problem in the encoding. BCR's recording process is essentially:
From @YASHKRAJ's log file, we have:
06-02 15:02:52.002 11167 3424 D RecorderThread: [691] Encoded 1755648 frames at 48000; submitting buffer with index: 2, size: 4608, timestamp: 36576000, buffer: [0..4608] -> [4608..4608]
06-02 15:02:52.794 11167 3424 D RecorderThread: [691] Encoded 1757952 frames at 48000; submitting buffer with index: 3, size: 4608, timestamp: 36624000, buffer: [0..4608] -> [4608..4608]
Looking at the log, the buffer is size: 4608
. (4608 bytes) / (2 bytes per sample) / (48000 samples per second) = 0.048 seconds = 48ms. This means the call audio is recorded in 48ms chunks. The time it takes to encode each chunk must not take more than 48ms or else the audio will be broken. So this is really a CPU usage issue.
In the logs above, the chunk at timestamp: 36576000
(~36.6 seconds) was recorded at 15:02:52.002
, but the next chunk wasn't recorded until 15:02:52.794
. So that chunk took 792ms to encode... way more than the 48ms needed for a smooth recording. This matches what @YASHKRAJ said:
2nd test had issue at 36 second.
The real fix is to move the encoding process to a different thread. That way, even if encoding is slow, it will not block the recording and won't cause dropped samples.
Right now, I'm planning:
The dropped frames from @YASHKRAJ's logs:
1. 20220602_145822.791+0530_out_198.txt
- 0 drops (click to expand):2. 20220602_150212.922+0530_out_198.txt
- 2 drops (click to expand):3. 20220602_150802.947+0530_out_198.txt
- 3 drops (click to expand):The dropped frames from @robertio's logs:
20220602_174829.874+0200_out_1270.txt
- 151 drops (click to expand):Hi Andrew,
I don't fully understand the explanation you provided because I'm not a programmer, but very rarely seen so detailed, so clear precise explanation. You do an awesome job! Many thanks!
Question 1: I don't understand if my log shows 151 drops, why I don't hear any problem in ogg file? Question 2: Why I don't have heard any jumps in my ogg file and YASHKRAJ still has? Question 3: I also not understand, why audacity analysis didn't show the error at 36 second? Question 4: As I said I don't fully understand, the problem and the encoding mechanism, but if cpu resources could cause issues, then the maybe the approach should be changed. Post process, or multi threads (as u wrote). I don't know which and how. :) Please consider my phone -K30 Pro is very strong hardware. Can it cause that I don't have jump/overlap issue with this BCR-1.8.r2.g6eda631-debug?
Thanks and no problem!
Question 1: I don't understand if my log shows 151 drops, why I don't hear any problem in ogg file? Question 2: Why I don't have heard any jumps in my ogg file and YASHKRAJ still has? ... Can it cause that I don't have jump/overlap issue with this BCR-1.8.r2.g6eda631-debug?
It might be because of how short the drops are. Yours only exceed the limit a lot more, but only by around 30-35ms and they're pretty consistent (no big jumps). Android can probably tolerate this. YASHKRAJ's had some that were >200ms over and one that was ~800ms over.
Question 3: I also not understand, why audacity analysis didn't show the error at 36 second?
The debug build recorded both .wav
and .flac
/.ogg
at the same time. I did the analysis in audacity to prove that both of the files are identical, so the issue was not caused by a bug in the encoding process. The issue could be heard at 36 seconds in both files.
The CPU load caused by the encoding was slowing down the recording part too much that it affected both the raw audio and the encoded audio.
Question 4: As I said I don't fully understand, the problem and the encoding mechanism, but if cpu resources could cause issues, then the maybe the approach should be changed. Post process, or multi threads (as u wrote). I don't know which and how. :)
Yeah, post processing is not a bad idea either.
Please consider my phone -K30 Pro is very strong hardware.
Definitely! I don't think hardware is the issue. Real-time audio is just hard to get right :)
By the way, does your ROM have built-in screen recording with the "device audio and microphone" mode? Screenshot_20220603-004049 I'm curious if the audio is smooth in those recordings. It records almost exactly the same way as BCR's M4A/AAC mode, except it records from the microphone instead of a phone call.
Hi Andrew, Thanks for very clear explanations! I got it now. I tried built in screen recorder with the proposed settings - and it was flowless, no jump or any issue. So im waiting now to test anything you need.
It turns out MediaCodec is already multithreaded so no changes are needed there.
In version 1.10, I made one final change to give the recording thread a very high CPU priority. Not sure if it helps, but maybe :)
It seems like default OGG/Opus recording is already working well on your devices. I don't think there's anything else I can do to make it better for the slower codecs (eg. FLAC).
Isn't it strange? Bcz: on my device (with sdm732 - which is not that slow) other call recording apps (boldbeast/axet call rec) don't have this (overlapping audio) bug. So, is it really a CPU related thing? And, i tried flac/ops/flac - with least bit rates also, still mostly there was an overlapping...
N.B.: your BCR is very reliable regarding recording calls on A12. (While axet call rec mostly skip recoding calls on A12 devices, idk why)
And, no audio source issue in ur app (like some crappy apps uses mic to rec calls).
So, your app is robust. Thanks for building it.
I only compared with other apps regarding the overlapping issue (not regarding reliability)
It seems like default OGG/Opus recording is already working well on your devices. I don't think there's anything else I can do to make it better for the slower codecs (eg. FLAC).
First of all thanks for continuosly working on this issue to resolve it!
What I'd found that v1.9 was very unstable, it had more audio drops in comparison to previous versions.
I always try to keep recordings in ogg format but on 1.10 version, When I recorded a 4min 2sec long call then the total duration was only of 2min 42sec and the audio issue started from 2min 24th sec whereas the Google's default recorder which records in wav format had recorded total of 4min 2sec call and it hasn't any audio drop issue.
First of all thanks for continuosly working on this issue to resolve it!
No problem! I don't like giving up :slightly_smiling_face:
So, your app is robust. Thanks for building it.
Thank you!
I'm trying a slightly different approach this time. Does this debug build help at all? BCR-1.10.r9.g7c88a96-debug.zip (Please upload the audio and .log.txt
file if possible.)
I significantly increased the buffer size for recording so that if encoding slows down, it can "absorb" the impact. It should hopefully be able to handle up to an 800ms slowdown spike without causing the overlapping audio (maybe!).
There should be no downside to doing this (the latency increases, but doesn't matter for recording purposes). Please let me know if this debug build is somehow worse than previous versions.
1.log.txt Btw, this time no overlapping happened! Call duration and recoding duration is same. I tested for a few calls, since v1.10, and, all of them are okay (16Khz, 24kbps m4a)
No problem! I don't like giving up :slightly_smiling_face:
Exactly! That's why we're still here on the path of resolving this issue :)
I'm trying a slightly different approach this time. Does this debug build help at all? BCR-1.10.r9.g7c88a96-debug.zip (Please upload the audio and
.log.txt
file if possible.)Here are the some recordings which have issue and some haven't. Please check the zip and read the prefix of file name and if it has text file then read that also for that folder.
Probability of the issue of recordings at 8000Hz sample rate has less comparatively.
Thanks for the logs!
06-05 21:05:51.080 11968 27890 D RecorderThread/2442: AudioRecord minimum buffer size: 640
That is interesting. That buffer size is 1/3 of what it is on my Pixel. (I believe this is controlled by the vendor firmware, not by the ROM.)
Also, this is is interesting/weird from 20220605_210548.762+0530_out_198.log.txt
. It's writing a .wav
file, so there's no compression/encoding, but somehow, there's a bunch of:
<...> 199.XXXXXXms
<...> 399.XXXXXXms
There should be no reason it takes that long to write < 1KB to the output file.
Out of curiosity, do you have BCR configured to record to the internal storage or an SD card?
Noticed in the BCR-1.10.r9.g7c88a96-debug build Native Sample Rate option was missing in all the codec option
Ah yep, I forgot to mention this. That option had to be removed to be able to change the buffer size. Otherwise, it has to start recording once to detect the sample rate and then stop and restart again to set the buffer size (might cause a couple seconds at the beginning of the call to be lost).
and WAV codec haven't any bitrate slider(don't remember if previously it had).
This part is normal. WAV doesn't support compression, so there's nothing to configure.
Out of curiosity, do you have BCR configured to record to the internal storage or an SD card?
Recording in the SD Card.
I'd tried changing Recording Location previously in the initial builds of BCR but that time the issue was still there and so after that I haven't tried it.
But when now changed the location to default "storage/emulated/0/Android/data/com.chiller3.bcr/files"
on latest v1.10 debug then till now I haven't faced the issue.
I'll test further if I found any issues or it just fixed the issue.
Hi,
Still has jumps with BCR 1.10 and also with the BCR-1.10.r9.g7c88a96-debug.
OGG - My log and oga file is here: https://easyupload.io/m/prurv7 - made with BCR-1.10.r9.g7c88a96-debug. First jumps at around ~20seconds. Call was 1 minute but recorded file is only 53 seconds. Settings: ogg/opus 48kbps, 12000Hz.
WAV also has jumps. Log and wav is here: https://easyupload.io/m/t4pwa5- made with BCR-1.10.r9.g7c88a96-debug. First jumps at around ~10seconds. Call was 1:35 minute but recorded file is only 1:22 m. Settings: wav/pcm 8000Hz.
I save the record files here:
but this only a virtual "external" -it is on the internal flash, -because my phone doesent have external SD at all.
Hey!! Good news!
If i changed the file save folder to the default, then sounds the records works properly!!
As YASHKRAJ reported also.
But this is very strange in my case because i have only built in memory -no SD- so the filesystem speed should not change when i change the location, however the partitions format can be different.
Andrew: @chenxiaolong Do you need me to change back to debug and make some debug file?
Awesome! It seems like file://
works for both of you, so maybe this is Android's SAF (storage access framework) being slow for small writes.
I created a new debug build: BCR-1.10.r21.gbeb47e0-debug.zip
This build always records to the default file://
path initially and then moves the files to the selected output directory when the recording is complete.
Hi @chenxiaolong
I tried latest v1.4 too but the audio recording overlapping is still there!
Say If I record for a 20 seconds long call then sometimes it's the recorded duration only getting 7 seconds, sometimes it's 11 seconds and sometimes whole 20 seconds!
When the duration reducing say for 7 seconds long recording then the remaining recording of 13 seconds seems getting overlapped between 6th to 7th second of the recorded audio!
I've also allowed BCR to run in the background, So there's no issue with getting it killed in background.