/// <summary>Constructor - Supports opening a FLAC file</summary> public FLACFileReader(string flacFileName) { // Open the flac file for reading through a binary reader m_stream = File.OpenRead(flacFileName); m_reader = new BinaryReader(m_stream); // Create the FLAC decoder m_decoderContext = LibFLACSharp.FLAC__stream_decoder_new(); if (m_decoderContext == IntPtr.Zero) throw new ApplicationException("FLAC: Could not initialize stream decoder!"); // Create call back delegates m_writeCallback = new LibFLACSharp.Decoder_WriteCallback(FLAC_WriteCallback); m_metadataCallback = new LibFLACSharp.Decoder_MetadataCallback(FLAC_MetadataCallback); m_errorCallback = new LibFLACSharp.Decoder_ErrorCallback(FLAC_ErrorCallback); // Initialize the FLAC decoder if (LibFLACSharp.FLAC__stream_decoder_init_file(m_decoderContext, flacFileName, m_writeCallback, m_metadataCallback, m_errorCallback, IntPtr.Zero) != 0) throw new ApplicationException("FLAC: Could not open stream for reading!"); // Process the meta-data (but not the audio frames) so we can prepare the NAudio wave format FLACCheck( LibFLACSharp.FLAC__stream_decoder_process_until_end_of_metadata(m_decoderContext), "Could not process until end of metadata"); // Initialize NAudio wave format m_waveFormat = new WaveFormat(m_flacStreamInfo.SampleRate, m_flacStreamInfo.BitsPerSample, m_flacStreamInfo.Channels); }
/// <summary>Constructor - Supports opening a FLAC file</summary> public FLACFileReader(string flacFileName) { // Open the flac file for reading through a binary reader m_stream = File.OpenRead(flacFileName); m_reader = new BinaryReader(m_stream); // Create the FLAC decoder m_decoderContext = LibFLACSharp.FLAC__stream_decoder_new(); if (m_decoderContext == IntPtr.Zero) { throw new ApplicationException("FLAC: Could not initialize stream decoder!"); } // Create call back delegates m_writeCallback = new LibFLACSharp.Decoder_WriteCallback(FLAC_WriteCallback); m_metadataCallback = new LibFLACSharp.Decoder_MetadataCallback(FLAC_MetadataCallback); m_errorCallback = new LibFLACSharp.Decoder_ErrorCallback(FLAC_ErrorCallback); // Initialize the FLAC decoder if (LibFLACSharp.FLAC__stream_decoder_init_file(m_decoderContext, flacFileName, m_writeCallback, m_metadataCallback, m_errorCallback, IntPtr.Zero) != 0) { throw new ApplicationException("FLAC: Could not open stream for reading!"); } // Process the meta-data (but not the audio frames) so we can prepare the NAudio wave format FLACCheck( LibFLACSharp.FLAC__stream_decoder_process_until_end_of_metadata(m_decoderContext), "Could not process until end of metadata"); // Initialize NAudio wave format m_waveFormat = new WaveFormat(m_flacStreamInfo.SampleRate, m_flacStreamInfo.BitsPerSample, m_flacStreamInfo.Channels); }