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());
        }
        private int apiSelect()
        {
            int selectedHostApi = PortAudio.Pa_GetDefaultHostApi();
            int apiCount        = PortAudio.Pa_GetHostApiCount();

            for (int i = 0; i < apiCount; i++)
            {
                PortAudio.PaHostApiInfo apiInfo = PortAudio.Pa_GetHostApiInfo(i);
                if ((apiInfo.type == PortAudio.PaHostApiTypeId.paDirectSound) ||
                    (apiInfo.type == PortAudio.PaHostApiTypeId.paOSS))
                {
                    selectedHostApi = i;
                }
            }
            return(selectedHostApi);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Selects the most appropriate host api
        /// </summary>
        /// <returns>The most appropriate host api</returns>
        public int GetHostApi()
        {
            if (_Disposed)
            {
                throw new ObjectDisposedException("PortAudioHandle already disposed");
            }

            int selectedHostApi = PortAudio.Pa_GetDefaultHostApi();
            int apiCount        = PortAudio.Pa_GetHostApiCount();

            for (int i = 0; i < apiCount; i++)
            {
                PortAudio.PaHostApiInfo apiInfo = PortAudio.Pa_GetHostApiInfo(i);
                if ((apiInfo.type == PortAudio.PaHostApiTypeId.paDirectSound) ||
                    (apiInfo.type == PortAudio.PaHostApiTypeId.paALSA))
                {
                    selectedHostApi = i;
                }
            }
            return(selectedHostApi);
        }
Exemplo n.º 4
0
        void AudioSettingsControlLoad(object sender, EventArgs e)
        {
            driverTypeComboBox.Items.Clear();
            int hostApiCount = PortAudio.Pa_GetHostApiCount();

            for (int i = 0; i < hostApiCount; i++)
            {
                PortAudio.PaHostApiInfo hostApiInfo = PortAudio.Pa_GetHostApiInfo(i);
                if (hostApiInfo.type != PortAudio.PaHostApiTypeId.paInDevelopment)
                {
                    driverTypeComboBox.Items.Add(new HostApiItem(hostApiInfo));
                }
            }
            driverTypeComboBox.SelectedIndex = PortAudio.Pa_GetDefaultHostApi();

            sampleRateComboBox.Items.Clear();
            sampleRateComboBox.Items.Add(192000);
            sampleRateComboBox.Items.Add(176400);
            sampleRateComboBox.Items.Add(96000);
            sampleRateComboBox.Items.Add(88200);
            sampleRateComboBox.Items.Add(48000);
            sampleRateComboBox.Items.Add(44100);
            sampleRateComboBox.Items.Add(38400);
            sampleRateComboBox.Items.Add(37800);
            sampleRateComboBox.Items.Add(32000);
            sampleRateComboBox.Items.Add(24000);
            sampleRateComboBox.Items.Add(22050);
            sampleRateComboBox.Items.Add(19200);
            sampleRateComboBox.Items.Add(18900);
            sampleRateComboBox.Items.Add(16000);
            sampleRateComboBox.Items.Add(12000);
            sampleRateComboBox.Items.Add(11025);
            sampleRateComboBox.Items.Add(9600);
            sampleRateComboBox.Items.Add(8000);
            sampleRateComboBox.SelectedIndex = 5;
        }