ar1st0crat / NWaves

.NET DSP library with a lot of audio processing functions
MIT License
453 stars 71 forks source link

Xamarin Android not play wav file #45

Closed slagusev closed 3 years ago

slagusev commented 3 years ago
            try
            {
                using (var stream = new FileStream(fistBank, FileMode.Open))
                {
                    var waveFile = new WaveFile(stream);
                    signal = waveFile[Channels.Left];
                }
            }
            catch(Exception ex)
            {
                Toast.MakeText(Application.Context, ex.ToString(), ToastLength.Short).Show();
            }

Added to the project, added permissions for reading files, I get the path to the file. I press the button and silence ... The file does not play ... It does not even generate signals from examples

ar1st0crat commented 3 years ago

This code is not supposed to play audio file. It just parses WAV file and loads data into DiscreteSignal object (essentially, array of audio samples). In NWaves only the very basic playback/recording is supported and only for Windows clients. The main purpose of this lib is signal processing. So, for audio playback you'll need to write some Android native code (maybe using Android.Media.MediaPlayer class) or use Xamarin audio/media plugins/packages that can be found over Internet.

slagusev commented 3 years ago

That is, receive sound from signal if from the code above? I tried it through BASS anyway silence

            using (var stream = new FileStream(fistBank, FileMode.Open))
            {
                var waveFile = new WaveFile(stream);
                signal = waveFile[Channels.Average];
                int length = signal.Length;
                byte[] buffer = new byte[length];

                _hGCFile = GCHandle.Alloc(buffer, GCHandleType.Pinned);

                if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
                {
                    int b_stream = Bass.BASS_StreamCreateFile(_hGCFile.AddrOfPinnedObject(), 0L,length, BASSFlag.BASS_SAMPLE_SOFTWARE | BASSFlag.BASS_SAMPLE_FLOAT);

                    if (b_stream != 0)
                    {
                        Bass.BASS_ChannelPlay(b_stream, false);
                    }
                }
            }