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 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 { if (errorCheck("Initialize", PortAudio.Pa_Initialize())) { return(-1); } _Initialized = true; int hostApi = apiSelect(); _apiInfo = PortAudio.Pa_GetHostApiInfo(hostApi); _outputDeviceInfo = PortAudio.Pa_GetDeviceInfo(_apiInfo.defaultOutputDevice); _paStreamCallback = new PortAudio.PaStreamCallbackDelegate(_PaStreamCallback); if (_outputDeviceInfo.defaultLowOutputLatency < 0.1) { _outputDeviceInfo.defaultLowOutputLatency = 0.1; } } catch (Exception) { _Initialized = false; CLog.LogError("Error Init PortAudio Playback"); return(-1); } _FileName = FileName; _Decoder.Open(FileName); _Duration = _Decoder.GetLength(); FormatInfo format = _Decoder.GetFormatInfo(); _ByteCount = 2 * format.ChannelCount; _BytesPerSecond = format.SamplesPerSecond * _ByteCount; _CurrentTime = 0f; _SyncTimer.Time = _CurrentTime; AudioStreams stream = new AudioStreams(0); IntPtr data = new IntPtr(0); PortAudio.PaStreamParameters outputParams = new PortAudio.PaStreamParameters(); outputParams.channelCount = format.ChannelCount; outputParams.device = _apiInfo.defaultOutputDevice; outputParams.sampleFormat = PortAudio.PaSampleFormat.paInt16; outputParams.suggestedLatency = _outputDeviceInfo.defaultLowOutputLatency; errorCheck("OpenDefaultStream", PortAudio.Pa_OpenStream( out _Ptr, IntPtr.Zero, ref outputParams, format.SamplesPerSecond, (uint)CConfig.AudioBufferSize, PortAudio.PaStreamFlags.paNoFlag, _paStreamCallback, data)); stream.handle = _Ptr.ToInt32(); if (stream.handle != 0) { _Paused = true; _waiting = true; _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 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 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 { if (errorCheck("Initialize", PortAudio.Pa_Initialize())) return -1; _Initialized = true; int hostApi = apiSelect(); _apiInfo = PortAudio.Pa_GetHostApiInfo(hostApi); _outputDeviceInfo = PortAudio.Pa_GetDeviceInfo(_apiInfo.defaultOutputDevice); _paStreamCallback = new PortAudio.PaStreamCallbackDelegate(_PaStreamCallback); if (_outputDeviceInfo.defaultLowOutputLatency < 0.1) _outputDeviceInfo.defaultLowOutputLatency = 0.1; } catch (Exception) { _Initialized = false; CLog.LogError("Error Init PortAudio Playback"); return -1; } _FileName = FileName; _Decoder.Open(FileName); _Duration = _Decoder.GetLength(); FormatInfo format = _Decoder.GetFormatInfo(); _ByteCount = 2 * format.ChannelCount; _BytesPerSecond = format.SamplesPerSecond * _ByteCount; _CurrentTime = 0f; _SyncTimer.Time = _CurrentTime; AudioStreams stream = new AudioStreams(0); IntPtr data = new IntPtr(0); PortAudio.PaStreamParameters outputParams = new PortAudio.PaStreamParameters(); outputParams.channelCount = format.ChannelCount; outputParams.device = _apiInfo.defaultOutputDevice; outputParams.sampleFormat = PortAudio.PaSampleFormat.paInt16; outputParams.suggestedLatency = _outputDeviceInfo.defaultLowOutputLatency; uint bufsize = (uint)CConfig.AudioBufferSize; errorCheck("OpenDefaultStream", PortAudio.Pa_OpenStream( out _Ptr, IntPtr.Zero, ref outputParams, format.SamplesPerSecond, bufsize, PortAudio.PaStreamFlags.paNoFlag, _paStreamCallback, data)); stream.handle = _Ptr.ToInt32(); if (stream.handle != 0) { _Paused = true; _waiting = true; _FileOpened = true; _data = new RingBuffer(BUFSIZE); _NoMoreData = false; _DecoderThread.Priority = ThreadPriority.Normal; _DecoderThread.Name = Path.GetFileName(FileName); _DecoderThread.Start(); return stream.handle; } return -1; }