public AudioDecoder(DecoderSettings settings, string path, Stream IO, Stream IO_WVC) { m_settings = settings; m_read_bytes = ReadCallback; m_get_pos = TellCallback; m_set_pos_abs = SeekCallback; m_set_pos_rel = SeekRelativeCallback; m_push_back_byte = PushBackCallback; m_get_length = LengthCallback; m_can_seek = CanSeekCallback; m_ioReader = (WavpackStreamReader64 *)Marshal.AllocHGlobal(sizeof(WavpackStreamReader64)).ToPointer(); m_ioReader->read_bytes = Marshal.GetFunctionPointerForDelegate(m_read_bytes); m_ioReader->write_bytes = IntPtr.Zero; m_ioReader->get_pos = Marshal.GetFunctionPointerForDelegate(m_get_pos); m_ioReader->set_pos_abs = Marshal.GetFunctionPointerForDelegate(m_set_pos_abs); m_ioReader->set_pos_rel = Marshal.GetFunctionPointerForDelegate(m_set_pos_rel); m_ioReader->push_back_byte = Marshal.GetFunctionPointerForDelegate(m_push_back_byte); m_ioReader->get_length = Marshal.GetFunctionPointerForDelegate(m_get_length); m_ioReader->can_seek = Marshal.GetFunctionPointerForDelegate(m_can_seek); m_ioReader->truncate_here = IntPtr.Zero; m_ioReader->close = IntPtr.Zero; _IO_ungetc = _IO_WVC_ungetc = -1; _path = path; _IO = (IO != null) ? IO : new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); _IO_WVC = (IO != null) ? IO_WVC : File.Exists(path + "c") ? new FileStream(path + "c", FileMode.Open, FileAccess.Read, FileShare.Read) : null; string errorMessage; _wpc = wavpackdll.WavpackOpenFileInputEx64(m_ioReader, IO_ID_WV, IO_ID_WVC, out errorMessage, OpenFlags.OPEN_WVC, 0); if (_wpc == null) { throw new Exception("Unable to initialize the decoder: " + errorMessage); } pcm = new AudioPCMConfig( wavpackdll.WavpackGetBitsPerSample(_wpc), wavpackdll.WavpackGetNumChannels(_wpc), (int)wavpackdll.WavpackGetSampleRate(_wpc), (AudioPCMConfig.SpeakerConfig)wavpackdll.WavpackGetChannelMask(_wpc)); _sampleCount = wavpackdll.WavpackGetNumSamples64(_wpc); _sampleOffset = 0; }
public AudioDecoder(DecoderSettings settings, string path, Stream IO = null) : this(settings, path, IO, null) { }