I’m developing a UWP application ( for Windows 10) which works with audio data. It receives samples buffer at the start in the form of a float array of samples, which items are changing from -1f to 1f. Earlier I used NAudio.dll 1.8.0 that gives all necessary functionality. Worked with WaveFileReader, waveBuffer.FloatBuffer, WaveFileWriter classes. However, when I finished this app and tried to build Release version, got this error: ILT0042: Arrays of pointer types are not currently supported: 'System.Int32*[]'.
I’ve tried to solve it:
There is advice to remove the link to .dll, but I need it.
I’ve tried to install NAudio the same version using Manage NuGet Packages, but WaveFileReader, WaveFileWriter is not available.
In NAudio developer’s answer (How to store a .wav file in Windows 10 with NAudio) I’ve read about using AudioGraph, but I can build float array of samples only in the realtime playback, but I need get the full samples to pack right after the audio file uploading. Example of getting samples during the recording process or playback: https://learn.microsoft.com/ru-ru/windows/uwp/audio-video-camera/audio-graphs
That’s why I need help: how to get FloatBuffer for working with samples after audio file uploading? For example, for building audio waves or calculation for audio effects applying.
Thank you in advance.
I’ve tried to use FileStream and BitConverter.ToSingle(), however, I had a different result compared to NAudio. In other words, I’m still looking for a solution.
private float[] GetBufferArray() { string _path = ApplicationData.Current.LocalFolder.Path.ToString() + "/track_1.mp3"; FileStream _stream = new FileStream(_path, FileMode.Open); BinaryReader _binaryReader = new BinaryReader(_stream); int _dataSize = _binaryReader.ReadInt32(); byte[] _byteBuffer = _binaryReader.ReadBytes(_dataSize); int _sizeFloat = sizeof(float); float[] _floatBuffer = new float[_byteBuffer.Length / _sizeFloat]; for (int i = 0, j = 0; i < _byteBuffer.Length - _sizeFloat; i += _sizeFloat, j++) { _floatBuffer[j] = BitConverter.ToSingle(_byteBuffer, i); } return _floatBuffer; }
AudioFileReader
orMp3FileReader
class?AudioFileReader
will give you a float[] of the audio data right out of the box. – MaidieMediaFoundationReader
class, which should read most common audio files for you. – Maidie