public int Open(string FileName) { if (_FileOpened) return -1; if (!System.IO.File.Exists(FileName)) return -1; if (_FileOpened) return -1; _Decoder = new CAudioDecoderFFmpeg(); _Decoder.Init(); try { _source = AL.GenSource(); _buffers = AL.GenBuffers(buffer_count); _state = 0; //AL.SourceQueueBuffers(_source, _buffers.Length, _buffers); } catch (Exception) { _Initialized = false; CLog.LogError("Error Init OpenAL Playback"); return -1; } _FileName = FileName; _Decoder.Open(FileName); _Duration = _Decoder.GetLength(); _format = _Decoder.GetFormatInfo(); _ByteCount = 2 * _format.ChannelCount; _BytesPerSecond = _format.SamplesPerSecond * _ByteCount; _CurrentTime = 0f; _Timer.Reset(); AudioStreams stream = new AudioStreams(0); stream.handle = _buffers[0]; if (stream.handle != 0) { _FileOpened = true; _data = new RingBuffer(BUFSIZE); _NoMoreData = false; _DecoderThread.Priority = ThreadPriority.Normal; _DecoderThread.Name = Path.GetFileName(FileName); _DecoderThread.Start(); return stream.handle; } return -1; }
public override void Open(string FileName, bool Loop) { if (!_Initialized) return; _FileName = FileName; _fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read); _instance = CAcinerella.ac_init(); CAcinerella.ac_open(_instance, IntPtr.Zero, null, _rc, _sc, null, IntPtr.Zero); _Instance = (TAc_instance)Marshal.PtrToStructure(_instance, typeof(TAc_instance)); if (!_Instance.opened) { //Free(); return; } int AudioStreamIndex = -1; TAc_stream_info Info = new TAc_stream_info(); for (int i = 0; i < _Instance.stream_count; i++) { CAcinerella.ac_get_stream_info(_instance, i, out Info); if (Info.stream_type == TAc_stream_type.AC_STREAM_TYPE_AUDIO) { try { _audiodecoder = CAcinerella.ac_create_decoder(_instance, i); } catch (Exception) { return; } AudioStreamIndex = i; break; } } if (AudioStreamIndex < 0) { //Free(); return; } TAc_decoder Audiodecoder = (TAc_decoder)Marshal.PtrToStructure(_audiodecoder, typeof(TAc_decoder)); _FormatInfo = new FormatInfo(); _FormatInfo.SamplesPerSecond = Audiodecoder.stream_info.audio_info.samples_per_second; _FormatInfo.BitDepth = Audiodecoder.stream_info.audio_info.bit_depth; _FormatInfo.ChannelCount = Audiodecoder.stream_info.audio_info.channel_count; _CurrentTime = 0f; if (_FormatInfo.BitDepth != 16) { CLog.LogError("Unsupported BitDepth in file " + FileName); return; } _FileOpened = true; }