public unsafe int Read(float[] buffer, int offset, int sampleCount) { //return FAudioFile.Read(buffer, offset, sampleCount); int bytesread = 0; if (FIsPlaying) { bytesread = FAudioFile.Read(buffer, offset, sampleCount); if (bytesread == 0) { if (FLoop[0]) { FAudioFile.CurrentTime = FLoopStartTime; FRunToEndBeforeLooping = false; bytesread = FAudioFile.Read(buffer, offset, sampleCount); } else { FIsPlaying = false; bytesread = FSilence.Read(buffer, offset, sampleCount); } } } else { bytesread = FSilence.Read(buffer, offset, sampleCount); } return(bytesread); }
private int ReadSamplesToLocalBuffer(int sampleCount) { int totalSamplesRead = 0; int numChannels = sourceStream.WaveFormat.Channels; if (isBackwardsLoop) { SamplePosition -= sampleCount / numChannels; } while (totalSamplesRead < sampleCount) { int samplesToRead = sampleCount - totalSamplesRead; int samplesRead = sourceStream.Read(overlapBuffer, totalSamplesRead, samplesToRead); totalSamplesRead += samplesRead; } if (isBackwardsLoop) { SamplePosition -= totalSamplesRead / numChannels; } return(totalSamplesRead); }
public int Read(float[] buffer, int offset, int count) { var read = _reader.Read(buffer, offset, count); if (read < count) { _reader.Position = 0; read = _reader.Read(buffer, offset, count); } return(read); }
public List <float> read(string selectedFile, long samples) { using (var reader = new AudioFileReader(selectedFile)) { int i = 0; List <float> values = new List <float>(); float[] q = new float[samples]; while ((i = reader.Read(q, 0, q.Length)) > 0) { i = reader.Read(q, 0, q.Length); values.AddRange(q); } return(values); } }
private static bool FindMax(string file, out AudioFileReader reader, float volume) { float max = 0; reader = new AudioFileReader(file); // find the max peak float[] buffer = new float[reader.WaveFormat.SampleRate]; int read; do { read = reader.Read(buffer, 0, buffer.Length); for (int n = 0; n < read; n++) { var abs = Math.Abs(buffer[n]); if (abs > max) { max = abs; } } } while(read > 0); //Console.WriteLine($"Max sample value: {max}"); if (max == 0 || max > 1.0f) { return(false); } // rewind and amplify reader.Position = 0; reader.Volume = volume / max; return(true); }
private void NewSongSelected() { songFile = new FileInfo(directorySelectorController.selectedItemFullName); songNameText.text = songFile.Name; project.songName = songNameText.text; directorySelectorController.DeactivateSelection(); if (songFile.Extension == ".wav" || songFile.Extension == ".ogg") { WWW www; www = new WWW("file:///" + songFile.FullName); while (!www.isDone) { ; //Wait until the song is fully downloaded } songAudioClip = www.GetAudioClip(true); songAudioClip.LoadAudioData(); } else if (songFile.Extension == ".mp3") { AudioFileReader reader = new AudioFileReader(songFile.FullName); float[] data = new float[reader.Length / 4]; reader.Read(data, 0, (int)reader.Length / 4); AudioClip newClip = AudioClip.Create("SongAudioClip", data.Length / reader.WaveFormat.Channels, reader.WaveFormat.Channels, reader.WaveFormat.SampleRate, false); newClip.SetData(data, 0); songAudioClip = newClip; songAudioClip.LoadAudioData(); } stage.musicSource.clip = songAudioClip; stage.timeSlider.value = 0.0f; stage.timeSlider.maxValue = songAudioClip.length; stage.OnSliderValueChanged(); }
public List <string> CreateSpectograms(string audioFilePath) { LOGGER.Info("Reading audio file."); List <string> result = new List <string>(); using (AudioFileReader audioFile = new AudioFileReader(audioFilePath)) { List <double> audioData = new List <double>(); int percentageDone = 0; float[] buffer = new float[BUFFER_SIZE]; int samplesRead = -1; do { LOGGER.Debug("Reading samples to buffer (size: {buffersize})", BUFFER_SIZE); samplesRead = audioFile.Read(buffer, 0, BUFFER_SIZE); audioData.AddRange(buffer.Take(samplesRead).Select(x => (double)x)); // another percent done int percentage = (int)(audioFile.Position * 100 / audioFile.Length); if (percentage != percentageDone) { percentageDone = percentage; LOGGER.Info("Creating spectrograms .. completed {per,3}% .. saving image.", percentageDone); // make sure the spectrogram ends during a pause (except at 100%) int splitIndex = (percentageDone == 100) ? audioData.Count : DetermineSplitIndex(audioData); result.Add(SaveIndexedSpectogram(audioData, audioFile.WaveFormat.SampleRate, splitIndex, percentageDone)); // save post-split data and make it the start of the new block audioData = audioData.TakeLast(audioData.Count - splitIndex).ToList(); } } while ((samplesRead > 0) && (percentageDone < RUN_X_PERCENT)); } return(result); }
public void Test_WavFile_ReadASehgal() { // READ THE WAV FILE WITH NAUDIO double[] audio; int sampleRate; string wavFilePath = "../../../../../data/asehgal-original.wav"; using (var audioFileReader = new AudioFileReader(wavFilePath)) { sampleRate = audioFileReader.WaveFormat.SampleRate; var wholeFile = new List <float>((int)(audioFileReader.Length / 4)); var readBuffer = new float[audioFileReader.WaveFormat.SampleRate * audioFileReader.WaveFormat.Channels]; int samplesRead = 0; while ((samplesRead = audioFileReader.Read(readBuffer, 0, readBuffer.Length)) > 0) { wholeFile.AddRange(readBuffer.Take(samplesRead)); } audio = Array.ConvertAll(wholeFile.ToArray(), x => (double)x); } // TEST VALUES ARE WHAT WE EXPECT double lengthSec = (double)audio.Length / sampleRate; Assert.AreEqual(40_000, sampleRate); Assert.AreEqual(40, lengthSec, .01); // CREATE THE SPECTROGRAM int fftSize = 8192; var spec = new Spectrogram(sampleRate, fftSize, stepSize: 4_000, maxFreq: 2_000); spec.Add(audio); spec.SaveImage("asehgal.png", intensity: 10_000, dB: true); }
// Creates a Unity AudioClip from an audio file public static AudioClip LoadAudio(string filePath) { AudioClip audioClip; if (AudioClipCache.TryGetValue(filePath, out audioClip)) { return(audioClip); } try { using (var reader = new AudioFileReader(soundPath + filePath)) { var length = reader.Length / 4; var samples = new float[length]; reader.Read(samples, 0, samples.Length); var name = Path.GetFileNameWithoutExtension(filePath); var channels = reader.WaveFormat.Channels; var frequency = reader.WaveFormat.SampleRate; audioClip = AudioClip.Create(name, (int)length, channels, frequency, false); audioClip.SetData(samples, 0); AudioClipCache.Add(filePath, audioClip); return(audioClip); } } catch (Exception) { return(null); } }
/// <summary> /// Gets the peak byte from the audio file reader. /// </summary> /// <param name="reader">The reader.</param> /// <returns>The peak byte as an absolute value.</returns> public virtual float GetPeak(AudioFileReader reader) { float peak = 0; var buffer = new float[reader.WaveFormat.SampleRate]; int read; // determine the peak do { read = reader.Read(buffer, 0, buffer.Length); for (int n = 0; n < read; n++) { var abs = Math.Abs(buffer[n]); if (abs > peak) { peak = abs; } } } while (read > 0); // rewind the reader and set the volume reader.Position = 0; return(peak); }
public static void Main(string[] argv) { ISampleProvider reader = new AudioFileReader("samples/sample.wav"); List <float> allSamples = new List <float>(); float[] samples = new float[1024]; while (reader.Read(samples, 0, samples.Length) > 0) { for (int i = 0; i < samples.Length; i++) { allSamples.Add(samples[i]); } } samples = new float[allSamples.Count]; for (int i = 0; i < samples.Length; i++) { samples[i] = allSamples[i]; } Plot plot = new Plot("Wave Plot", 512, 512); plot.plot(samples, 44100 / 1000, Color.Red); Application.Run(plot); }
/// <summary> /// Открытвает аудиофайл и заполняет данными (массив байтов и частота дискретизации) /// </summary> /// <param name="file"></param> public static void GetWaveData(ref WavFile wav) { //Чтение аудиофайла AudioFileReader reader = new AudioFileReader(wav.Name); if (reader.WaveFormat.Channels != 2) { throw new NotStereoException(); } int bitsPerSample = reader.WaveFormat.BitsPerSample; wav.Length = (int)(((reader.Length * 8) / bitsPerSample) / (reader.WaveFormat.SampleRate * 2)); wav.Samplerate = reader.WaveFormat.SampleRate; int sampleCount = (int)((reader.Length * 8) / reader.WaveFormat.BitsPerSample); //Запись в массив reader.ToSampleProvider(); float[] buffer = new float[(reader.Length * 8) / reader.WaveFormat.BitsPerSample]; //Запись в структуру по левому и правому каналу reader.Read(buffer, 0, sampleCount); wav.Left = new double[sampleCount]; wav.Right = new double[sampleCount]; for (int i = 0, j = 0; i < sampleCount; i += 2, ++j) { wav.Left[j] = buffer[i]; wav.Right[j] = buffer[i + 1]; } }
public CachedSound(string audioFileName, int playerSampleRate = 44100) { using (var audioFileReader = new AudioFileReader(audioFileName)) { WaveFormat = audioFileReader.WaveFormat; if (WaveFormat.SampleRate != playerSampleRate) { using (var resampler = new MediaFoundationResampler(audioFileReader, playerSampleRate)) { var wholeFile = new List <byte>(); var readBuffer = new byte[resampler.WaveFormat.SampleRate * resampler.WaveFormat.Channels]; int samplesRead; while ((samplesRead = resampler.Read(readBuffer, 0, readBuffer.Length)) > 0) { wholeFile.AddRange(readBuffer.Take(samplesRead)); } AudioData = new float[wholeFile.Count / 4]; Buffer.BlockCopy(wholeFile.ToArray(), 0, AudioData, 0, wholeFile.Count); WaveFormat = new WaveFormat(playerSampleRate, audioFileReader.WaveFormat.Channels); } } else { var wholeFile = new List <float>((int)(audioFileReader.Length / 4)); var readBuffer = new float[audioFileReader.WaveFormat.SampleRate * audioFileReader.WaveFormat.Channels]; int samplesRead; while ((samplesRead = audioFileReader.Read(readBuffer, 0, readBuffer.Length)) > 0) { wholeFile.AddRange(readBuffer.Take(samplesRead)); } AudioData = wholeFile.ToArray(); } } }
static void Main(string[] args) { Application.Init(); WaveOutEvent outputDevice = new WaveOutEvent(); string musicPath = GetFilepath(); AudioFileReader musicDataReader = new AudioFileReader(musicPath); AudioFileReader musicPlaybackReader = new AudioFileReader(musicPath); SerialConnection.Start(); Console.WriteLine("Connection open!"); outputDevice.Init(musicPlaybackReader); outputDevice.Play(); while (outputDevice.PlaybackState == PlaybackState.Playing) { if (musicDataReader.HasData(currentSentPosition)) { musicDataReader.Position = musicPlaybackReader.Position; musicDataReader.Read(amplitudeBuffer, 0, amplitudeBuffer.Length); AudioData lightCounts = AudioMethods.GetFrequencyBands(amplitudeBuffer); byte[] bytesSent = SerialConnection.SendFrequencyBandData(lightCounts); foreach (byte byteSent in bytesSent) { Console.Write(byteSent + ", "); } Console.WriteLine(""); currentSentPosition += amplitudeBuffer.Length; } } SerialConnection.SendData(new byte[48]); }
public override AudioEffectResult ApplyEffect(ref AudioFileReader Reader) { float max = 0; float[] buffer = new float[Reader.WaveFormat.SampleRate]; int read; do { read = Reader.Read(buffer, 0, buffer.Length); for (int n = 0; n < read; n++) { var abs = Math.Abs(buffer[n]); if (abs > max) { max = abs; } } } while (read > 0); if (!(max == 0) && !(max > NormalizerLevel)) { Console.WriteLine("Normalized"); Reader.Position = 0; Reader.Volume = NormalizerLevel / max; return(AudioEffectResult.Completed); } else { return(AudioEffectResult.Failed); } }
public static AudioClipData LoadAudioFile(string path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } string basename = Path.GetFileNameWithoutExtension(path); string extension = Path.GetExtension(path); AudioType type = extension == ".mp3" ? AudioType.MPEG : extension == ".wav" ? AudioType.WAV : AudioType.UNKNOWN; if (type == AudioType.UNKNOWN) { throw new NotSupportedException($"{extension} files are not supported"); } AudioFileReader reader = new AudioFileReader(path); int size = (int)(reader.Length / sizeof(float)); float[] audioData = new float[size]; reader.Read(audioData, 0, size); return(new AudioClipData(basename, size / reader.WaveFormat.Channels, reader.WaveFormat.Channels, reader.WaveFormat.SampleRate, false, audioData, 0)); }
public AudioFile(string filepath) { _reader = new AudioFileReader(filepath); _sampleRate = _reader.ToWaveProvider().WaveFormat.SampleRate; _channels = _reader.ToWaveProvider().WaveFormat.Channels; float[] data = new float[_reader.Length]; _reader.Read(data, 0, data.Length); if (_channels == 1) { _channel1 = data; } else { _channel1 = new float[data.Length / 2]; _channel2 = new float[data.Length / 2]; var chidx = 0; for (int i = 0; i < data.Length; i++) { if (i % 2 == 0) { _channel1[chidx] = data[i]; } else { _channel2[chidx] = data[i]; chidx++; } } } _length = _channel1.Length; }
private float[][] LoadChannels(string filename) { ISampleProvider sampleProvider = new AudioFileReader(filename); List <float>[] channels = new List <float> [sampleProvider.WaveFormat.Channels]; for (int i = 0; i < channels.Length; i++) { channels[i] = new List <float>(); } float[] buffer = new float[channels.Length]; while (sampleProvider.Read(buffer, 0, buffer.Length) == buffer.Length) { for (int i = 0; i < channels.Length; i++) { channels[i].Add(buffer[i]); } } float[][] result = new float[channels.Length][]; for (int i = 0; i < channels.Length; i++) { result[i] = channels[i].ToArray(); } return(result); }
public CachedSound(string audioFileName) { using (var audioFileReader = new AudioFileReader(audioFileName)) { this.WaveFormat = audioFileReader.WaveFormat; if (this.WaveFormat.SampleRate != 44100 || this.WaveFormat.Channels != 2) { using (var resampled = new ResamplerDmoStream(audioFileReader, WaveFormat.CreateIeeeFloatWaveFormat(44100, 2))) { ISampleProvider resampledSampleProvider = resampled.ToSampleProvider(); this.WaveFormat = resampledSampleProvider.WaveFormat; List <float> wholeFile = new List <float>((int)resampled.Length); float[] readBuffer = new float[resampled.WaveFormat.SampleRate * resampled.WaveFormat.Channels]; int samplesRead; while ((samplesRead = resampledSampleProvider.Read(readBuffer, 0, readBuffer.Length)) > 0) { wholeFile.AddRange(readBuffer.Take(samplesRead)); } this.AudioData = wholeFile.ToArray(); } } else { List <float> wholeFile = new List <float>((int)(audioFileReader.Length / 4)); float[] readBuffer = new float[audioFileReader.WaveFormat.SampleRate * audioFileReader.WaveFormat.Channels]; int samplesRead; while ((samplesRead = audioFileReader.Read(readBuffer, 0, readBuffer.Length)) > 0) { wholeFile.AddRange(readBuffer.Take(samplesRead)); } this.AudioData = wholeFile.ToArray(); } } }
public void ReadWavTest() { // Создали объект, который тестируем MainForm mf = new MainForm(); // прменили тестируемый метод - ReadDataFromExternalSource(inPath) string inPath = "1.wav"; double [] readAsBinaryData = mf.ReadDataFromExternalSource(inPath); // сделали проверку. Пока просто чтоданные найдены Assert.AreEqual(true, readAsBinaryData.Length > 0, "Выбор файла данных"); // Прочли тот же файл стандартной бибилотекой float[] readByNAudio = null; int r = 0; using (var reader = new AudioFileReader(inPath)) { readByNAudio = new float[reader.Length / sizeof(float)]; r = reader.Read(readByNAudio, 0, readByNAudio.Length); } //Проверили, что прочтено данных столько же как и проверяемым методом Assert.AreEqual(r, readAsBinaryData.Length, "Фактическое Количество данных"); // Вызвали метод сравнения двух массивов. Значения в них отличаются множителем 32768. // Если метод вернет количество элементов массива, то все ОК. Если нет, то найдено существенное различие! Assert.AreEqual(r, copareFloatAndDouble(readByNAudio, readAsBinaryData, 32768, 0.0000000001), "Эквивалентность данных"); }
private bool LoadAudioBytestream(string path) { try { WWW www = new WWW(path); if (www.error == null) { AFR = new AudioFileReader(path); AudioData = new float[(int)AFR.Length]; AFR.Read(AudioData, 0, (int)AFR.Length); clip = AudioClip.Create(Path.GetFileNameWithoutExtension(path), (int)AFR.Length, AFR.WaveFormat.Channels, AFR.WaveFormat.SampleRate, false); clip.SetData(AudioData, 0); SoundSystem.clip = clip; return(true); } } catch (System.Exception ex) { Debug.LogWarning("ERROR: " + ex.Message); } return(false); }
public static void Main(string[] argv) { ISampleProvider decoder = new AudioFileReader(FILE); FFT fft = new FFT(1024, 44100); float[] samples = new float[1024]; float[] spectrum = new float[1024 / 2 + 1]; float[] lastSpectrum = new float[1024 / 2 + 1]; List <float> spectralFlux = new List <float>(); while (decoder.Read(samples, 0, samples.Length) > 0) { fft.Forward(samples); System.Array.Copy(spectrum, 0, lastSpectrum, 0, spectrum.Length); System.Array.Copy(fft.GetSpectrum(), 0, spectrum, 0, spectrum.Length); float flux = 0; for (int i = 0; i < spectrum.Length; i++) { flux += (spectrum[i] - lastSpectrum[i]); } spectralFlux.Add(flux); } Plot plot = new Plot("Spectral Flux", 1024, 512); plot.plot(spectralFlux, 1, Color.Red); new PlaybackVisualizer(plot, 1024, FILE); //new PlaybackVisualizer(plot, spectralFlux.Count, FILE); }
private int GetSilenceTime(AudioFileReader fileReader, SilenceLocation location, sbyte silenceThreshold = -20) { float[] buffer = new float[fileReader.WaveFormat.SampleRate * 4]; int result = 0; bool volumeFound = false; bool eof = false; long oldPosition = fileReader.Position; while (!volumeFound && !eof) { int samplesRead = fileReader.Read(buffer, 0, buffer.Length); if (samplesRead == 0) { eof = true; } for (int i = 0; i < samplesRead; i++) { if (!IsSilence(buffer[i], silenceThreshold)) { result = (int)fileReader.Position - (samplesRead - i) * 4; if (location == SilenceLocation.Start) { volumeFound = true; break; } } } } fileReader.Position = oldPosition; return(result); }
public int Read(float[] buffer, int offset, int count) { if (_playbackState == PlaybackState.Playing) { var sampleCount = _audioFileReader.Read(buffer, offset, count); if (sampleCount == 0) { Stop(); } return(sampleCount); } if (_playbackState == PlaybackState.Paused) { var i = offset; while (i < offset + count) { buffer[i++] = 0.0f; } return(count); } _playbackState = PlaybackState.Stopped; return(0); }
public static void Main(string[] argv) { //ISampleProvider reader = new AudioFileReader(@"C:\Users\perivar.nerseth\Music\Sleep Away16.wav"); //ISampleProvider reader = new AudioFileReader("samples/sample.wav"); ISampleProvider reader = new AudioFileReader(@"C:\Users\perivar.nerseth\Music\Sleep Away32f.wav"); AudioDevice device = new AudioDevice(); float[] samples = new float[1024]; while (reader.Read(samples, 0, samples.Length) > 0) { device.WriteSamples(samples); } System.Threading.Thread.Sleep(10000); device.Dispose(); /* * WaveFileReader wfr = new WaveFileReader("samples/sample.wav"); * WaveOut audioOutput = new WaveOut(); * WaveChannel32 wc = new WaveChannel32(wfr); * wc.PadWithZeroes = false; * audioOutput.Init(wc); * audioOutput.PlaybackStopped += new EventHandler<StoppedEventArgs>(_waveOutDevice_PlaybackStopped); * audioOutput.Play(); * * while (audioOutput.PlaybackState != PlaybackState.Stopped) { * System.Threading.Thread.Sleep(100); * } */ }
private void flatButton4_Click_1(object sender, EventArgs e) { try { ChangeStatus("Decrypting your sound ...", FlatUI.FlatAlertBox._Kind.Info); AudioFileReader ReadedSound = new AudioFileReader(SoundPath); int SoundSize = Convert.ToInt32(ReadedSound.Length); byte[] HauteurArray = new byte[SoundSize]; ReadedSound.Read(HauteurArray, 0, SoundSize); Hauteur = ReadedSound.WaveFormat.SampleRate; Channel = ReadedSound.WaveFormat.Channels; for (int a = 0; a < HauteurArray.Length; ++a) { HauteurDecryptees.Add(PreparedRSA.Decrypt(HauteurArray[a])); } } catch (Exception error) { MessageBox.Show(error.Data + "\n" + error.Message + "\n" + error.Source, null, MessageBoxButtons.OK, MessageBoxIcon.Error); ChangeStatus("An error happened !", FlatUI.FlatAlertBox._Kind.Error); Application.Exit(); } ChangeStatus("Done with success!", FlatUI.FlatAlertBox._Kind.Success); Export(); }
/// <summary> /// Split a Stereo Wave file into two mono float arrays /// </summary> /// <param name="filePath">file to use</param> /// <param name="audioDataLeft">returned float array for the left channel</param> /// <param name="audioDataRight">returned float array for the right channel</param> public static void SplitStereoWaveFileToMono(string filePath, out float[] audioDataLeft, out float[] audioDataRight) { using (AudioFileReader pcm = new AudioFileReader(filePath)) { int channels = pcm.WaveFormat.Channels; int bytesPerSample = pcm.WaveFormat.BitsPerSample / 8; long samplesDesired = pcm.Length; byte[] buffer = new byte[samplesDesired]; audioDataLeft = new float[samplesDesired / bytesPerSample / channels]; audioDataRight = new float[samplesDesired / bytesPerSample / channels]; int bytesRead = pcm.Read(buffer, 0, buffer.Length); int index = 0; for (int sample = 0; sample < bytesRead / bytesPerSample / channels; sample++) { if (bytesPerSample == 4) { // 32 bit pcm data as float audioDataLeft[sample] = BitConverter.ToSingle(buffer, index); index += bytesPerSample; audioDataRight[sample] = BitConverter.ToSingle(buffer, index); index += bytesPerSample; } else if (bytesPerSample == 2) { // 16 bit pcm data audioDataLeft[sample] = (float)BitConverter.ToInt16(buffer, index) / 32768f; index += bytesPerSample; audioDataRight[sample] = (float)BitConverter.ToInt16(buffer, index) / 32768f; index += bytesPerSample; } } } }
public AudioClip LoadAudio(string path) { var name = Path.GetFileNameWithoutExtension(path); try { var aud = new AudioFileReader(path); var AudioData = new float[aud.Length]; aud.Read(AudioData, 0, (int)aud.Length); var clip = AudioClip.Create(name, (int)aud.Length, aud.WaveFormat.Channels, aud.WaveFormat.SampleRate, false); clip.SetData(AudioData, 0); if (clip.isReadyToPlay) { aud.Dispose(); AudioLoveConfig config = new AudioLoveConfig(); config.clip = clip; config.requireLv = -1; audioCllips.Add(path, config); // audioCllips.Add(name, clip); return(clip); } } catch { return(null); } return(null); }
public SeñalAudio(string rutaArchivo) { RutaArchivo = rutaArchivo; Muestras = new List <Muestra>(); AudioFileReader reader = new AudioFileReader(rutaArchivo); TiempoInicial = 0.0; TiempoFinal = reader.TotalTime.TotalSeconds; FrecuenciaMuestreo = reader.WaveFormat.SampleRate; var bufferLectura = new float[reader.WaveFormat.Channels]; double instanteActual = 0.0; double periodoMuestreo = 1.0 / FrecuenciaMuestreo; int muestrasLeidas = 0; do { muestrasLeidas = reader.Read(bufferLectura, 0, reader.WaveFormat.Channels); if (muestrasLeidas > 0) { double max = bufferLectura.Take(muestrasLeidas).Max(); Muestras.Add(new Muestra(instanteActual, max)); if (Math.Abs(max) > AmplitudMaxima) { AmplitudMaxima = Math.Abs(max); } } instanteActual += periodoMuestreo; } while (muestrasLeidas > 0); }
public static async Task <float[]> ReadAudioFile(string source) { float[] block = new float[1024]; var result = new List <float>(); using (var reader = new AudioFileReader(source)) { int nread = 0; do { await Task.Run(() => { nread = reader.Read(block, 0, block.Length); for (int i = 0; i < nread; i++) { result.Add(block[i]); } }); } while (nread > 0); } return(result.ToArray()); }