public Audio(int inputChannels, int outputChannels, int frequency, uint framesPerBuffer, PortAudio.PaStreamCallbackDelegate paStreamCallback) { log("Initializing..."); this.inputChannels = inputChannels; this.outputChannels = outputChannels; 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()); }
public Audio(int inputChannels, int outputChannels, int frequency, uint framesPerBuffer, PortAudio.PaStreamCallbackDelegate paStreamCallback) { log("Initializing..."); this.inputChannels = inputChannels; this.outputChannels = outputChannels; 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()); }
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 HostApiItem(PortAudio.PaHostApiInfo hostApiInfo, IUpdatableControl updatableControl) { this.hostApiInfo = hostApiInfo; int deviceCount = PortAudio.Pa_GetDeviceCount(); int selectedHostApiDeviceCount = 0; 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 == hostApiInfo.type) { selectedHostApiDeviceCount++; } } if (selectedHostApiDeviceCount > 0) { switch(hostApiInfo.type) { case PortAudio.PaHostApiTypeId.paMME: hostApiDeviceControl = new MMEDeviceControl(hostApiInfo, updatableControl); break; case PortAudio.PaHostApiTypeId.paDirectSound: hostApiDeviceControl = new DirectSoundDeviceControl(hostApiInfo, updatableControl); break; case PortAudio.PaHostApiTypeId.paASIO: hostApiDeviceControl = new ASIODeviceControl(hostApiInfo, updatableControl); break; case PortAudio.PaHostApiTypeId.paALSA: hostApiDeviceControl = new ALSADeviceControl(hostApiInfo, updatableControl); break; } } else { hostApiDeviceControl = new NoDevicesDeviceControl(hostApiInfo, updatableControl); } }
public NoDevicesDeviceControl(PortAudio.PaHostApiInfo paHostApiInfo, IUpdatableControl updatableControl) { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // // TODO: Add constructor code after the InitializeComponent() call. // this.paHostApiInfo = paHostApiInfo; this.updatableControl = updatableControl; }
public ASIODeviceControl(PortAudio.PaHostApiInfo paHostApiInfo, IUpdatableControl updatableControl) { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // // TODO: Add constructor code after the InitializeComponent() call. // this.paHostApiInfo = paHostApiInfo; this.updatableControl = updatableControl; }
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.paALSA)) { selectedHostApi = i; } } return(selectedHostApi); }
public HostApiItem(PortAudio.PaHostApiInfo hostApiInfo, IUpdatableControl updatableControl) { this.hostApiInfo = hostApiInfo; int deviceCount = PortAudio.Pa_GetDeviceCount(); int selectedHostApiDeviceCount = 0; 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 == hostApiInfo.type) { selectedHostApiDeviceCount++; } } if (selectedHostApiDeviceCount > 0) { switch (hostApiInfo.type) { case PortAudio.PaHostApiTypeId.paMME: hostApiDeviceControl = new MMEDeviceControl(hostApiInfo, updatableControl); break; case PortAudio.PaHostApiTypeId.paDirectSound: hostApiDeviceControl = new DirectSoundDeviceControl(hostApiInfo, updatableControl); break; case PortAudio.PaHostApiTypeId.paASIO: hostApiDeviceControl = new ASIODeviceControl(hostApiInfo, updatableControl); break; case PortAudio.PaHostApiTypeId.paALSA: hostApiDeviceControl = new ALSADeviceControl(hostApiInfo, updatableControl); break; } } else { hostApiDeviceControl = new NoDevicesDeviceControl(hostApiInfo, updatableControl); } }
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, this)); } } 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; update(); }
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; }