/// <summary> /// Decode a signal from the specified file. /// </summary> /// /// <param name="fileName">File name to read signal from.</param> /// <param name="frameInfo">Information about the decoded signal.</param> /// /// <returns>Return decoded signal.</returns> /// public static Signal DecodeFromFile(string fileName, out FrameInfo frameInfo) { string fileExtension = FormatDecoderAttribute.GetNormalizedExtension(fileName); IAudioDecoder decoder = FormatDecoderAttribute.GetDecoders(fileExtension, decoderTypes, decoders.Value); if (decoder != null) { // open stream using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { // open decoder decoder.Open(stream); // read all audio frames Signal signal = decoder.Decode(); decoder.Close(); frameInfo = new FrameInfo(signal.NumberOfChannels, signal.SampleRate, Signal.GetSampleSize(signal.SampleFormat), 0, signal.Length); return(signal); } } throw new ArgumentException(String.Format("No suitable decoder has been found for the file format {0}. If ", fileExtension) + "you are trying to decode .wav files, please add a reference to Accord.Audio.DirectSound. You might need to instantiate" + "at least one type from this assembly to make sure it has been loaded in the AppDomain of your applicatoin.", "fileName"); }
private void _DoFree() { if (_PaHandle != null) { if (_Stream != IntPtr.Zero) { _PaHandle.CloseStream(_Stream); } _PaHandle.Close(); _PaHandle = null; } if (_DecoderThread != null) { if (Thread.CurrentThread.ManagedThreadId != _DecoderThread.ManagedThreadId) { throw new Exception("Another thread should never free the decoder thread!"); } _DecoderThread = null; } if (_Decoder != null) { _Decoder.Close(); _Decoder = null; } if (_EventDecode != null) { _EventDecode.Close(); _EventDecode = null; } if (_CloseStreamListener != null) { _CloseStreamListener.OnCloseStream(this); } }
/// <summary> /// Decode a signal from the specified file. /// </summary> /// /// <param name="fileName">File name to read signal from.</param> /// <param name="frameInfo">Information about the decoded signal.</param> /// /// <returns>Return decoded signal.</returns> /// public static Signal DecodeFromFile(string fileName, out FrameInfo frameInfo) { Signal signal = null; string fileExtension = Path.GetExtension(fileName).ToUpperInvariant(); if ((fileExtension != string.Empty) && (fileExtension.Length != 0)) { fileExtension = fileExtension.Substring(1); if (!decoders.ContainsKey(fileExtension)) { FormatDecoderAttribute.PopulateDictionaryWithDecodersFromAllAssemblies <IAudioDecoder>(decoders, fileExtension); } if (decoders.ContainsKey(fileExtension)) { IAudioDecoder decoder = (IAudioDecoder)Activator.CreateInstance(decoders[fileExtension]); // open stream using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { // open decoder decoder.Open(stream); // read all audio frames signal = decoder.Decode(); decoder.Close(); } frameInfo = new FrameInfo(signal.Channels, signal.SampleRate, Signal.GetSampleSize(signal.SampleFormat), 0, signal.Length); return(signal); } } throw new ArgumentException(String.Format("No suitable decoder has been found for the file format {0}. If ", fileExtension) + "you are trying to decode .wav files, please add a reference to Accord.Audio.DirectSouond.", "fileName"); }
private void _DoFree() { if (_Source != 0) { AL.SourceStop(_Source); if (_Buffers != null) { AL.DeleteBuffers(_Buffers); _Buffers = null; } AL.DeleteSource(_Source); _Source = 0; } if (_DecoderThread != null) { if (Thread.CurrentThread.ManagedThreadId != _DecoderThread.ManagedThreadId) { throw new Exception("Another thread should never free the decoder thread!"); } _DecoderThread = null; } if (_Decoder != null) { _Decoder.Close(); _Decoder = null; } _SampleBuf = null; if (_EventDecode != null) { _EventDecode.Close(); _EventDecode = null; } if (_CloseStreamListener != null) { _CloseStreamListener.OnCloseStream(this); } }