示例#1
0
        void ASIODeviceControlLoad(object sender, EventArgs e)
        {
            int deviceCount = PortAudio.Pa_GetDeviceCount();

            Console.WriteLine("Device count: " + paHostApiInfo.deviceCount + " default input device: " + paHostApiInfo.defaultInputDevice);

            deviceComboBox.Items.Clear();
            for (int i = 0; i < deviceCount; i++)
            {
                PortAudio.PaDeviceInfo  paDeviceInfo = PortAudio.Pa_GetDeviceInfo(i);
                PortAudio.PaHostApiInfo paHostApi    = PortAudio.Pa_GetHostApiInfo(paDeviceInfo.hostApi);
                if (paHostApi.type == PortAudio.PaHostApiTypeId.paASIO)
                {
                    Console.WriteLine("\n#" + i + "\n" + paDeviceInfo);
                    if (paDeviceInfo.maxOutputChannels > 0)
                    {
                        deviceComboBox.Items.Add(new DeviceItem(i, paDeviceInfo));
                        if (i == paHostApiInfo.defaultOutputDevice)
                        {
                            deviceComboBox.SelectedIndex = deviceComboBox.Items.Count - 1;
                        }
                    }
                }
            }

            bufferSizeComboBox.Items.Clear();
            int bufferSize = 256;

            while (bufferSize < 44100 / 2)
            {
                bufferSizeComboBox.Items.Add(bufferSize);
                bufferSize *= 2;
            }
            bufferSizeComboBox.SelectedIndex = 2;
        }
        public PortAudioPlayer(int channels, int frequency, uint framesPerBuffer,
                               PortAudio.PaStreamCallbackDelegate paStreamCallback)
        {
            log("Initializing...");
            this.channels         = channels;
            this.frequency        = frequency;
            this.framesPerBuffer  = framesPerBuffer;
            this.paStreamCallback = paStreamCallback;
            if (errorCheck("Initialize", PortAudio.Pa_Initialize()))
            {
                this.disposed = true;
                // if Pa_Initialize() returns an error code,
                // Pa_Terminate() should NOT be called.
                throw new Exception("Can't initialize audio");
            }
            int apiCount = PortAudio.Pa_GetHostApiCount();

            for (int i = 0; i < apiCount; i++)
            {
                PortAudio.PaHostApiInfo availableApiInfo = PortAudio.Pa_GetHostApiInfo(i);
                log("available API index: " + i + "\n" + availableApiInfo.ToString());
            }
            this.hostApi = apiSelect();
            log("selected Host API: " + this.hostApi);
            this.apiInfo          = PortAudio.Pa_GetHostApiInfo(this.hostApi);
            this.inputDeviceInfo  = PortAudio.Pa_GetDeviceInfo(apiInfo.defaultInputDevice);
            this.outputDeviceInfo = PortAudio.Pa_GetDeviceInfo(apiInfo.defaultOutputDevice);
            log("input device:\n" + inputDeviceInfo.ToString());
            log("output device:\n" + outputDeviceInfo.ToString());
        }
示例#3
0
        /// <summary>
        /// Init PortAudio and list record devices
        /// </summary>
        /// <returns>true if success</returns>
        public bool Init()
        {
            _Devices = new List <SRecordDevice>();

            try
            {
                if (_initialized)
                {
                    CloseAll();
                }

                if (errorCheck("Initialize", PortAudio.Pa_Initialize()))
                {
                    return(false);
                }

                _initialized = true;
                int hostAPI = apiSelect();

                int numDevices = PortAudio.Pa_GetDeviceCount();
                for (int i = 0; i < numDevices; i++)
                {
                    PortAudio.PaDeviceInfo info = PortAudio.Pa_GetDeviceInfo(i);
                    if (info.hostApi == hostAPI && info.maxInputChannels > 0)
                    {
                        SRecordDevice dev = new SRecordDevice();

                        dev.ID     = i;
                        dev.Name   = info.name;
                        dev.Driver = info.name + i.ToString();
                        dev.Inputs = new List <SInput>();

                        SInput inp = new SInput();
                        inp.Name = "Default";

                        inp.Channels = info.maxInputChannels;
                        if (inp.Channels > 2)
                        {
                            inp.Channels = 2; //more are not supported in vocaluxe
                        }
                        dev.Inputs.Add(inp);
                        _Devices.Add(dev);
                    }
                }

                _recHandle = new IntPtr[_Devices.Count];
                _myRecProc = new PortAudio.PaStreamCallbackDelegate(myPaStreamCallback);

                _DeviceConfig = _Devices.ToArray();
            }
            catch (Exception e)
            {
                _initialized = false;
                CLog.LogError("Error initializing PortAudio: " + e.Message);
                return(false);
            }

            return(true);
        }
示例#4
0
        private void comboBoxHostApiDevices_SelectedIndexChanged(object sender, EventArgs e)
        {
            PortAudio.PaDeviceInfo deviceInfo = (PortAudio.PaDeviceInfo) this.comboBoxHostApiDevices.SelectedItem;

            SetDeviceNumber();

            this.textBox1.Text = deviceInfo.Dump();
        }
示例#5
0
        private void comboBoxHostApi_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.comboBoxHostApiDevices.Items.Clear();

            PortAudio.PaHostApiInfo hostApiInfo = (PortAudio.PaHostApiInfo) this.comboBoxHostApi.SelectedItem;

            int hostApiIndex = PortAudio.NativeMethods.Pa_HostApiTypeIdToHostApiIndex(hostApiInfo.type);

            for (int hostDevice = 0; hostDevice < hostApiInfo.deviceCount; hostDevice++)
            {
                int device = PortAudio.NativeMethods.Pa_HostApiDeviceIndexToDeviceIndex(hostApiIndex, hostDevice);

                PortAudio.PaDeviceInfo deviceInfo = PortAudio.ManagedWrappers.Pa_GetDeviceInfo(device);

                this.comboBoxHostApiDevices.Items.Add(deviceInfo);
            }

            this.comboBoxHostApiDevices.SelectedIndex = 0;

            SetDeviceNumber();

            this.textBox2.Text = hostApiInfo.Dump();
        }
示例#6
0
        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);
        }
示例#7
0
 public DeviceItem(int deviceIndex, PortAudio.PaDeviceInfo deviceInfo)
 {
     this.deviceIndex = deviceIndex;
     this.deviceInfo = deviceInfo;
 }
示例#8
0
 public DeviceItem(int deviceIndex, PortAudio.PaDeviceInfo deviceInfo)
 {
     this.deviceIndex = deviceIndex;
     this.deviceInfo  = deviceInfo;
 }