示例#1
0
        private IntPtr streamOpen(int inputDevice, int inputChannels,
                                  int outputDevice, int outputChannels,
                                  int sampleRate, uint framesPerBuffer)
        {
            IntPtr stream = new IntPtr();
            IntPtr data   = new IntPtr(0);

            PortAudio.PaStreamParameters inputParams = new PortAudio.PaStreamParameters();
            inputParams.channelCount     = inputChannels;
            inputParams.device           = inputDevice;
            inputParams.sampleFormat     = PortAudio.PaSampleFormat.paFloat32;
            inputParams.suggestedLatency = this.inputDeviceInfo.defaultLowInputLatency;
            PortAudio.PaStreamParameters outputParams = new PortAudio.PaStreamParameters();
            outputParams.channelCount     = outputChannels;
            outputParams.device           = outputDevice;
            outputParams.sampleFormat     = PortAudio.PaSampleFormat.paFloat32;
            outputParams.suggestedLatency = this.outputDeviceInfo.defaultLowOutputLatency;
            errorCheck("OpenDefaultStream", PortAudio.Pa_OpenStream(
                           out stream,
                           ref inputParams,
                           ref outputParams,
                           sampleRate,
                           framesPerBuffer,
                           PortAudio.PaStreamFlags.paNoFlag,
                           this.paStreamCallback,
                           data));
            return(stream);
        }
示例#2
-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;
        }
示例#3
-1
        /// <summary>
        /// Start Voice Capturing
        /// </summary>
        /// <param name="DeviceConfig"></param>
        /// <returns></returns>
        public bool Start(SRecordDevice[] DeviceConfig)
        {
            if (!_initialized)
                return false;

            for (int i = 0; i < _Buffer.Length; i++)
            {
                _Buffer[i].Reset();
            }

            for (int i = 0; i < _recHandle.Length; i++)
            {
                _recHandle[i] = IntPtr.Zero;
            }

            _DeviceConfig = DeviceConfig;
            bool[] active = new bool[DeviceConfig.Length];
            for (int dev = 0; dev < DeviceConfig.Length; dev++)
            {
                active[dev] = false;
                for (int inp = 0; inp < DeviceConfig[dev].Inputs.Count; inp++)
                {
                    if (DeviceConfig[dev].Inputs[inp].PlayerChannel1 > 0 ||
                        DeviceConfig[dev].Inputs[inp].PlayerChannel2 > 0)
                        active[dev] = true;
                }
            }

            bool result = true;
            for (int i = 0; i < _recHandle.Length; i++)
            {
                if (active[i])
                {
                    PortAudio.PaStreamParameters inputParams = new PortAudio.PaStreamParameters();
                    inputParams.channelCount = _DeviceConfig[i].Inputs[0].Channels;
                    inputParams.device = _DeviceConfig[i].ID;
                    inputParams.sampleFormat = PortAudio.PaSampleFormat.paInt16;
                    inputParams.suggestedLatency = PortAudio.Pa_GetDeviceInfo(_DeviceConfig[i].ID).defaultLowInputLatency;

                    if (errorCheck("OpenStream", PortAudio.Pa_OpenStream(
                        out _recHandle[i],
                        ref inputParams,
                        IntPtr.Zero,
                        44100,
                        PortAudio.paFramesPerBufferUnspecified,
                        PortAudio.PaStreamFlags.paNoFlag,
                        _myRecProc,
                        new IntPtr(i))))
                        return false;

                    if (errorCheck("Start Stream", PortAudio.Pa_StartStream(_recHandle[i])))
                        return false;
                }
            }

            return result;
        }
示例#4
-1
        private IntPtr streamOpen(int inputDevice,int inputChannels,
            int outputDevice,int outputChannels,
            int sampleRate, uint framesPerBuffer)
        {
            IntPtr stream = new IntPtr();
             		IntPtr data = new IntPtr(0);

             		PortAudio.PaStreamParameters? inputParams;
            if (inputDevice == -1 || inputChannels <= 0) {
                inputParams = null;
            } else {
                PortAudio.PaStreamParameters inputParamsTemp = new PortAudio.PaStreamParameters();
                inputParamsTemp.channelCount = inputChannels;
                inputParamsTemp.device = inputDevice;
                inputParamsTemp.sampleFormat = PortAudio.PaSampleFormat.paFloat32;
                inputParamsTemp.suggestedLatency = this.inputDeviceInfo.defaultLowInputLatency;
                inputParams = inputParamsTemp;
            }
            PortAudio.PaStreamParameters? outputParams;
            if (outputDevice == -1 || outputChannels <= 0) {
                outputParams = null;
            } else {
                PortAudio.PaStreamParameters outputParamsTemp = new PortAudio.PaStreamParameters();
             		    outputParamsTemp.channelCount = outputChannels;
             		    outputParamsTemp.device = outputDevice;
             		    outputParamsTemp.sampleFormat = PortAudio.PaSampleFormat.paFloat32;
             		    outputParamsTemp.suggestedLatency = this.outputDeviceInfo.defaultLowOutputLatency;
                outputParams = outputParamsTemp;
            }
             		errorCheck("OpenDefaultStream",PortAudio.Pa_OpenStream(
                out stream,
                ref inputParams,
                ref outputParams,
                sampleRate,
                framesPerBuffer,
                PortAudio.PaStreamFlags.paNoFlag,
                this.paStreamCallback,
                data));
            return stream;
        }
示例#5
-1
 private IntPtr streamOpen(int inputDevice,int inputChannels,
                  int outputDevice,int outputChannels,
                  int sampleRate, uint framesPerBuffer)
 {
     IntPtr stream = new IntPtr();
      		IntPtr data = new IntPtr(0);
      		PortAudio.PaStreamParameters inputParams = new PortAudio.PaStreamParameters();
      		inputParams.channelCount = inputChannels;
      		inputParams.device = inputDevice;
      		inputParams.sampleFormat = PortAudio.PaSampleFormat.paFloat32;
      		inputParams.suggestedLatency = 0.0;
      		PortAudio.PaStreamParameters outputParams = new PortAudio.PaStreamParameters();
      		outputParams.channelCount = outputChannels;
      		outputParams.device = outputDevice;
      		outputParams.sampleFormat = PortAudio.PaSampleFormat.paFloat32;
      		outputParams.suggestedLatency = 0.0;
      		errorCheck("OpenDefaultStream",PortAudio.Pa_OpenStream(
         out stream,
         ref inputParams,
         ref outputParams,
         sampleRate,
         framesPerBuffer,
         PortAudio.PaStreamFlags.paNoFlag,
         this.paStreamCallback,
         data));
     return stream;
 }