/// <summary>Constructor - Supports opening a FLAC file</summary> public FLACFileReader(string flacFileName) { m_decoderContext = IntPtr.Zero; Console.WriteLine("FLACFileReader: " + 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 = LibFLAC.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 LibFLAC.Decoder_WriteCallback(FLAC_WriteCallback); m_metadataCallback = new LibFLAC.Decoder_MetadataCallback(FLAC_MetadataCallback); m_errorCallback = new LibFLAC.Decoder_ErrorCallback(FLAC_ErrorCallback); // Initialize the FLAC decoder if (LibFLAC.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( LibFLAC.FLAC__stream_decoder_process_until_end_of_metadata(m_decoderContext), "Could not process until end of metadata"); // Initialize NAudio wave format m_waveFormat = new WaveInformation(m_flacStreamInfo.SampleRate, m_flacStreamInfo.BitsPerSample, m_flacStreamInfo.Channels); Console.WriteLine("Total FLAC Samples: {0}", LibFLAC.FLAC__stream_decoder_get_total_samples(m_decoderContext)); }
private void SetupCallbacks () { mReadCallback = new LibFLAC.DecoderReadCallback (this.ReadCallback); mSeekCallback = new LibFLAC.DecoderSeekCallback (this.SeekCallback); mTellCallback = new LibFLAC.DecoderTellCallback (this.TellCallback); mLengthCallback = new LibFLAC.DecoderLengthCallback (this.LengthCallback); mEOFCallback = new LibFLAC.DecoderEofCallback (this.EOFCallback); mWriteCallback = new LibFLAC.DecoderWriteCallbackWithStatus (this.WriteCallback); mMetadataCallback = new LibFLAC.Decoder_MetadataCallback (this.MetadataCallback); mErrorCallback = new LibFLAC.Decoder_ErrorCallback (this.ErrorCallback); }