Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make recording in-place and fix the WAV header on the Android platform #151

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

t871005y
Copy link
Contributor

I notice that all platforms except Android record audio in place. For example, during recording, the audio file should be saved directly to the specified path in the code.

However, on Android, the audio file is initially saved to a temporary path during recording and then copied to the specified path after recording stops. This process may lead to issues such as losing important audio files if the app crashes during recording. But if we save the audio file directly to the specified path during recording, we can simply repair the WAV header at that path to recover it in case the recording does not stop normally.
To fix this issue, I think we can write the WAV header before the audio data to reserve space, and then update it after recording to finalize the audio file.

Additionally, I also found some issues with creating WAV headers on the Android platform.

BlockAlign(Number of bytes per block) shoud be (NumberOfChannels* BitsPerSample / 8). The default channel is mono, so this option is incorrect by default setting.

header[32] = (byte)(2 * 16 / 8); // block align

Thanks to PR #108, we can adjust the bit depth (number of bits per sample), so it should be variable rather than constant. If you use Pcm8bit on the current version of Plugin.Maui.Audio.Sample, it will produce incorrect results, playing as noise.

header[34] = Convert.ToByte(16); // bits per sample

@jfversluis
Copy link
Owner

Wow this is amazing! Thank you so much! I'll look at this asap!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants