public unsafe static bool StartAudio(ref PA19.PaStreamCallback callback, uint block_size, double sample_rate, int host_api_index, int input_dev_index, int output_dev_index, int num_channels, int callback_num, int latency_ms) // changes yt7pwr { try { if (enable_local_host) // normal operation { if (res_outl == null) res_outl = new float[65536]; if (res_outr == null) res_outr = new float[65536]; if (res_inl == null) res_inl = new float[65536]; if (res_inr == null) res_inr = new float[65536]; if (vac_outl == null) vac_outl = new float[65536]; if (vac_outr == null) vac_outr = new float[65536]; if (vac_inl == null) vac_inl = new float[65536]; if (vac_inr == null) vac_inr = new float[65536]; int in_dev = PA19.PA_HostApiDeviceIndexToDeviceIndex(host_api_index, input_dev_index); int out_dev = PA19.PA_HostApiDeviceIndexToDeviceIndex(host_api_index, output_dev_index); PA19.PaStreamParameters inparam = new PA19.PaStreamParameters(); PA19.PaStreamParameters outparam = new PA19.PaStreamParameters(); inparam.device = in_dev; inparam.channelCount = num_channels; inparam.sampleFormat = PA19.paFloat32 | PA19.paNonInterleaved; inparam.suggestedLatency = ((float)latency_ms / 1000); outparam.device = out_dev; outparam.channelCount = num_channels; outparam.sampleFormat = PA19.paFloat32 | PA19.paNonInterleaved; outparam.suggestedLatency = ((float)latency_ms / 1000); if (host_api_index == PA19.PA_HostApiTypeIdToHostApiIndex(PA19.PaHostApiTypeId.paWASAPI) && (console.WinVer == WindowsVersion.Windows7 || console.WinVer == WindowsVersion.Windows8 || console.WinVer == WindowsVersion.WindowsVista)) { PA19.PaWasapiStreamInfo stream_info = new PA19.PaWasapiStreamInfo(); stream_info.hostApiType = PA19.PaHostApiTypeId.paWASAPI; stream_info.version = 1; stream_info.flags = 0; stream_info.threadPriority = PA19.PaWasapiThreadPriority.eThreadPriorityNone; stream_info.size = (UInt32)sizeof(PA19.PaWasapiStreamInfo); inparam.hostApiSpecificStreamInfo = &stream_info; outparam.hostApiSpecificStreamInfo = &stream_info; } int error = 0; if (callback_num == 0) error = PA19.PA_OpenStream(out stream3, &inparam, &outparam, sample_rate, block_size, 0, callback, 0, 2); else error = PA19.PA_OpenStream(out stream5, &inparam, &outparam, sample_rate, block_size, 0, callback, 0, 4); // VAC if (error != 0) { #if(WIN32) MessageBox.Show(PA19.PA_GetErrorText(error), "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show(text, "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif return false; } if (callback_num == 0) error = PA19.PA_StartStream(stream3); else error = PA19.PA_StartStream(stream5); if (error != 0) { #if(WIN32) MessageBox.Show(PA19.PA_GetErrorText(error), "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show(text, "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif } return true; } else if (enable_ethernet_server) { if (res_inl == null) res_inl = new float[65536]; if (res_inr == null) res_inr = new float[65536]; if (vac_outl == null) vac_outl = new float[65536]; if (vac_outr == null) vac_outr = new float[65536]; if (vac_inl == null) vac_inl = new float[65536]; if (vac_inr == null) vac_inr = new float[65536]; resampServerPtrIn_l = DttSP.NewResamplerF(sample_rate1, 6000); resampServerPtrIn_r = DttSP.NewResamplerF(sample_rate1, 6000); resampPtrOut_l = DttSP.NewResamplerF(6000, sample_rate1); resampPtrOut_r = DttSP.NewResamplerF(6000, sample_rate1); int in_dev = PA19.PA_HostApiDeviceIndexToDeviceIndex(host_api_index, input_dev_index); int out_dev = PA19.PA_HostApiDeviceIndexToDeviceIndex(host_api_index, output_dev_index); PA19.PaStreamParameters inparam = new PA19.PaStreamParameters(); PA19.PaStreamParameters outparam = new PA19.PaStreamParameters(); inparam.device = in_dev; inparam.channelCount = num_channels; inparam.sampleFormat = PA19.paFloat32 | PA19.paNonInterleaved; inparam.suggestedLatency = ((float)latency_ms / 1000); outparam.device = out_dev; outparam.channelCount = num_channels; outparam.sampleFormat = PA19.paFloat32 | PA19.paNonInterleaved; outparam.suggestedLatency = ((float)latency_ms / 1000); int error = 0; error = PA19.PA_OpenStream(out stream3, &inparam, &outparam, sample_rate, block_size, 0, callback, 0, 2); if (error != 0) { #if(WIN32) MessageBox.Show(PA19.PA_GetErrorText(error), "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show(text, "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif return false; } if (callback_num == 0) error = PA19.PA_StartStream(stream3); if (error != 0) { #if(WIN32) MessageBox.Show(PA19.PA_GetErrorText(error), "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show(text, "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif return false; } return true; } else if (enable_ethernet_client) // network client mode { if (res_outl == null) res_outl = new float[65536]; if (res_outr == null) res_outr = new float[65536]; if (vac_outl == null) vac_outl = new float[65536]; if (vac_outr == null) vac_outr = new float[65536]; if (vac_inl == null) vac_inl = new float[65536]; if (vac_inr == null) vac_inr = new float[65536]; resampPtrOut_l = DttSP.NewResamplerF(6000, sample_rate1); resampPtrOut_r = DttSP.NewResamplerF(6000, sample_rate1); resampServerPtrIn_l = DttSP.NewResamplerF(sample_rate1, 6000); resampServerPtrIn_r = DttSP.NewResamplerF(sample_rate1, 6000); int in_dev = PA19.PA_HostApiDeviceIndexToDeviceIndex(host_api_index, input_dev_index); int out_dev = PA19.PA_HostApiDeviceIndexToDeviceIndex(host_api_index, output_dev_index); PA19.PaStreamParameters inparam = new PA19.PaStreamParameters(); PA19.PaStreamParameters outparam = new PA19.PaStreamParameters(); inparam.device = in_dev; inparam.channelCount = num_channels; inparam.sampleFormat = PA19.paFloat32 | PA19.paNonInterleaved; inparam.suggestedLatency = ((float)latency_ms / 1000); outparam.device = out_dev; outparam.channelCount = num_channels; outparam.sampleFormat = PA19.paFloat32 | PA19.paNonInterleaved; outparam.suggestedLatency = ((float)latency_ms / 1000); int error = 0; if (vac_callback) error = PA19.PA_OpenStream(out stream3, &inparam, &outparam, sample_rate, block_size, 0, callback, 0, 2); else error = PA19.PA_OpenStream(out stream5, null, &outparam, sample_rate, block_size, 0, callback, 0, 4); // VAC if (error != 0) { #if(WIN32) MessageBox.Show(PA19.PA_GetErrorText(error), "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show(text, "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif return false; } if (callback_num == 0) error = PA19.PA_StartStream(stream3); else error = PA19.PA_StartStream(stream5); if (error != 0) { #if(WIN32) MessageBox.Show(PA19.PA_GetErrorText(error), "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show(text, "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif return false; } return true; } return false; } catch (Exception ex) { Debug.Print(ex.ToString()); return false; } }
public unsafe static bool StartAudioExclusiveWin7(ref PA19.PaStreamCallback callback, uint block_size, double sample_rate, int host_api_index, int input_dev_index, int output_dev_index, int callback_id, int callback_num, int latency_ms) // yt7pwr { try { #region local host if (enable_local_host) // normal operation { int error = 0; if (res_outl == null) res_outl = new float[65536]; if (res_outr == null) res_outr = new float[65536]; if (res_inl == null) res_inl = new float[65536]; if (res_inr == null) res_inr = new float[65536]; if (vac_outl == null) vac_outl = new float[65536]; if (vac_outr == null) vac_outr = new float[65536]; if (vac_inl == null) vac_inl = new float[65536]; if (vac_inr == null) vac_inr = new float[65536]; int in_dev = PA19.PA_HostApiDeviceIndexToDeviceIndex(host_api_index, input_dev_index); int out_dev = PA19.PA_HostApiDeviceIndexToDeviceIndex(host_api_index, output_dev_index); PA19.PaStreamParameters inparam = new PA19.PaStreamParameters(); PA19.PaStreamParameters outparam = new PA19.PaStreamParameters(); if (output_dev_index == 0xffff) { inparam.device = in_dev; inparam.channelCount = 2; inparam.sampleFormat = PA19.paFloat32 | PA19.paNonInterleaved; inparam.suggestedLatency = ((float)latency_ms / 1000); if (host_api_index == PA19.PA_HostApiTypeIdToHostApiIndex(PA19.PaHostApiTypeId.paWASAPI) && audio_exclusive && (console.WinVer == WindowsVersion.Windows7 | console.WinVer == WindowsVersion.Windows8 || console.WinVer == WindowsVersion.WindowsVista)) { PA19.PaWasapiStreamInfo input_stream_info = new PA19.PaWasapiStreamInfo(); input_stream_info.hostApiType = PA19.PaHostApiTypeId.paWASAPI; input_stream_info.threadPriority = PA19.PaWasapiThreadPriority.eThreadPriorityProAudio; input_stream_info.version = 1; input_stream_info.size = (UInt32)sizeof(PA19.PaWasapiStreamInfo); input_stream_info.flags = (UInt32)PA19.PaWasapiFlags.paWinWasapiExclusive | PA19.AUDCLNT_STREAMFLAGS_EVENTCALLBACK; inparam.hostApiSpecificStreamInfo = &input_stream_info; } error = 0; if (callback_num == 0) error = PA19.PA_OpenStream(out stream1, &inparam, null, sample_rate, block_size, 0, callback, 0, callback_id); else error = PA19.PA_OpenStream(out stream5, &inparam, null, sample_rate, block_size, 0, callback, 0, callback_id); // input for excl. VAC if (error != 0) { #if(WIN32) MessageBox.Show("Opening input fails!\n\n" + PA19.PA_GetErrorText(error).ToString(), "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show("Opening input fails!\n\n" + text, "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif return false; } if (callback_num == 0) error = PA19.PA_StartStream(stream1); else error = PA19.PA_StartStream(stream5); if (error != 0) { #if(WIN32) MessageBox.Show("Starting input fails!\n" + PA19.PA_GetErrorText(error).ToString(), "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show("Starting input fails!\n" + text, "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif return false; } } else if (output_dev_index == 0xf0f0) { inparam.device = in_dev; inparam.channelCount = 2; inparam.sampleFormat = PA19.paFloat32 | PA19.paNonInterleaved; inparam.suggestedLatency = ((float)latency_ms / 1000); if (host_api_index == PA19.PA_HostApiTypeIdToHostApiIndex(PA19.PaHostApiTypeId.paWASAPI) && audio_exclusive && (console.WinVer == WindowsVersion.Windows7 || console.WinVer == WindowsVersion.Windows8 || console.WinVer == WindowsVersion.WindowsVista)) { PA19.PaWasapiStreamInfo input_stream_info = new PA19.PaWasapiStreamInfo(); input_stream_info.hostApiType = PA19.PaHostApiTypeId.paWASAPI; input_stream_info.threadPriority = PA19.PaWasapiThreadPriority.eThreadPriorityProAudio; input_stream_info.version = 1; input_stream_info.size = (UInt32)sizeof(PA19.PaWasapiStreamInfo); input_stream_info.flags = (UInt32)PA19.PaWasapiFlags.paWinWasapiExclusive | PA19.AUDCLNT_STREAMFLAGS_EVENTCALLBACK; inparam.hostApiSpecificStreamInfo = &input_stream_info; } error = 0; error = PA19.PA_OpenStream(out stream2, &inparam, null, sample_rate, block_size, 0, callback, 0, callback_id); if (error != 0) { #if(WIN32) MessageBox.Show("Opening input fails!\n\n" + PA19.PA_GetErrorText(error).ToString(), "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show("Opening input fails!\n\n" + text, "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif return false; } error = PA19.PA_StartStream(stream2); if (error != 0) { #if(WIN32) MessageBox.Show("Starting input fails!\n" + PA19.PA_GetErrorText(error).ToString(), "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show("Starting input fails!\n" + text, "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif return false; } } else if (input_dev_index == 0xffff) { outparam.device = out_dev; outparam.channelCount = 2; outparam.sampleFormat = PA19.paFloat32 | PA19.paNonInterleaved; outparam.suggestedLatency = ((float)latency_ms / 1000); if (host_api_index == PA19.PA_HostApiTypeIdToHostApiIndex(PA19.PaHostApiTypeId.paWASAPI) && (console.WinVer == WindowsVersion.Windows7 || console.WinVer == WindowsVersion.Windows8 || console.WinVer == WindowsVersion.WindowsVista)) { PA19.PaWasapiStreamInfo output_stream_info = new PA19.PaWasapiStreamInfo(); output_stream_info.hostApiType = PA19.PaHostApiTypeId.paWASAPI; output_stream_info.threadPriority = PA19.PaWasapiThreadPriority.eThreadPriorityProAudio; output_stream_info.version = 1; output_stream_info.size = (UInt32)sizeof(PA19.PaWasapiStreamInfo); output_stream_info.flags = (UInt32)PA19.PaWasapiFlags.paWinWasapiExclusive | PA19.AUDCLNT_STREAMFLAGS_EVENTCALLBACK; outparam.hostApiSpecificStreamInfo = &output_stream_info; } if (callback_num == 0) error = PA19.PA_OpenStream(out stream3, null, &outparam, sample_rate, block_size, 0, callback, 0, callback_id); else error = PA19.PA_OpenStream(out stream6, null, &outparam, sample_rate, block_size, 0, callback, 0, callback_id); if (error != 0) { #if(WIN32) MessageBox.Show("Opening output fails!\n" + PA19.PA_GetErrorText(error).ToString(), "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show("Opening output fails!\n" + text, "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif return false; } if (callback_num == 0) error = PA19.PA_StartStream(stream3); else error = PA19.PA_StartStream(stream6); if (error != 0) { #if(WIN32) MessageBox.Show("Starting output fails!\n" + PA19.PA_GetErrorText(error).ToString(), "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show("Starting output fails!\n" + text, "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif return false; } } else if (input_dev_index == 0xf0f0) { outparam.device = out_dev; outparam.channelCount = 2; outparam.sampleFormat = PA19.paFloat32 | PA19.paNonInterleaved; outparam.suggestedLatency = ((float)latency_ms / 1000); if (host_api_index == PA19.PA_HostApiTypeIdToHostApiIndex(PA19.PaHostApiTypeId.paWASAPI) && (console.WinVer == WindowsVersion.Windows7 || console.WinVer == WindowsVersion.Windows8 || console.WinVer == WindowsVersion.WindowsVista)) { PA19.PaWasapiStreamInfo output_stream_info = new PA19.PaWasapiStreamInfo(); output_stream_info.hostApiType = PA19.PaHostApiTypeId.paWASAPI; output_stream_info.threadPriority = PA19.PaWasapiThreadPriority.eThreadPriorityProAudio; output_stream_info.version = 1; output_stream_info.size = (UInt32)sizeof(PA19.PaWasapiStreamInfo); output_stream_info.flags = (UInt32)PA19.PaWasapiFlags.paWinWasapiExclusive | PA19.AUDCLNT_STREAMFLAGS_EVENTCALLBACK; outparam.hostApiSpecificStreamInfo = &output_stream_info; } error = PA19.PA_OpenStream(out stream4, null, &outparam, sample_rate, block_size, 0, callback, 0, callback_id); if (error != 0) { #if(WIN32) MessageBox.Show("Opening output fails!\n" + PA19.PA_GetErrorText(error).ToString(), "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show("Opening output fails!\n" + text, "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif return false; } error = PA19.PA_StartStream(stream4); if (error != 0) { #if(WIN32) MessageBox.Show("Starting output fails!\n" + PA19.PA_GetErrorText(error).ToString(), "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show("Starting output fails!\n" + text, "PortAudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif return false; } } return true; } #endregion return false; } catch (Exception ex) { Debug.Print(ex.ToString()); return false; } }
public unsafe static bool StartVACAudio(ref PA19.PaStreamCallback callback, uint block_size, double sample_rate, int host_api_index, int input_dev_index, int output_dev_index, int num_channels, int latency_ms) // yt7pwr { try { int in_dev = PA19.PA_HostApiDeviceIndexToDeviceIndex(host_api_index, input_dev_index); int out_dev = PA19.PA_HostApiDeviceIndexToDeviceIndex(host_api_index, output_dev_index); PA19.PaStreamParameters inparam = new PA19.PaStreamParameters(); PA19.PaStreamParameters outparam = new PA19.PaStreamParameters(); inparam.device = in_dev; inparam.channelCount = num_channels; inparam.sampleFormat = PA19.paFloat32 | PA19.paNonInterleaved; inparam.suggestedLatency = ((float)latency_ms / 1000); outparam.device = out_dev; outparam.channelCount = num_channels; outparam.sampleFormat = PA19.paFloat32 | PA19.paNonInterleaved; outparam.suggestedLatency = ((float)latency_ms / 1000); if (host_api_index == PA19.PA_HostApiTypeIdToHostApiIndex(PA19.PaHostApiTypeId.paWASAPI) && (console.WinVer == WindowsVersion.Windows7 || console.WinVer == WindowsVersion.Windows8 || console.WinVer == WindowsVersion.WindowsVista)) { PA19.PaWasapiStreamInfo stream_info = new PA19.PaWasapiStreamInfo(); stream_info.hostApiType = PA19.PaHostApiTypeId.paWASAPI; stream_info.version = 1; stream_info.flags = 0; stream_info.threadPriority = PA19.PaWasapiThreadPriority.eThreadPriorityNone; stream_info.size = (UInt32)sizeof(PA19.PaWasapiStreamInfo); inparam.hostApiSpecificStreamInfo = &stream_info; outparam.hostApiSpecificStreamInfo = &stream_info; } int error = PA19.PA_OpenStream(out stream5, &inparam, &outparam, sample_rate, block_size, 0, callback, 0, 4); if (error != 0) { #if(WIN32) MessageBox.Show(PA19.PA_GetErrorText(error), "PortAudio Error\n VAC settings error!", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show(text, "PortAudio Error\n VAC settings error!", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif return false; } error = PA19.PA_StartStream(stream5); if (error != 0) { #if(WIN32) MessageBox.Show(PA19.PA_GetErrorText(error), "PortAudio Error\nVAC settings error!", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif #if(WIN64) string err = PA19.PA_GetErrorText(error); byte[] berr = System.Text.Encoding.Unicode.GetBytes(err); string text = Encoding.UTF8.GetString(berr); MessageBox.Show(text, "PortAudio Error\nVAC settings error", MessageBoxButtons.OK, MessageBoxIcon.Error); #endif return false; } return true; } catch (Exception ex) { Debug.Write(ex.ToString()); return false; } }