naudio / NAudio

Audio and MIDI library for .NET
MIT License
5.57k stars 1.1k forks source link

Implementing WaveOutEvent for Android #1027

Open MilesFan opened 1 year ago

MilesFan commented 1 year ago

I am working on an MAUI Blazor application using NAudio, and NAudio is very helpful.

MAUI Blazor is cross-platform and I am expecting this application also works on Android (and maybe iOS in the future).

I understand NAudio WaveOut is just for Windows, and I try to make an Android implementation with Android AudioTrack which is available in Xamarin Android SDK.

However, reinventing the wheel has not been very successful, there are bugs here and there (my fault). So I thought I may as well just mimic WaveOutEvent.

I digged a bit into WaveOutEvent and find out WaveInterop seems to be the only thing Windows-specific, and I tried to replace it with Android AudioTrack. But I am now stuck because it works very differently to Android AudioTrack. To be more specific, I have no idea how to get WaveOutBuffer work with Android AudioTrack.

Has anyone got an idea?

markheath commented 1 year ago

The key interface in NAudio for playing audio is IWavePlayer. To support NAudio on android, you'd need to adapt whatever the AudioTrack can do to the IWavePlayer interface. You wouldn't use WaveOutBuffer at all.

SineVector241 commented 1 month ago

https://gist.github.com/SineVector241/58152564e615066132b081e8e2d00645 : Recorder Implementation https://gist.github.com/neilt6/6d07322070470536ea0ba409c343c2a5 : Playback Implementation - Note: I have a comment on that gist with a more recent/updated version.