public unsafe static bool StartAudioExclusiveWinXP(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_inl == null) res_inl = 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); 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 inputs 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); 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); error = 0; 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); error = 0; 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; } }
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; } }
unsafe public static int input_CallbackVAC(void* input, void* output, int frameCount, // yt7pwr PA19.PaStreamCallbackTimeInfo* timeInfo, int statusFlags, void* userData) { try { #if(WIN64) Int64* array_ptr = (Int64*)input; float* in_l_ptr1 = (float*)array_ptr[0]; float* in_r_ptr1 = (float*)array_ptr[1]; #endif #if(WIN32) int* array_ptr = (int*)input; float* in_l_ptr1 = (float*)array_ptr[0]; float* in_r_ptr1 = null; if (console.SetupForm.VACchNumber == 2) in_r_ptr1 = (float*)array_ptr[1]; // stereo else in_r_ptr1 = (float*)array_ptr[0]; // mono #endif if (vac_rb_reset) { vac_rb_reset = false; Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.Reset(); rb_vacIN_r.Reset(); rb_vacOUT_l.Reset(); rb_vacOUT_r.Reset(); Win32.LeaveCriticalSection(cs_vac); return 0; } //[patch_7 #region VOX if (vox_enabled) { float* vox_l = null, vox_r = null; vox_l = in_l_ptr1; vox_r = in_r_ptr1; if (dsp_mode == DSPMode.LSB || dsp_mode == DSPMode.USB || dsp_mode == DSPMode.DSB || dsp_mode == DSPMode.AM || dsp_mode == DSPMode.SAM || dsp_mode == DSPMode.FMN) { Peak = MaxSample(vox_l, vox_r, frameCount); // compare power to threshold if (Peak > vox_threshold) vox_active = true; else vox_active = false; } } #endregion //patch_7] if (mox) { if ((console.CurrentDSPMode == DSPMode.CWU || console.CurrentDSPMode == DSPMode.CWL) && vac_mon && mon) { } else { if (vac_resample) { int outsamps; fixed (float* res_inl_ptr = &(res_inl[0])) fixed (float* res_inr_ptr = &(res_inr[0])) { DttSP.DoResamplerF(in_l_ptr1, res_inl_ptr, frameCount, &outsamps, resampPtrIn_l); DttSP.DoResamplerF(in_r_ptr1, res_inr_ptr, frameCount, &outsamps, resampPtrIn_r); if ((rb_vacIN_l.WriteSpace() >= outsamps) && (rb_vacIN_r.WriteSpace() >= outsamps)) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.WritePtr(res_inl_ptr, outsamps); rb_vacIN_r.WritePtr(res_inr_ptr, outsamps); Win32.LeaveCriticalSection(cs_vac); if (wave_record && record_tx_preprocessed && vac_primary_audiodev) wave_file_writer.AddWriteBuffer(res_inl_ptr, res_inr_ptr); } else { VACDebug("rb_vacIN overflow CBvac"); } if (vac_mon && mon) { Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.WritePtr(in_l_ptr1, frameCount); rb_vacOUT_r.WritePtr(in_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); } } } else { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.WritePtr(in_l_ptr1, frameCount); rb_vacIN_r.WritePtr(in_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); if (wave_record && record_tx_preprocessed && vac_primary_audiodev) wave_file_writer.AddWriteBuffer(in_l_ptr1, in_r_ptr1); if (vac_mon && mon) { Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.WritePtr(in_l_ptr1, frameCount); rb_vacOUT_r.WritePtr(in_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); } } } } return VAC_callback_return; } catch (Exception ex) { Debug.Write(ex.ToString()); return 0; } }
unsafe public static int output_CallbackVAC(void* input, void* output, int frameCount, // yt7pwr PA19.PaStreamCallbackTimeInfo* timeInfo, int statusFlags, void* userData) { try { #if(WIN64) Int64* array_ptr = (Int64*)output; float* out_l_ptr1 = (float*)array_ptr[0]; float* out_r_ptr1 = null; #endif #if(WIN32) int* array_ptr = (int*)output; float* out_l_ptr1 = (float*)array_ptr[0]; float* out_r_ptr1 = null; if (console.SetupForm.VACchNumber == 2) out_r_ptr1 = (float*)array_ptr[1]; // stereo else out_r_ptr1 = (float*)array_ptr[0]; // mono #endif if (vac_rb_reset) { vac_rb_reset = false; ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.Reset(); rb_vacIN_r.Reset(); rb_vacOUT_l.Reset(); rb_vacOUT_r.Reset(); Win32.LeaveCriticalSection(cs_vac); return 0; } double vol_l = vac_volume_left; double vol_r = vac_volume_right; if (mox && mon && vac_mon) { if (vac_resample) { if ((rb_vacOUT_l.ReadSpace() >= frameCount) && (rb_vacOUT_r.ReadSpace() >= frameCount)) { Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.ReadPtr(out_l_ptr1, frameCount); rb_vacOUT_r.ReadPtr(out_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); if (wave_record && !record_tx_preprocessed && vac_primary_audiodev) wave_file_writer.AddWriteBuffer(out_l_ptr1, out_r_ptr1); } else { VACDebug("rb_vacIN underflow CBvac"); } } else { if (dsp_mode == DSPMode.CWL || dsp_mode == DSPMode.CWU) { DttSP.CWMonitorExchange(out_l_ptr1, out_r_ptr1, frameCount); } else { Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.ReadPtr(out_l_ptr1, frameCount); rb_vacOUT_r.ReadPtr(out_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); } ScaleBuffer(out_l_ptr1, out_l_ptr1, frameCount, (float)vac_rx_scale); ScaleBuffer(out_r_ptr1, out_r_ptr1, frameCount, (float)vac_rx_scale); if (wave_record && !record_tx_preprocessed && vac_primary_audiodev) wave_file_writer.AddWriteBuffer(out_l_ptr1, out_r_ptr1); } } else if (!mox) { Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.ReadPtr(out_l_ptr1, frameCount); rb_vacOUT_r.ReadPtr(out_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); ScaleBuffer(out_l_ptr1, out_l_ptr1, frameCount, (float)vac_rx_scale); ScaleBuffer(out_r_ptr1, out_r_ptr1, frameCount, (float)vac_rx_scale); if (wave_record && !record_rx_preprocessed && vac_primary_audiodev) wave_file_writer.AddWriteBuffer(out_l_ptr1, out_r_ptr1); } if (VACPrimaryAudiodevice && mox && (!vac_mon || !mon)) // TX { ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); } else { switch (vac_mute_ch) { case MuteChannels.Left: { ScaleBuffer(out_r_ptr1, out_r_ptr1, frameCount, (float)vol_r); ScaleBuffer(out_r_ptr1, out_l_ptr1, frameCount, 1.0f); } break; case MuteChannels.Right: { ScaleBuffer(out_l_ptr1, out_l_ptr1, frameCount, (float)vol_l); ScaleBuffer(out_l_ptr1, out_r_ptr1, frameCount, 1.0f); } break; case MuteChannels.Both: { ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); } break; case MuteChannels.None: { ScaleBuffer(out_l_ptr1, out_l_ptr1, frameCount, (float)vol_l); ScaleBuffer(out_r_ptr1, out_r_ptr1, frameCount, (float)vol_r); } break; } } return VAC_callback_return; } catch (Exception ex) { Debug.Write(ex.ToString()); return 0; } }
public static unsafe extern int StartAudioNative(int sample_rate, int samples_per_block, PA19.PaStreamCallback cb, int sample_bits, int no_send);
unsafe public static int Pipe(void* input, void* output, int frameCount, PA19.PaStreamCallbackTimeInfo* timeInfo, int statusFlags, void* userData) { float* inptr = (float*)input; float* outptr = (float*)output; for (int i = 0; i < frameCount; i++) { *outptr++ = *inptr++; *outptr++ = *inptr++; } return 0; }
unsafe public static int NetworkServerCallbackVACFullSpectar(void* input, void* output, int frameCount, PA19.PaStreamCallbackTimeInfo* timeInfo, int statusFlags, void* userData) { return 0; }
unsafe public static int input_Callback4Port(void* input, void* output, int frameCount, // yt7pwr PA19.PaStreamCallbackTimeInfo* timeInfo, int statusFlags, void* userData) { try { if (mox || (vox_enabled && !vac_enabled)) { #if(WIN64) Int64* array_ptr = (Int64*)input; float* in_l_ptr1 = (float*)array_ptr[0]; float* in_r_ptr1 = (float*)array_ptr[1]; double* VAC_in = (double*)input; #endif #if(WIN32) int* array_ptr = (int*)input; float* in_l_ptr1 = (float*)array_ptr[0]; float* in_r_ptr1 = (float*)array_ptr[1]; double* VAC_in = (double*)input; #endif float* in_l = null, in_l_VAC = null, in_r = null, in_r_VAC = null; if (!mox && !voice_message_record) // rx { in_l = in_l_ptr1; in_r = in_r_ptr1; } else if (mox && !voice_message_record) { // tx if (voice_message_playback) voice_msg_file_reader.GetPlayBuffer(in_l_ptr1, in_l_ptr1); in_l = in_l_ptr1; in_r = in_r_ptr1; } else if (voice_message_record) { in_l = in_l_ptr1; in_r = in_r_ptr1; } if (voice_message_record) { try { if (vac_enabled) { if (rb_vacIN_l.ReadSpace() >= frameCount && rb_vacIN_r.ReadSpace() >= frameCount) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(in_l_ptr1, frameCount); rb_vacIN_r.ReadPtr(in_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { ClearBuffer(in_l_ptr1, frameCount); ClearBuffer(in_r_ptr1, frameCount); VACDebug("rb_vacIN underflow VoiceMsg record"); } } ScaleBuffer(in_l, in_l, frameCount, (float)mic_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)mic_preamp); voice_msg_file_writer.AddWriteBuffer(in_l, in_r); } catch (Exception ex) { VACDebug("Audio: " + ex.ToString()); } } if (loopDLL_enabled) { int i; fixed (double* loopDLL_inl_ptr = &(loopDLL_inl[0])) { if (console.loopDLL.ReadTXBuffer(loopDLL_inl_ptr)) { for (i = 0; i < frameCount; i++) { in_l[0] = (float)(loopDLL_inl[i] / 1e5); in_r[0] = 0.0f; //(float)(loopDLL_inl[i] / 1e4); in_l++; in_r++; } } else { } } in_l = in_l_ptr1; in_r = in_r_ptr1; } switch (current_audio_state1) { case AudioState.DTTSP: #region VOX float* vox_l = null, vox_r = null; vox_l = in_l_ptr1; vox_r = in_l_ptr1; if (vox_enabled && !vac_enabled) { if (dsp_mode == DSPMode.LSB || dsp_mode == DSPMode.USB || dsp_mode == DSPMode.DSB || dsp_mode == DSPMode.AM || dsp_mode == DSPMode.SAM || dsp_mode == DSPMode.FMN) { ScaleBuffer(vox_l, vox_l, frameCount, (float)mic_preamp); ScaleBuffer(vox_r, vox_r, frameCount, (float)mic_preamp); Peak = MaxSample(vox_l, vox_r, frameCount); // compare power to threshold if (Peak > vox_threshold) vox_active = true; else vox_active = false; } } #endregion else { // scale input with mic preamp if ((mox || voice_message_record) && dsp_mode == DSPMode.LSB || dsp_mode == DSPMode.USB || dsp_mode == DSPMode.DSB || dsp_mode == DSPMode.AM || dsp_mode == DSPMode.SAM || dsp_mode == DSPMode.FMN) { ScaleBuffer(in_l, in_l, frameCount, (float)mic_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)mic_preamp); } else { ScaleBuffer(in_l, in_l, frameCount, 0.0f); ScaleBuffer(in_r, in_r, frameCount, 0.0f); } if (echo_enable && (dsp_mode != DSPMode.DIGL || dsp_mode != DSPMode.DIGU)) { if (!echo_pause) { echoRB.WritePtr(in_l, frameCount); if (echoRB.ReadSpace() > echo_delay - 2) { EchoMixer(in_l, in_r, frameCount); } } } } #region Input Signal Source switch (current_input_signal) { case SignalSource.SOUNDCARD: break; case SignalSource.SINE: SineWave(in_l, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(in_r, frameCount, phase_accumulator1, sine_freq1); ScaleBuffer(in_l, in_l, frameCount, (float)input_source_scale); ScaleBuffer(in_r, in_r, frameCount, (float)input_source_scale); break; case SignalSource.NOISE: Noise(in_l, frameCount); Noise(in_r, frameCount); break; case SignalSource.TRIANGLE: Triangle(in_l, frameCount, sine_freq1); CopyBuffer(in_l, in_r, frameCount); break; case SignalSource.SAWTOOTH: Sawtooth(in_l, frameCount, sine_freq1); CopyBuffer(in_l, in_r, frameCount); break; } #endregion if (!loopDLL_enabled && vac_enabled && rb_vacIN_l != null && rb_vacIN_r != null && rb_vacOUT_l != null && rb_vacOUT_r != null) { if (mox) { if (rb_vacIN_l.ReadSpace() >= frameCount && rb_vacIN_r.ReadSpace() >= frameCount) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(in_l, frameCount); rb_vacIN_r.ReadPtr(in_r, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { ClearBuffer(in_l, frameCount); ClearBuffer(in_r, frameCount); VACDebug("rb_vacIN underflow inCB4"); } ScaleBuffer(in_l, in_l, frameCount, (float)vac_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)vac_preamp); if (echo_enable && (dsp_mode != DSPMode.DIGL || dsp_mode != DSPMode.DIGU)) { if (!echo_pause) { echoRB.WritePtr(in_l, frameCount); if (echoRB.ReadSpace() > echo_delay - 2) { EchoMixer(in_l, in_r, frameCount); } } } } } else if (!VACDirectI_Q && loopDLL_enabled && mox) { ScaleBuffer(in_l, in_l, frameCount, (float)vac_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)vac_preamp); } DttSP_mutex.WaitOne(); DttSP.ExchangeInputSamples(thread_no, in_l, in_r, frameCount); DttSP_mutex.ReleaseMutex(); break; case AudioState.CW: break; case AudioState.SWITCH: if (!ramp_down && !ramp_up) { ClearBuffer(in_l_ptr1, frameCount); ClearBuffer(in_l_ptr1, frameCount); if (mox != next_mox) mox = next_mox; } if (mox) DttSP.ExchangeInputSamples(thread_no, in_l_ptr1, in_l_ptr1, frameCount); if (ramp_down) { int i; for (i = 0; i < frameCount; i++) { float w = (float)Math.Sin(ramp_val * Math.PI / 2.0); in_l[i] *= w; in_r[i] *= w; ramp_val += ramp_step; if (++ramp_count >= ramp_samples) { ramp_down = false; break; } } if (ramp_down) { for (; i < frameCount; i++) { in_l[i] = 0.0f; in_r[i] = 0.0f; } } } else if (ramp_up) { for (int i = 0; i < frameCount; i++) { float w = (float)Math.Sin(ramp_val * Math.PI / 2.0); in_l[i] *= w; in_r[i] *= w; ramp_val += ramp_step; if (++ramp_count >= ramp_samples) { ramp_up = false; break; } } } switch_count--; if (switch_count == ramp_up_num) RampUp = true; if (switch_count == 0) current_audio_state1 = next_audio_state1; break; } if (VACDirectI_Q && !MultiPSK_server_enable && vac_enabled && !loopDLL_enabled && rb_vacIN_l != null && rb_vacIN_r != null && rb_vacOUT_l != null && rb_vacOUT_r != null) { fixed (float* outl_ptr = &(vac_outl[0])) fixed (float* outr_ptr = &(vac_outr[0])) { if (!mox) { if (sample_rateVAC == sample_rate1) { if ((rb_vacOUT_l.WriteSpace() >= frameCount) && (rb_vacOUT_r.WriteSpace() >= frameCount)) { if (vac_correct_iq) CorrectIQBuffer(in_l, in_r, vac_iq_gain, vac_iq_phase, frameCount); Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.WritePtr(in_l_ptr1, frameCount); rb_vacOUT_r.WritePtr(in_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { VACDebug("rb_vacOUT overflow inCB4"); } } else { fixed (float* res_outl_ptr = &(res_outl[0])) fixed (float* res_outr_ptr = &(res_outr[0])) { int outsamps; DttSP.DoResamplerF(in_l_ptr1, res_outl_ptr, frameCount, &outsamps, resampPtrOut_l); DttSP.DoResamplerF(in_r_ptr1, res_outr_ptr, frameCount, &outsamps, resampPtrOut_r); if ((rb_vacOUT_l.WriteSpace() >= outsamps) && (rb_vacOUT_r.WriteSpace() >= outsamps)) { if (vac_correct_iq) CorrectIQBuffer(res_outl_ptr, res_outr_ptr, vac_iq_gain, vac_iq_phase, frameCount); Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.WritePtr(res_outl_ptr, outsamps); rb_vacOUT_r.WritePtr(res_outr_ptr, outsamps); Win32.LeaveCriticalSection(cs_vac); } else { vac_rb_reset = true; VACDebug("rb_vacOUT overflow inCB4"); } } } } } } } return callback_return; } catch (Exception ex) { Debug.Write(ex.ToString()); return 0; } }
unsafe public static int NetworkServerCallbackAFSpectar(void* input, void* output, int frameCount, PA19.PaStreamCallbackTimeInfo* timeInfo, int statusFlags, void* userData) { try { int* array_ptr = (int*)input; float* in_l_ptr1 = (float*)array_ptr[0]; float* in_r_ptr1 = (float*)array_ptr[1]; int* array_out_ptr = (int*)output; float* out_l_ptr1 = (float*)array_out_ptr[0]; float* out_r_ptr1 = (float*)array_out_ptr[1]; if (wave_playback) wave_file_reader.GetPlayBuffer(in_l_ptr1, in_r_ptr1); else if ((wave_record && !mox && record_rx_preprocessed) || (wave_record && mox && record_tx_preprocessed)) wave_file_writer.AddWriteBuffer(in_l_ptr1, in_r_ptr1); else if (voice_message_record && !console.MOX) wave_file_writer.AddWriteBuffer(in_l_ptr1, in_r_ptr1); if (phase) { //phase_mutex.WaitOne(); Marshal.Copy(new IntPtr(in_l_ptr1), phase_buf_l, 0, frameCount); Marshal.Copy(new IntPtr(in_r_ptr1), phase_buf_r, 0, frameCount); //phase_mutex.ReleaseMutex(); } float* in_l = null, in_r = null, out_l = null, out_r = null; if (!mox) { if (!console.RX_IQ_channel_swap) { in_l = in_l_ptr1; in_r = in_r_ptr1; out_l = out_l_ptr1; out_r = out_r_ptr1; } else { in_l = in_r_ptr1; in_r = in_l_ptr1; out_l = out_r_ptr1; out_r = out_l_ptr1; } } else { if (voice_message_playback) voice_msg_file_reader.GetPlayBuffer(in_l_ptr1, in_r_ptr1); if (!console.TX_IQ_channel_swap) { in_r = in_l_ptr1; in_l = in_r_ptr1; out_r = out_l_ptr1; out_l = out_r_ptr1; } else { in_l = in_l_ptr1; in_r = in_r_ptr1; out_l = out_l_ptr1; out_r = out_r_ptr1; } } switch (current_audio_state1) { case AudioState.DTTSP: if (dsp_mode == DSPMode.CWU || dsp_mode == DSPMode.CWL) { DttSP.CWtoneExchange(out_l_ptr1, out_r_ptr1, frameCount); } // scale input with mic preamp if (mox && !vac_enabled && (dsp_mode == DSPMode.LSB || dsp_mode == DSPMode.USB || dsp_mode == DSPMode.DSB || dsp_mode == DSPMode.AM || dsp_mode == DSPMode.SAM || dsp_mode == DSPMode.FMN)) { ScaleBuffer(in_l, in_l, frameCount, (float)mic_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)mic_preamp); } if (vac_enabled && rb_vacIN_l != null && rb_vacIN_r != null && rb_vacOUT_l != null && rb_vacOUT_r != null) { if (mox) { if (rb_vacIN_l.ReadSpace() >= frameCount) rb_vacIN_l.ReadPtr(in_l, frameCount); else { ClearBuffer(in_l, frameCount); VACDebug("rb_vacIN underflow"); } if (rb_vacIN_r.ReadSpace() >= frameCount) rb_vacIN_r.ReadPtr(in_r, frameCount); else { ClearBuffer(in_r, frameCount); VACDebug("rb_vacIN underflow"); } ScaleBuffer(in_l, in_l, frameCount, (float)vac_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)vac_preamp); DttSP.ExchangeSamples(thread_no, in_l, in_r, out_l, out_r, frameCount); } else { DttSP.ExchangeSamples(thread_no, in_l, in_r, out_l, out_r, frameCount); if ((rb_vacIN_l.ReadSpace() >= frameCount) && (rb_vacIN_r.ReadSpace() >= frameCount)) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(in_l, frameCount); rb_vacIN_r.ReadPtr(in_r, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { ClearBuffer(in_l, frameCount); ClearBuffer(in_r, frameCount); VACDebug("rb_vacIN underflow"); VACDebug("rb_vacIN underflow"); } } } else DttSP.ExchangeSamples(thread_no, in_l, in_r, out_l, out_r, frameCount); break; case AudioState.CW: if (next_audio_state1 == AudioState.SWITCH) { Win32.memset(in_l_ptr1, 0, frameCount * sizeof(float)); Win32.memset(in_r_ptr1, 0, frameCount * sizeof(float)); DttSP.ExchangeSamples(thread_no, in_l_ptr1, in_r_ptr1, out_l_ptr1, out_r_ptr1, frameCount); if (switch_count == 0) next_audio_state1 = AudioState.CW; switch_count--; } DttSP.CWtoneExchange(out_r_ptr1, out_l_ptr1, frameCount); break; case AudioState.SINL_COSR: if (two_tone) { double dump; SineWave2Tone(out_l_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out dump, out dump); CosineWave2Tone(out_r_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); } else { SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); } break; case AudioState.SINL_SINR: if (two_tone) { SineWave2Tone(out_l_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); } else { phase_accumulator1 = SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); } break; case AudioState.SINL_NOR: if (mox) { if (two_tone) { double dump; if (console.tx_IF) { CosineWave2Tone(out_r, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + console.TX_IF_shift * 1e5, sine_freq2 + console.TX_IF_shift * 1e5, out dump, out dump); SineWave2Tone(out_l, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + console.TX_IF_shift * 1e5, sine_freq2 + console.TX_IF_shift * 1e5, out phase_accumulator1, out phase_accumulator2); } else { double osc = (console.VFOAFreq - console.LOSCFreq) * 1e6; CosineWave2Tone(out_r, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + osc, sine_freq2 + osc, out dump, out dump); SineWave2Tone(out_l, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + osc, sine_freq2 + osc, out phase_accumulator1, out phase_accumulator2); } } else { if (console.tx_IF) { CosineWave(out_r, frameCount, phase_accumulator1, sine_freq1 + console.TX_IF_shift * 1e5); phase_accumulator1 = SineWave(out_l, frameCount, phase_accumulator1, sine_freq1 + console.TX_IF_shift * 1e5); } else { double osc = (console.VFOAFreq - console.LOSCFreq) * 1e6; CosineWave(out_r, frameCount, phase_accumulator1, sine_freq1 + osc); phase_accumulator1 = SineWave(out_l, frameCount, phase_accumulator1, sine_freq1 + osc); } } float iq_gain = 1.0f + (1.0f - (1.0f + 0.001f * (float)console.SetupForm.udDSPImageGainTX.Value)); float iq_phase = 0.001f * (float)console.SetupForm.udDSPImagePhaseTX.Value; CorrectIQBuffer(out_l, out_r, iq_gain, iq_phase, frameCount); } break; case AudioState.COSL_SINR: if (two_tone) { double dump; CosineWave2Tone(out_l_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out dump, out dump); SineWave2Tone(out_r_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); } else { CosineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = SineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); } break; case AudioState.NOL_SINR: if (two_tone) { ClearBuffer(out_l_ptr1, frameCount); SineWave2Tone(out_r_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); } else { ClearBuffer(out_l_ptr1, frameCount); phase_accumulator1 = SineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); } break; case AudioState.NOL_NOR: ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); break; case AudioState.PIPE: CopyBuffer(in_l_ptr1, out_l_ptr1, frameCount); CopyBuffer(in_r_ptr1, out_r_ptr1, frameCount); break; case AudioState.SWITCH: if (!ramp_down && !ramp_up) { ClearBuffer(in_l_ptr1, frameCount); ClearBuffer(in_r_ptr1, frameCount); if (mox != next_mox) mox = next_mox; } DttSP.ExchangeSamples(thread_no, in_l_ptr1, in_r_ptr1, out_l_ptr1, out_r_ptr1, frameCount); if (ramp_down) { int i; for (i = 0; i < frameCount; i++) { float w = (float)Math.Sin(ramp_val * Math.PI / 2.0); out_l_ptr1[i] *= w; out_r_ptr1[i] *= w; ramp_val += ramp_step; if (++ramp_count >= ramp_samples) { ramp_down = false; break; } } if (ramp_down) { for (; i < frameCount; i++) { out_l_ptr1[i] = 0.0f; out_r_ptr1[i] = 0.0f; } } } else if (ramp_up) { for (int i = 0; i < frameCount; i++) { float w = (float)Math.Sin(ramp_val * Math.PI / 2.0); out_l_ptr1[i] *= w; out_r_ptr1[i] *= w; ramp_val += ramp_step; if (++ramp_count >= ramp_samples) { ramp_up = false; break; } } } else { ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); } if (next_audio_state1 == AudioState.CW) { //cw_delay = 1; DttSP.CWtoneExchange(out_l_ptr1, out_r_ptr1, frameCount); } else if (switch_count == 1) DttSP.CWRingRestart(); switch_count--; //if(switch_count == ramp_up_num) RampUp = true; if (switch_count == 0) current_audio_state1 = next_audio_state1; break; } fixed (float* res_inl_ptr = &(res_inl[0])) fixed (float* res_inr_ptr = &(res_inr[0])) { int outsamps; DttSP.DoResamplerF(out_l, res_inl_ptr, frameCount, &outsamps, resampServerPtrIn_l); // down to 6000 DttSP.DoResamplerF(out_r, res_inr_ptr, frameCount, &outsamps, resampServerPtrIn_r); byte* tmp_l_ptr = (byte*)res_inl_ptr; byte* tmp_r_ptr = (byte*)res_inr_ptr; byte[] buffer = new byte[8192]; for (int i = 2; i < buffer.Length; i++) { buffer[i] = tmp_l_ptr[0]; buffer[i + 1] = tmp_r_ptr[0]; tmp_l_ptr++; tmp_r_ptr++; i++; } CATNetwork_mutex.WaitOne(); fixed (void* rptr = &buffer[0]) fixed (void* wptr = &console.ServerSocket.send_buffer[0]) Win32.memcpy(wptr, rptr, buffer.Length); CATNetwork_mutex.WaitOne(); } console.ServerSocket.sendEvent.Set(); double vol = monitor_volume_left; if (mox) { vol = TXScale; if (high_pwr_am) { if (dsp_mode == DSPMode.AM || dsp_mode == DSPMode.SAM) vol *= 1.414; } } ScaleBuffer(out_l, out_l, frameCount, (float)vol); ScaleBuffer(out_r, out_r, frameCount, (float)vol); return 0; } catch (Exception e) { Debug.Print(e.ToString()); return -1; } }
unsafe public static int NetworkServerCallback4PortFullSpectar(void* input, void* output, int frameCount, PA19.PaStreamCallbackTimeInfo* timeInfo, int statusFlags, void* userData) { try { int* array_ptr = (int*)input; float* in_ptr = (float*)array_ptr[0]; byte* tmp_ptr = (byte*)in_ptr; byte[] buffer = new byte[frameCount * sizeof(float) * 2 + 2]; for (int i = 2; i < buffer.Length; i++) { buffer[i] = tmp_ptr[0]; tmp_ptr++; } CATNetwork_mutex.WaitOne(); // prepare for sending new data fixed (void* rptr = &buffer[0]) fixed (void* wptr = &console.ServerSocket.send_buffer[0]) Win32.memcpy(wptr, rptr, buffer.Length); CATNetwork_mutex.ReleaseMutex(); console.ServerSocket.sendEvent.Set(); return 0; } catch (Exception e) { Debug.Print(e.ToString()); return -1; } }
unsafe public static int NetworkClientCallback1(void* input, void* output, int frameCount, PA19.PaStreamCallbackTimeInfo* timeInfo, int statusFlags, void* userData) { try { if (audio_stop) return callback_return; //audio_run.WaitOne(100); double* VAC_in = (double*)input; int* out_array_ptr = (int*)output; float* out_l_ptr1 = (float*)out_array_ptr[0]; float* out_r_ptr1 = (float*)out_array_ptr[1]; byte* out_left = (byte*)out_l_ptr1; byte* out_right = (byte*)out_r_ptr1; float* tmp_input_l = stackalloc float[frameCount * sizeof(float)]; float* tmp_input_r = stackalloc float[frameCount * sizeof(float)]; float* tmp_in_l = (float*)tmp_input_l; float* tmp_in_r = (float*)tmp_input_r; byte* left = (byte*)tmp_in_l; byte* right = (byte*)tmp_in_r; if (client_rf_spectar) { CATNetwork_mutex.WaitOne(); Marshal.Copy(network_input_bufer_l, 0, new IntPtr(tmp_in_l), 8192); Marshal.Copy(network_input_bufer_r, 0, new IntPtr(tmp_in_r), 8192); CATNetwork_mutex.ReleaseMutex(); } else { for (int i = 0; i < 1024; i++) { left[0] = network_input_bufer_l[i]; right[0] = network_input_bufer_l[i + 1]; left++; right++; i++; } fixed (float* res_outr_ptr = &(res_outr[0])) fixed (float* res_outl_ptr = &(res_outl[0])) { int outsamps; DttSP.DoResamplerF(tmp_in_l, res_outl_ptr, frameCount, &outsamps, resampPtrOut_l); DttSP.DoResamplerF(tmp_in_r, res_outr_ptr, frameCount, &outsamps, resampPtrOut_r); tmp_in_l = res_outl_ptr; tmp_in_r = res_outr_ptr; } } if (wave_playback) { tmp_in_l = (float*)tmp_input_l; tmp_in_r = (float*)tmp_input_r; wave_file_reader.GetPlayBuffer(tmp_in_l, tmp_in_r); } else if ((wave_record && !mox && record_rx_preprocessed) || (wave_record && mox && record_tx_preprocessed)) { tmp_in_l = (float*)tmp_input_l; tmp_in_r = (float*)tmp_input_r; wave_file_writer.AddWriteBuffer(tmp_in_l, tmp_in_r); } else if (voice_message_record && !console.MOX) { tmp_in_l = (float*)tmp_input_l; tmp_in_r = (float*)tmp_input_r; wave_file_writer.AddWriteBuffer(tmp_in_l, tmp_in_r); } if (phase) { //phase_mutex.WaitOne(); Marshal.Copy(new IntPtr(tmp_in_l), phase_buf_l, 0, frameCount); Marshal.Copy(new IntPtr(tmp_in_r), phase_buf_r, 0, frameCount); //phase_mutex.ReleaseMutex(); } float* in_l = null, in_r = null, out_l = null, out_r = null, in_l_VAC = null, in_r_VAC = null; if (!console.RX_IQ_channel_swap) { in_l = (float*)tmp_in_l; in_r = (float*)tmp_in_r; out_l = out_l_ptr1; out_r = out_r_ptr1; } else { in_l = (float*)tmp_in_r; in_r = (float*)tmp_in_l; out_l = out_r_ptr1; out_r = out_l_ptr1; } if (vac_enabled && loopDLL_enabled && mox) { int i; in_l_VAC = in_l; // save pointer in_r_VAC = in_r; // save pointer fixed (double* loopDLL_inl_ptr = &(loopDLL_inl[0])) { if (console.loopDLL.ReadTXBuffer(loopDLL_inl_ptr)) { for (i = 0; i < frameCount; i++) { in_l[0] = (float)(loopDLL_inl[i] / 1e4); in_r[0] = (float)(loopDLL_inl[i] / 1e4); in_l++; in_r++; } } else { } } in_l = in_l_VAC; // restore pointer in_r = in_r_VAC; // restore pointer } switch (current_audio_state1) { case AudioState.DTTSP: if (dsp_mode == DSPMode.CWU || dsp_mode == DSPMode.CWL) { DttSP.CWtoneExchange(out_l_ptr1, out_r_ptr1, frameCount); } // scale input with mic preamp if (mox && !vac_enabled && (dsp_mode == DSPMode.LSB || dsp_mode == DSPMode.USB || dsp_mode == DSPMode.DSB || dsp_mode == DSPMode.AM || dsp_mode == DSPMode.SAM || dsp_mode == DSPMode.FMN)) { if (wave_playback) { ScaleBuffer(in_l, in_l, frameCount, (float)wave_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)wave_preamp); } else { ScaleBuffer(in_l, in_l, frameCount, (float)mic_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)mic_preamp); } } #region Input Signal Source switch (current_input_signal) { case SignalSource.SOUNDCARD: break; case SignalSource.SINE: SineWave(in_l, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(in_r, frameCount, phase_accumulator1, sine_freq1); ScaleBuffer(in_l, in_l, frameCount, (float)input_source_scale); ScaleBuffer(in_r, in_r, frameCount, (float)input_source_scale); break; case SignalSource.NOISE: Noise(in_l, frameCount); Noise(in_r, frameCount); break; case SignalSource.TRIANGLE: Triangle(in_l, frameCount, sine_freq1); CopyBuffer(in_l, in_r, frameCount); break; case SignalSource.SAWTOOTH: Sawtooth(in_l, frameCount, sine_freq1); CopyBuffer(in_l, in_r, frameCount); break; } #endregion if (vac_enabled && rb_vacIN_l != null && rb_vacIN_r != null && rb_vacOUT_l != null && rb_vacOUT_r != null) { if (mox) { if (rb_vacIN_l.ReadSpace() >= frameCount) rb_vacIN_l.ReadPtr(in_l, frameCount); else { ClearBuffer(in_l, frameCount); VACDebug("rb_vacIN underflow"); } if (rb_vacIN_r.ReadSpace() >= frameCount) rb_vacIN_r.ReadPtr(in_r, frameCount); else { ClearBuffer(in_r, frameCount); VACDebug("rb_vacIN underflow"); } ScaleBuffer(in_l, in_l, frameCount, (float)vac_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)vac_preamp); DttSP.ExchangeSamples(thread_no, in_l, in_r, out_l, out_r, frameCount); } else { DttSP.ExchangeSamples(thread_no, in_l, in_r, out_l, out_r, frameCount); if ((rb_vacIN_l.ReadSpace() >= frameCount) && (rb_vacIN_r.ReadSpace() >= frameCount)) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(in_l, frameCount); rb_vacIN_r.ReadPtr(in_r, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { ClearBuffer(in_l, frameCount); ClearBuffer(in_r, frameCount); VACDebug("rb_vacIN underflow"); } } } else DttSP.ExchangeSamples(thread_no, in_l, in_r, out_l, out_r, frameCount); #region Output Signal Source switch (current_output_signal) { case SignalSource.SOUNDCARD: break; case SignalSource.SINE: SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); break; case SignalSource.NOISE: Noise(out_l_ptr1, frameCount); Noise(out_r_ptr1, frameCount); break; case SignalSource.TRIANGLE: Triangle(out_l_ptr1, frameCount, sine_freq1); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); break; case SignalSource.SAWTOOTH: Sawtooth(out_l_ptr1, frameCount, sine_freq1); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); break; } #endregion break; case AudioState.CW: if (next_audio_state1 == AudioState.SWITCH) { Win32.memset(tmp_in_l, 0, frameCount * sizeof(float)); Win32.memset(tmp_in_r, 0, frameCount * sizeof(float)); if (vac_enabled) { if ((rb_vacIN_l.ReadSpace() >= frameCount) && (rb_vacIN_r.ReadSpace() >= frameCount)) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(tmp_in_l, frameCount); rb_vacIN_r.ReadPtr(tmp_in_r, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { VACDebug("rb_vacIN underflow switch time!"); } } DttSP.ExchangeSamples(thread_no, tmp_in_l, tmp_in_r, out_l_ptr1, out_r_ptr1, frameCount); if (switch_count == 0) next_audio_state1 = AudioState.CW; switch_count--; } DttSP.CWtoneExchange(out_r_ptr1, out_l_ptr1, frameCount); break; case AudioState.SINL_COSR: if (two_tone) { double dump; SineWave2Tone(out_l_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out dump, out dump); CosineWave2Tone(out_r_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); } else { SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); } break; case AudioState.SINL_SINR: if (two_tone) { SineWave2Tone(out_l_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); } else { phase_accumulator1 = SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); } break; case AudioState.SINL_NOR: if (two_tone) { SineWave2Tone(out_l_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); ClearBuffer(out_r_ptr1, frameCount); } else { phase_accumulator1 = SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); ClearBuffer(out_r_ptr1, frameCount); } break; case AudioState.CW_COSL_SINR: if (mox) { if (two_tone) { double dump; if (console.tx_IF) { CosineWave2Tone(out_r, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + console.TX_IF_shift * 1e5, sine_freq2 + console.TX_IF_shift * 1e5, out dump, out dump); SineWave2Tone(out_l, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + console.TX_IF_shift * 1e5, sine_freq2 + console.TX_IF_shift * 1e5, out phase_accumulator1, out phase_accumulator2); } else { double osc = (console.VFOAFreq - console.LOSCFreq) * 1e6; CosineWave2Tone(out_r, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + osc, sine_freq2 + osc, out dump, out dump); SineWave2Tone(out_l, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + osc, sine_freq2 + osc, out phase_accumulator1, out phase_accumulator2); } } else { if (console.tx_IF) { CosineWave(out_r, frameCount, phase_accumulator1, sine_freq1 + console.TX_IF_shift * 1e5); phase_accumulator1 = SineWave(out_l, frameCount, phase_accumulator1, sine_freq1 + console.TX_IF_shift * 1e5); } else { double osc = (console.VFOAFreq - console.LOSCFreq) * 1e6; CosineWave(out_r, frameCount, phase_accumulator1, sine_freq1 + osc); phase_accumulator1 = SineWave(out_l, frameCount, phase_accumulator1, sine_freq1 + osc); } } float iq_gain = 1.0f + (1.0f - (1.0f + 0.001f * (float)console.SetupForm.udDSPImageGainTX.Value)); float iq_phase = 0.001f * (float)console.SetupForm.udDSPImagePhaseTX.Value; CorrectIQBuffer(out_l, out_r, iq_gain, iq_phase, frameCount); } break; case AudioState.COSL_SINR: if (two_tone) { double dump; CosineWave2Tone(out_l_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out dump, out dump); SineWave2Tone(out_r_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); } else { CosineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = SineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); } break; case AudioState.NOL_SINR: if (two_tone) { ClearBuffer(out_l_ptr1, frameCount); SineWave2Tone(out_r_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); } else { ClearBuffer(out_l_ptr1, frameCount); phase_accumulator1 = SineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); } break; case AudioState.NOL_NOR: ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); break; case AudioState.PIPE: CopyBuffer(tmp_in_l, out_l_ptr1, frameCount); CopyBuffer(tmp_in_r, out_r_ptr1, frameCount); break; case AudioState.SWITCH: if (!ramp_down && !ramp_up) { ClearBuffer(tmp_in_l, frameCount); ClearBuffer(tmp_in_r, frameCount); if (mox != next_mox) mox = next_mox; } if (vac_enabled) { if ((rb_vacIN_l.ReadSpace() >= frameCount) && (rb_vacIN_r.ReadSpace() >= frameCount)) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(tmp_in_l, frameCount); rb_vacIN_r.ReadPtr(tmp_in_r, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { VACDebug("rb_vacIN underflow switch time!"); } } DttSP.ExchangeSamples(thread_no, tmp_in_l, tmp_in_r, out_l_ptr1, out_r_ptr1, frameCount); if (ramp_down) { int i; for (i = 0; i < frameCount; i++) { float w = (float)Math.Sin(ramp_val * Math.PI / 2.0); out_l_ptr1[i] *= w; out_r_ptr1[i] *= w; ramp_val += ramp_step; if (++ramp_count >= ramp_samples) { ramp_down = false; break; } } if (ramp_down) { for (; i < frameCount; i++) { out_l_ptr1[i] = 0.0f; out_r_ptr1[i] = 0.0f; } } } else if (ramp_up) { for (int i = 0; i < frameCount; i++) { float w = (float)Math.Sin(ramp_val * Math.PI / 2.0); out_l_ptr1[i] *= w; out_r_ptr1[i] *= w; ramp_val += ramp_step; if (++ramp_count >= ramp_samples) { ramp_up = false; break; } } } else { ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); } if (next_audio_state1 == AudioState.CW) { //cw_delay = 1; DttSP.CWtoneExchange(out_l_ptr1, out_r_ptr1, frameCount); } else if (switch_count == 1) DttSP.CWRingRestart(); switch_count--; //if(switch_count == ramp_up_num) RampUp = true; if (switch_count == 0) current_audio_state1 = next_audio_state1; break; } double vol = monitor_volume_left; if (mox) { vol = TXScale; if (high_pwr_am) { if (dsp_mode == DSPMode.AM || dsp_mode == DSPMode.SAM) vol *= 1.414; } } if ((wave_record && !mox && !record_rx_preprocessed) || // post process audio (wave_record && mox && !record_tx_preprocessed)) wave_file_writer.AddWriteBuffer(out_l_ptr1, out_r_ptr1); if (VACPrimaryAudiodevice && !mox && current_audio_state1 == AudioState.DTTSP && !loopDLL_enabled) { ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); } if (loopDLL_enabled && vac_enabled && !mox) // rx { int i; double[] buffer = new double[frameCount]; fixed (double* buffer_ptr = &(buffer[0])) fixed (float* res_outl_ptr = &(res_outl[0])) { ScaleBuffer(out_l, res_outl_ptr, frameCount, (float)vol); ScaleBuffer(out_l, out_l, frameCount, 0.0f); ScaleBuffer(out_r, out_r, frameCount, 0.0f); { for (i = 0; i < frameCount; i++) { buffer[i] = (double)1e5 * res_outl[i]; } console.loopDLL.WriteRXBuffer(buffer_ptr); } } } else if (loopDLL_enabled && vac_enabled && mox) // tx { ScaleBuffer(out_l, out_l, frameCount, (float)vol); ScaleBuffer(out_r, out_r, frameCount, (float)vol); fixed (float* res_inl_ptr = &(res_inl[0])) fixed (float* res_inr_ptr = &(res_inr[0])) { int outsamps; DttSP.DoResamplerF(out_l, res_inl_ptr, frameCount, &outsamps, resampServerPtrIn_l); // down to 6000 DttSP.DoResamplerF(out_r, res_inr_ptr, frameCount, &outsamps, resampServerPtrIn_r); byte* tmp_l_ptr = (byte*)res_inl_ptr; byte* tmp_r_ptr = (byte*)res_inr_ptr; byte[] buffer = new byte[8192]; for (int i = 2; i < buffer.Length; i++) { buffer[i] = tmp_l_ptr[0]; buffer[i + 1] = tmp_r_ptr[0]; tmp_l_ptr++; tmp_r_ptr++; i++; } CATNetwork_mutex.WaitOne(); fixed (void* rptr = &buffer[0]) fixed (void* wptr = &console.ClientSocket.send_buffer[0]) Win32.memcpy(wptr, rptr, buffer.Length); CATNetwork_mutex.WaitOne(); } console.ClientSocket.sendEvent.Set(); } else { ScaleBuffer(out_l, out_l, frameCount, (float)vol); ScaleBuffer(out_r, out_r, frameCount, (float)vol); } //audio_run.ReleaseMutex(); return callback_return; } catch (Exception ex) { CATNetwork_mutex.ReleaseMutex(); //audio_run.ReleaseMutex(); Debug.Write(ex.ToString()); return 0; } }
unsafe public static int CallbackVAC(void* input, void* output, int frameCount, // changes yt7pwr PA19.PaStreamCallbackTimeInfo* timeInfo, int statusFlags, void* userData) { try { if (audio_stop) return callback_return; #if(WIN64) Int64* array_ptr = (Int64*)input; float* in_l_ptr1 = (float*)array_ptr[0]; float* in_r_ptr1 = (float*)array_ptr[1]; array_ptr = (Int64*)output; float* out_l_ptr1 = (float*)array_ptr[0]; float* out_r_ptr1 = (float*)array_ptr[1]; #endif #if(WIN32) int* array_ptr = (int*)input; float* in_l_ptr1 = (float*)array_ptr[0]; float* in_r_ptr1 = null; if (console.SetupForm.VACchNumber == 1) // mono in_r_ptr1 = (float*)array_ptr[0]; else in_r_ptr1 = (float*)array_ptr[1]; // stereo array_ptr = (int*)output; float* out_l_ptr1 = (float*)array_ptr[0]; float* out_r_ptr1 = null; if (console.SetupForm.VACchNumber == 1) // mono out_r_ptr1 = (float*)array_ptr[0]; else out_r_ptr1 = (float*)array_ptr[1]; // stereo #endif if (vac_rb_reset) { vac_rb_reset = false; ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.Reset(); rb_vacIN_r.Reset(); rb_vacOUT_l.Reset(); rb_vacOUT_r.Reset(); Win32.LeaveCriticalSection(cs_vac); return 0; } #region VOX if (vox_enabled) { float* vox_l = null, vox_r = null; vox_l = in_l_ptr1; vox_r = in_r_ptr1; if (dsp_mode == DSPMode.LSB || dsp_mode == DSPMode.USB || dsp_mode == DSPMode.DSB || dsp_mode == DSPMode.AM || dsp_mode == DSPMode.SAM || dsp_mode == DSPMode.FMN) { Peak = MaxSample(vox_l, vox_r, frameCount); // compare power to threshold if (Peak > vox_threshold) vox_active = true; else vox_active = false; } } #endregion if (mox || voice_message_record) { if (vac_resample) { if (dsp_mode == DSPMode.CWU || dsp_mode == DSPMode.CWL) { if ((rb_vacOUT_l.ReadSpace() >= frameCount) && (rb_vacOUT_r.ReadSpace() >= frameCount)) { Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.ReadPtr(out_l_ptr1, frameCount); rb_vacOUT_r.ReadPtr(out_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { VACDebug("rb_vacIN underflow CBvac"); } ScaleBuffer(out_l_ptr1, out_l_ptr1, frameCount, (float)vac_rx_scale); ScaleBuffer(out_r_ptr1, out_r_ptr1, frameCount, (float)vac_rx_scale); } else { int outsamps; fixed (float* res_inl_ptr = &(res_inl[0])) fixed (float* res_inr_ptr = &(res_inr[0])) { DttSP.DoResamplerF(in_l_ptr1, res_inl_ptr, frameCount, &outsamps, resampPtrIn_l); DttSP.DoResamplerF(in_r_ptr1, res_inr_ptr, frameCount, &outsamps, resampPtrIn_r); if ((rb_vacIN_l.WriteSpace() >= outsamps) && (rb_vacIN_r.WriteSpace() >= outsamps)) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.WritePtr(res_inl_ptr, outsamps); rb_vacIN_r.WritePtr(res_inr_ptr, outsamps); Win32.LeaveCriticalSection(cs_vac); if (vac_primary_audiodev && (wave_record && record_tx_preprocessed)) wave_file_writer.AddWriteBuffer(res_inl_ptr, res_inr_ptr); } else { VACDebug("rb_vacIN overflow CBvac"); } if (vac_mon && mon) { ScaleBuffer(in_l_ptr1, out_l_ptr1, frameCount, (float)vac_rx_scale); ScaleBuffer(in_r_ptr1, out_r_ptr1, frameCount, (float)vac_rx_scale); } } } } else { if ((dsp_mode == DSPMode.CWU || dsp_mode == DSPMode.CWL) && vac_mon) { DttSP.CWMonitorExchange(out_l_ptr1, out_r_ptr1, frameCount); } else if (dsp_mode != DSPMode.CWU && dsp_mode != DSPMode.CWL) { if ((rb_vacIN_l.WriteSpace() >= frameCount) && (rb_vacIN_r.WriteSpace() >= frameCount)) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.WritePtr(in_l_ptr1, frameCount); rb_vacIN_r.WritePtr(in_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); if (vac_primary_audiodev && (wave_record && record_tx_preprocessed)) wave_file_writer.AddWriteBuffer(in_l_ptr1, in_r_ptr1); } else { VACDebug("rb_vacIN overflow CBvac"); } if (vac_mon && mon) { ScaleBuffer(in_l_ptr1, out_l_ptr1, frameCount, (float)vac_rx_scale); ScaleBuffer(in_r_ptr1, out_r_ptr1, frameCount, (float)vac_rx_scale); } } } } else { if (console.CurrentModel == Model.GENESIS_G6) { if ((rb_vacOUT_l.ReadSpace() >= frameCount) && (rb_vacOUT_r.ReadSpace() >= frameCount)) { Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.ReadPtr(out_l_ptr1, frameCount); rb_vacOUT_r.ReadPtr(out_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { //VACDebug(" underflow CBvac G6"); Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.ReadPtr(out_l_ptr1, frameCount); rb_vacOUT_r.ReadPtr(out_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); } if (wave_record && !record_rx_preprocessed && vac_primary_audiodev) wave_file_writer.AddWriteBuffer(out_l_ptr1, out_r_ptr1); } else { //if ((rb_vacOUT_l.ReadSpace() >= frameCount)) { Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.ReadPtr(out_l_ptr1, frameCount); rb_vacOUT_r.ReadPtr(out_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); if (wave_record && !record_rx_preprocessed && vac_primary_audiodev) wave_file_writer.AddWriteBuffer(out_l_ptr1, out_r_ptr1); } /*else { ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); VACDebug("rb_vacOUT underflow CBvac"); }*/ } } if (VACPrimaryAudiodevice && mox && !mon && !VACDirectI_Q) { ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); } if (wave_record && !record_tx_preprocessed && vac_primary_audiodev) wave_file_writer.AddWriteBuffer(out_l_ptr1, out_r_ptr1); double vol_l = vac_volume_left; double vol_r = vac_volume_right; if (!vac_primary_audiodev) { vol_l = console.AF / 100.0; vol_r = console.AF / 100.0; } if (Audio.VACDirectI_Q && !mox) { ScaleBuffer(out_l_ptr1, out_l_ptr1, frameCount, (float)vac_rx_scale); // RX gain ScaleBuffer(out_r_ptr1, out_r_ptr1, frameCount, (float)vac_rx_scale); } else { switch (vac_mute_ch) { case MuteChannels.Left: ScaleBuffer(out_r_ptr1, out_r_ptr1, frameCount, (float)vol_r); ScaleBuffer(out_r_ptr1, out_l_ptr1, frameCount, 1.0f); break; case MuteChannels.Right: { ScaleBuffer(out_l_ptr1, out_l_ptr1, frameCount, (float)vol_l); ScaleBuffer(out_l_ptr1, out_r_ptr1, frameCount, 1.0f); } break; case MuteChannels.Both: { ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); } break; case MuteChannels.None: { ScaleBuffer(out_l_ptr1, out_l_ptr1, frameCount, (float)vol_l); ScaleBuffer(out_r_ptr1, out_r_ptr1, frameCount, (float)vol_r); } break; } if (console.CurrentModel == Model.GENESIS_G6) { if (console.CurrentDisplayMode == DisplayMode.SCOPE || console.CurrentDisplayMode == DisplayMode.PANASCOPE) DoScope(out_l_ptr1, frameCount); } } return VAC_callback_return; } catch (Exception ex) { Debug.Write(ex.ToString()); return 0; } }
unsafe public static int Callback4Port(void* input, void* output, int frameCount, // changes yt7pwr PA19.PaStreamCallbackTimeInfo* timeInfo, int statusFlags, void* userData) { try { if (audio_stop) return callback_return; //audio_run.WaitOne(100); #if(WIN64) Int64* array_ptr = (Int64*)input; float* in_l_ptr1 = (float*)array_ptr[0]; float* in_r_ptr1 = (float*)array_ptr[1]; float* in_l_ptr2 = (float*)array_ptr[2]; float* in_r_ptr2 = (float*)array_ptr[3]; array_ptr = (Int64*)output; float* out_l_ptr1 = (float*)array_ptr[0]; float* out_r_ptr1 = (float*)array_ptr[1]; float* out_l_ptr2 = (float*)array_ptr[2]; float* out_r_ptr2 = (float*)array_ptr[3]; #endif #if(WIN32) int* array_ptr = (int*)input; float* in_l_ptr1 = (float*)array_ptr[0]; float* in_r_ptr1 = (float*)array_ptr[1]; float* in_l_ptr2 = (float*)array_ptr[2]; float* in_r_ptr2 = (float*)array_ptr[3]; array_ptr = (int*)output; float* out_l_ptr1 = (float*)array_ptr[0]; float* out_r_ptr1 = (float*)array_ptr[1]; float* out_l_ptr2 = (float*)array_ptr[2]; float* out_r_ptr2 = (float*)array_ptr[3]; #endif float* in_l = null, in_l_VAC = null, in_r = null, in_r_VAC = null; float* out_l1 = null, out_r1 = null, out_l2 = null, out_r2 = null; out_l1 = out_l_ptr1; out_r1 = out_r_ptr1; out_l2 = out_l_ptr2; out_r2 = out_r_ptr2; if (!mox && !voice_message_record) // rx { if (RX_input_1_2) { if (!console.RX_IQ_channel_swap) { in_l = in_l_ptr1; in_r = in_r_ptr1; } else { in_r = in_l_ptr1; in_l = in_r_ptr1; } } else { if (!console.RX_IQ_channel_swap) { in_l = in_l_ptr2; in_r = in_r_ptr2; } else { in_r = in_l_ptr2; in_l = in_r_ptr2; } } } else if (mox || voice_message_record) // tx or voice msg recording { if (console.LineMicShared) { if (RX_input_1_2) { in_l = in_l_ptr1; in_r = in_r_ptr1; } else { in_l = in_l_ptr2; in_r = in_r_ptr2; } } else { if (RX_input_1_2) { in_l = in_l_ptr2; in_r = in_r_ptr2; } else { in_l = in_l_ptr1; in_r = in_r_ptr1; } } if (console.TX_IQ_channel_swap) { if (TX_out_1_2) { out_l1 = out_r_ptr1; out_r1 = out_l_ptr1; out_l2 = out_r_ptr2; out_r2 = out_l_ptr2; } else { out_l1 = out_r_ptr2; out_r1 = out_l_ptr2; out_l2 = out_r_ptr1; out_r2 = out_l_ptr1; } } else { if (TX_out_1_2) { out_l1 = out_l_ptr1; out_r1 = out_r_ptr1; out_l2 = out_l_ptr2; out_r2 = out_r_ptr2; } else { out_l1 = out_l_ptr2; out_r1 = out_r_ptr2; out_l2 = out_l_ptr1; out_r2 = out_r_ptr1; } } } if (voice_message_playback) // yt7pwr voice_msg_file_reader.GetPlayBuffer(in_l, in_r); if (wave_playback) wave_file_reader.GetPlayBuffer(in_l, in_r); if (voice_message_record) // yt7pwr { try { if (vac_enabled) { if (rb_vacIN_l.ReadSpace() >= frameCount && rb_vacIN_r.ReadSpace() >= frameCount) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(in_l_ptr1, frameCount); rb_vacIN_r.ReadPtr(in_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { ClearBuffer(in_l_ptr1, frameCount); ClearBuffer(in_r_ptr1, frameCount); VACDebug("rb_vacIN underflow VoiceMsg record"); } } ScaleBuffer(in_l, in_l, frameCount, (float)mic_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)mic_preamp); voice_msg_file_writer.AddWriteBuffer(in_l, in_r); } catch (Exception ex) { VACDebug("Audio: " + ex.ToString()); } } if (wave_record && !vac_primary_audiodev && !mox && record_rx_preprocessed || (wave_record && !vac_primary_audiodev && mox && record_tx_preprocessed)) wave_file_writer.AddWriteBuffer(in_l, in_r); if (phase) { //phase_mutex.WaitOne(); Marshal.Copy(new IntPtr(in_l), phase_buf_l, 0, frameCount); Marshal.Copy(new IntPtr(in_r), phase_buf_r, 0, frameCount); //phase_mutex.ReleaseMutex(); } if (!MultiPSK_server_enable && vac_enabled && loopDLL_enabled && mox) { int i; in_l_VAC = in_l; // save pointer in_r_VAC = in_r; // save pointer fixed (double* loopDLL_inl_ptr = &(loopDLL_inl[0])) { try { if (console.loopDLL.ReadTXBuffer(loopDLL_inl_ptr)) { for (i = 0; i < frameCount; i++) { in_l[0] = (float)(loopDLL_inl[i] / 1e5); in_r[0] = 0.0f; // (float)(loopDLL_inl[i] / 1e5); in_l++; in_r++; } } else { } } catch (Exception ex) { console.chkPower.Checked = false; Thread.Sleep(100); MessageBox.Show("loop.dll error!Check your PATH settings!\n" + ex.ToString()); } } in_l = in_l_VAC; // restore pointer in_r = in_r_VAC; // restore pointer } else if (mox && MultiPSK_server_enable && console.MultiPSKServer.ClientConnected) { float* tmp_l = in_l; float* tmp_r = in_r; for (int i = 0; i < frameCount; i++) { in_l[0] = MultiPSK_output_bufer_l[i]; in_r[0] = 0.0f; // MultiPSK_output_bufer_l[i]; in_l++; in_r++; // i++; } in_l = tmp_l; in_r = tmp_r; } switch (current_audio_state1) { case AudioState.DTTSP: #region VOX float* vox_l = null, vox_r = null; if (vox_enabled && !vac_enabled) { switch (soundcard) { case SoundCard.FIREBOX: case SoundCard.EDIROL_FA_66: vox_l = in_l_ptr1; vox_r = in_r_ptr1; break; case SoundCard.DELTA_44: default: vox_l = in_l_ptr2; vox_r = in_r_ptr2; break; } if (dsp_mode == DSPMode.LSB || dsp_mode == DSPMode.USB || dsp_mode == DSPMode.DSB || dsp_mode == DSPMode.AM || dsp_mode == DSPMode.SAM || dsp_mode == DSPMode.FMN) { ScaleBuffer(vox_l, vox_l, frameCount, (float)mic_preamp); ScaleBuffer(vox_r, vox_r, frameCount, (float)mic_preamp); Peak = MaxSample(vox_l, vox_r, frameCount); // compare power to threshold if (Peak > vox_threshold) vox_active = true; else vox_active = false; } } else if (vox_enabled && vac_enabled) { if ((rb_vacIN_l.WriteSpace() >= frameCount) && (rb_vacIN_r.WriteSpace() >= frameCount)) { if (mox) { vox_l = in_l; vox_r = in_r; Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(in_l, frameCount); rb_vacIN_r.ReadPtr(in_r, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { fixed (float* vac_inl_ptr = &(vac_inl[0])) fixed (float* vac_inr_ptr = &(vac_inr[0])) { vox_l = vac_inl_ptr; vox_r = vac_inr_ptr; Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(vac_inl_ptr, frameCount); rb_vacIN_r.ReadPtr(vac_inr_ptr, frameCount); Win32.LeaveCriticalSection(cs_vac); } } } if (dsp_mode == DSPMode.LSB || dsp_mode == DSPMode.USB || dsp_mode == DSPMode.DSB || dsp_mode == DSPMode.AM || dsp_mode == DSPMode.SAM || dsp_mode == DSPMode.FMN) { Peak = MaxSample(vox_l, vox_r, frameCount); // compare power to threshold if (Peak > vox_threshold) vox_active = true; else vox_active = false; } } #endregion if (dsp_mode == DSPMode.CWU || dsp_mode == DSPMode.CWL) { DttSP.CWtoneExchange(out_l1, out_r1, frameCount); } // scale input with mic preamp if ((mox || voice_message_record) && !vac_enabled && (dsp_mode == DSPMode.LSB || dsp_mode == DSPMode.USB || dsp_mode == DSPMode.DSB || dsp_mode == DSPMode.AM || dsp_mode == DSPMode.SAM || dsp_mode == DSPMode.FMN)) { if (wave_playback) { ScaleBuffer(in_l, in_l, frameCount, (float)wave_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)wave_preamp); } else { ScaleBuffer(in_l, in_l, frameCount, (float)mic_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)mic_preamp); } if (echo_enable && (dsp_mode != DSPMode.DIGL || dsp_mode != DSPMode.DIGU)) { if (!echo_pause) { echoRB.WritePtr(in_l, frameCount); if (echoRB.ReadSpace() >= echo_delay - 2) { EchoMixer(in_l, in_r, frameCount); } } } } #region Input Signal Source switch (current_input_signal) { case SignalSource.SOUNDCARD: break; case SignalSource.SINE: SineWave(in_l, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(in_r, frameCount, phase_accumulator1, sine_freq1); ScaleBuffer(in_l, in_l, frameCount, (float)input_source_scale); ScaleBuffer(in_r, in_r, frameCount, (float)input_source_scale); break; case SignalSource.NOISE: Noise(in_l, frameCount); Noise(in_r, frameCount); break; case SignalSource.TRIANGLE: Triangle(in_l, frameCount, sine_freq1); CopyBuffer(in_l, in_r, frameCount); break; case SignalSource.SAWTOOTH: Sawtooth(in_l, frameCount, sine_freq1); CopyBuffer(in_l, in_r, frameCount); break; } #endregion if (!loopDLL_enabled && vac_enabled && !voice_message_playback && rb_vacIN_l != null && rb_vacIN_r != null && rb_vacOUT_l != null && rb_vacOUT_r != null) { if (mox) // transmit mode { if (rb_vacIN_l.ReadSpace() >= frameCount) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(in_l, frameCount); rb_vacIN_r.ReadPtr(in_r, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { ClearBuffer(in_l, frameCount); ClearBuffer(in_r, frameCount); VACDebug("rb_vacIN underflow switch time Cb4!"); } ScaleBuffer(in_l, in_l, frameCount, (float)vac_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)vac_preamp); if (echo_enable && (dsp_mode != DSPMode.DIGL || dsp_mode != DSPMode.DIGU)) { if (!echo_pause) { echoRB.WritePtr(in_l, frameCount); if (echoRB.ReadSpace() > echo_delay - 2) { EchoMixer(in_l, in_r, frameCount); } } } } } else if (loopDLL_enabled && vac_enabled && mox) { ScaleBuffer(in_l, in_l, frameCount, (float)vac_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)vac_preamp); } DttSP.ExchangeSamples(thread_no, in_l, in_r, out_l1, out_r1, frameCount); #region Output Signal Source switch (current_output_signal) { case SignalSource.SOUNDCARD: break; case SignalSource.SINE: switch (ChannelTest) { case TestChannels.Left: SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); break; case TestChannels.Right: SineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); break; case TestChannels.Both: SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); SineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator2 = CosineWave(out_r_ptr1, frameCount, phase_accumulator2, sine_freq1); break; } break; case SignalSource.NOISE: switch (ChannelTest) { case TestChannels.Both: Noise(out_l_ptr1, frameCount); Noise(out_r_ptr1, frameCount); break; case TestChannels.Left: Noise(out_l_ptr1, frameCount); break; case TestChannels.Right: Noise(out_r_ptr1, frameCount); break; } break; case SignalSource.TRIANGLE: switch (ChannelTest) { case TestChannels.Both: Triangle(out_l_ptr1, frameCount, sine_freq1); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); break; case TestChannels.Left: Triangle(out_l_ptr1, frameCount, sine_freq1); break; case TestChannels.Right: Triangle(out_r_ptr1, frameCount, sine_freq1); break; } break; case SignalSource.SAWTOOTH: switch (ChannelTest) { case TestChannels.Both: Sawtooth(out_l_ptr1, frameCount, sine_freq1); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); break; case TestChannels.Left: Sawtooth(out_l_ptr1, frameCount, sine_freq1); break; case TestChannels.Right: Sawtooth(out_r_ptr1, frameCount, sine_freq1); break; } break; } #endregion break; case AudioState.CW: if (next_audio_state1 == AudioState.SWITCH) { ClearBuffer(in_l, frameCount); ClearBuffer(in_r, frameCount); if (vac_enabled) { if ((rb_vacIN_l.ReadSpace() >= frameCount) && (rb_vacIN_r.ReadSpace() >= frameCount)) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(in_l_ptr1, frameCount); rb_vacIN_r.ReadPtr(in_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { VACDebug("rb_vacIN underflow switch time CB4!"); } } DttSP.CWtoneExchange(out_l1, out_r1, frameCount); ClearBuffer(out_l1, frameCount); ClearBuffer(out_r1, frameCount); if (switch_count == 0) next_audio_state1 = AudioState.CW; switch_count--; } else { DttSP.CWtoneExchange(out_l1, out_r1, frameCount); } break; case AudioState.SINL_COSR: out_l1 = out_l_ptr1; out_r1 = out_r_ptr1; out_l2 = out_l_ptr2; out_r2 = out_r_ptr2; if (two_tone) { double dump; SineWave2Tone(out_l1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out dump, out dump); CosineWave2Tone(out_r1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); } else { SineWave(out_l2, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(out_r2, frameCount, phase_accumulator1, sine_freq1); } break; case AudioState.SINL_SINR: out_l1 = out_l_ptr1; out_r1 = out_r_ptr1; out_l2 = out_l_ptr2; out_r2 = out_r_ptr2; if (two_tone) { SineWave2Tone(out_l1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); CopyBuffer(out_l1, out_r1, frameCount); } else { phase_accumulator1 = SineWave(out_l1, frameCount, phase_accumulator1, sine_freq1); CopyBuffer(out_l1, out_r1, frameCount); } break; case AudioState.SINL_NOR: out_l1 = out_l_ptr1; out_r1 = out_r_ptr1; out_l2 = out_l_ptr2; out_r2 = out_r_ptr2; if (two_tone) { SineWave2Tone(out_l1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); ClearBuffer(out_r1, frameCount); } else { phase_accumulator1 = SineWave(out_l1, frameCount, phase_accumulator1, sine_freq1); ClearBuffer(out_r1, frameCount); } break; case AudioState.CW_COSL_SINR: if (mox) { if (two_tone) { double dump; if (console.tx_IF) { CosineWave2Tone(out_r1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + console.TX_IF_shift * 1e5, sine_freq2 + console.TX_IF_shift * 1e5, out dump, out dump); SineWave2Tone(out_l1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + console.TX_IF_shift * 1e5, sine_freq2 + console.TX_IF_shift * 1e5, out phase_accumulator1, out phase_accumulator2); } else { double osc = (console.VFOAFreq - console.LOSCFreq) * 1e6; CosineWave2Tone(out_r1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + osc, sine_freq2 + osc, out dump, out dump); SineWave2Tone(out_l1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + osc, sine_freq2 + osc, out phase_accumulator1, out phase_accumulator2); } } else { if (console.tx_IF) { CosineWave(out_r1, frameCount, phase_accumulator1, sine_freq1 + console.TX_IF_shift * 1e5); phase_accumulator1 = SineWave(out_l1, frameCount, phase_accumulator1, sine_freq1 + console.TX_IF_shift * 1e5); } else { double osc = (console.VFOAFreq - console.LOSCFreq) * 1e6; CosineWave(out_r1, frameCount, phase_accumulator1, sine_freq1 + osc); phase_accumulator1 = SineWave(out_l1, frameCount, phase_accumulator1, sine_freq1 + osc); } } float iq_gain = 1.0f + (1.0f - (1.0f + 0.001f * (float)console.SetupForm.udDSPImageGainTX.Value)); float iq_phase = 0.001f * (float)console.SetupForm.udDSPImagePhaseTX.Value; CorrectIQBuffer(out_l1, out_r1, iq_gain, iq_phase, frameCount); } break; case AudioState.COSL_SINR: out_l1 = out_l_ptr1; out_r1 = out_r_ptr1; out_l2 = out_l_ptr2; out_r2 = out_r_ptr2; if (two_tone) { double dump; CosineWave2Tone(out_l1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out dump, out dump); SineWave2Tone(out_r1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); } else { CosineWave(out_l1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = SineWave(out_r1, frameCount, phase_accumulator1, sine_freq1); } break; case AudioState.NOL_SINR: out_l1 = out_l_ptr1; out_r1 = out_r_ptr1; out_l2 = out_l_ptr2; out_r2 = out_r_ptr2; if (two_tone) { ClearBuffer(out_l1, frameCount); SineWave2Tone(out_r1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); } else { ClearBuffer(out_l1, frameCount); phase_accumulator1 = SineWave(out_r1, frameCount, phase_accumulator1, sine_freq1); } break; case AudioState.NOL_NOR: ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); break; case AudioState.PIPE: CopyBuffer(in_l_ptr1, out_l_ptr1, frameCount); CopyBuffer(in_r_ptr1, out_r_ptr1, frameCount); break; case AudioState.SWITCH: if (!ramp_down && !ramp_up) { switch (dsp_mode) { case DSPMode.CWL: case DSPMode.CWU: break; default: ClearBuffer(in_l_ptr1, frameCount); ClearBuffer(in_r_ptr1, frameCount); break; } if (mox != next_mox) mox = next_mox; } if (vac_enabled) { if ((rb_vacIN_l.ReadSpace() >= frameCount) && (rb_vacIN_r.ReadSpace() >= frameCount)) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(in_l_ptr1, frameCount); rb_vacIN_r.ReadPtr(in_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { VACDebug("rb_vacIN underflow switch time CB4!"); } } DttSP.ExchangeSamples(thread_no, in_l, in_r, out_l1, out_r1, frameCount); if (ramp_down) { int i; for (i = 0; i < frameCount; i++) { float w = (float)Math.Sin(ramp_val * Math.PI / 2.0); out_l_ptr1[i] *= w; out_r_ptr1[i] *= w; ramp_val += ramp_step; if (++ramp_count >= ramp_samples) { ramp_down = false; break; } } if (ramp_down) { for (; i < frameCount; i++) { out_l_ptr1[i] = 0.0f; out_r_ptr1[i] = 0.0f; } } } else if (ramp_up) { for (int i = 0; i < frameCount; i++) { float w = (float)Math.Sin(ramp_val * Math.PI / 2.0); out_l_ptr1[i] *= w; out_r_ptr1[i] *= w; ramp_val += ramp_step; if (++ramp_count >= ramp_samples) { ramp_up = false; break; } } } else { ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); } if (next_audio_state1 == AudioState.CW) { //cw_delay = 1; DttSP.CWtoneExchange(out_l1, out_r1, frameCount); } else if (switch_count == 1) DttSP.CWRingRestart(); switch_count--; //if(switch_count == ramp_up_num) RampUp = true; if (switch_count == 0) current_audio_state1 = next_audio_state1; break; } // scale output for VAC if (vac_enabled && !loopDLL_enabled && rb_vacIN_l != null && rb_vacIN_r != null && rb_vacOUT_l != null && rb_vacOUT_r != null) { fixed (float* outl_ptr = &(vac_outl[0])) fixed (float* outr_ptr = &(vac_outr[0])) { if (!mox) { ScaleBuffer(out_l1, outl_ptr, frameCount, (float)vac_rx_scale); ScaleBuffer(out_r1, outr_ptr, frameCount, (float)vac_rx_scale); } else // zero samples going back to VAC since TX monitor is off { ScaleBuffer(out_l1, outl_ptr, frameCount, 0.0f); ScaleBuffer(out_r1, outr_ptr, frameCount, 0.0f); } if (!mox) { if (sample_rateVAC == sample_rate1) { if ((rb_vacOUT_l.WriteSpace() >= frameCount) && (rb_vacOUT_r.WriteSpace() >= frameCount)) { if (VACDirectI_Q) { if (vac_correct_iq) CorrectIQBuffer(in_l, in_r, vac_iq_gain, vac_iq_phase, frameCount); Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.WritePtr(in_l, frameCount); rb_vacOUT_r.WritePtr(in_r, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.WritePtr(outl_ptr, frameCount); rb_vacOUT_r.WritePtr(outr_ptr, frameCount); Win32.LeaveCriticalSection(cs_vac); } } else { VACDebug("rb_vacOUT overflow Cb4"); } } else { fixed (float* res_outl_ptr = &(res_outl[0])) fixed (float* res_outr_ptr = &(res_outr[0])) { int outsamps = 0; if ((rb_vacOUT_l.WriteSpace() >= outsamps) && (rb_vacOUT_r.WriteSpace() >= outsamps)) { if (VACDirectI_Q) { DttSP.DoResamplerF(in_l, res_outl_ptr, frameCount, &outsamps, resampPtrOut_l); DttSP.DoResamplerF(in_r, res_outr_ptr, frameCount, &outsamps, resampPtrOut_r); if (vac_correct_iq) CorrectIQBuffer(res_outl_ptr, res_outr_ptr, vac_iq_gain, vac_iq_phase, frameCount); rb_vacOUT_l.WritePtr(res_outl_ptr, frameCount); rb_vacOUT_r.WritePtr(res_outr_ptr, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { DttSP.DoResamplerF(outl_ptr, res_outl_ptr, frameCount, &outsamps, resampPtrOut_l); DttSP.DoResamplerF(outr_ptr, res_outr_ptr, frameCount, &outsamps, resampPtrOut_r); Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.WritePtr(res_outl_ptr, outsamps); rb_vacOUT_r.WritePtr(res_outr_ptr, outsamps); Win32.LeaveCriticalSection(cs_vac); } } else { VACDebug("rb_vacOUT overflow Cb4"); } } } } } } if (wave_record && !vac_primary_audiodev && !mox && !record_rx_preprocessed) // post process audio wave_file_writer.AddWriteBuffer(out_l1, out_r1); else if (wave_record && mox && !record_tx_preprocessed) wave_file_writer.AddWriteBuffer(out_l2, out_r2); if (console.CurrentDisplayMode == DisplayMode.SCOPE || console.CurrentDisplayMode == DisplayMode.PANASCOPE) DoScope(out_l1, frameCount); double vol_l = monitor_volume_left; double vol_r = monitor_volume_right; if (PrimaryDirectI_Q && !mox) { if (primary_correct_iq) { CorrectIQBuffer(in_l, in_r, primary_iq_gain, primary_iq_phase, frameCount); } ScaleBuffer(in_l, out_l1, frameCount, (float)vol_l); ScaleBuffer(in_r, out_r1, frameCount, (float)vol_r); } else if (!MultiPSK_server_enable && loopDLL_enabled && vac_enabled && !mox) { int i; double[] buffer = new double[frameCount]; fixed (double* buffer_ptr = &(buffer[0])) fixed (float* res_outl_ptr = &(res_outl[0])) { ScaleBuffer(out_l1, res_outl_ptr, frameCount, (float)vol_l); if (mon) { ScaleBuffer(out_l1, out_l1, frameCount, (float)vol_l); ScaleBuffer(out_r1, out_r1, frameCount, (float)vol_r); ScaleBuffer(out_l1, out_l2, frameCount, (float)vol_l); ScaleBuffer(out_r1, out_r2, frameCount, (float)vol_r); } else { ClearBuffer(out_l1, frameCount); ClearBuffer(out_r1, frameCount); ClearBuffer(out_l2, frameCount); ClearBuffer(out_r2, frameCount); } for (i = 0; i < frameCount; i++) { buffer[i] = (double)1e5 * res_outl[i]; } try { console.loopDLL.WriteRXBuffer(buffer_ptr); } catch (Exception ex) { console.chkPower.Checked = false; Thread.Sleep(100); MessageBox.Show("loop.dll error!Check your PATH settings!\n" + ex.ToString()); } } } else if (!mox && MultiPSK_server_enable && run_MultiPSK_server_thread) { fixed (float* res_outl_ptr = &(MultiPSK_output_bufer_l[0])) { int outsamps; ScaleBuffer(out_l1, out_l1, frameCount, (float)monitor_volume_left); DttSP.DoResamplerF(out_l1, res_outl_ptr, frameCount, &outsamps, resampPtrOut_l); if (mon) { float[] mon_out_l = new float[frameCount]; float[] mon_out_r = new float[frameCount]; Marshal.Copy((IntPtr)out_l1, mon_out_l, 0, frameCount); Marshal.Copy((IntPtr)out_r1, mon_out_r, 0, frameCount); ChangeVolume(mon_out_l, out_l1, frameCount, (float)monitor_volume_left); ChangeVolume(mon_out_r, out_r1, frameCount, (float)monitor_volume_right); ChangeVolume(mon_out_l, out_l2, frameCount, (float)monitor_volume_left); ChangeVolume(mon_out_r, out_r2, frameCount, (float)monitor_volume_right); } else { ClearBuffer(out_l2, frameCount); ClearBuffer(out_r2, frameCount); ClearBuffer(out_l2, frameCount); ClearBuffer(out_r2, frameCount); } } MultiPSK_event.Set(); } else { if (!mox) // RX { switch (mute_ch) { case MuteChannels.Left: ScaleBuffer(out_r1, out_r1, frameCount, (float)vol_r); ScaleBuffer(out_r1, out_l1, frameCount, 1.0f); ScaleBuffer(out_r1, out_r2, frameCount, 1.0f); ScaleBuffer(out_r1, out_l2, frameCount, 1.0f); break; case MuteChannels.Right: ScaleBuffer(out_l1, out_l1, frameCount, (float)vol_l); ScaleBuffer(out_l1, out_r1, frameCount, 1.0f); ScaleBuffer(out_l1, out_r2, frameCount, 1.0f); ScaleBuffer(out_l1, out_l2, frameCount, 1.0f); break; case MuteChannels.Both: ClearBuffer(out_l1, frameCount); ClearBuffer(out_r1, frameCount); ClearBuffer(out_l2, frameCount); ClearBuffer(out_r2, frameCount); break; case MuteChannels.None: ScaleBuffer(out_l1, out_l1, frameCount, (float)vol_l); ScaleBuffer(out_r1, out_r1, frameCount, (float)vol_r); ScaleBuffer(out_l1, out_l2, frameCount, (float)vol_l); ScaleBuffer(out_r1, out_r2, frameCount, (float)vol_r); break; } } else { // TX float[] tmp_out_l = new float[frameCount]; float[] tmp_out_r = new float[frameCount]; double tx_vol = TXScale; Marshal.Copy((IntPtr)out_l1, tmp_out_l, 0, frameCount); Marshal.Copy((IntPtr)out_r1, tmp_out_r, 0, frameCount); if (high_pwr_am) { if (dsp_mode == DSPMode.AM || dsp_mode == DSPMode.SAM) tx_vol *= 1.414; } ChangeVolume(tmp_out_r, out_r1, frameCount, (float)tx_vol); ChangeVolume(tmp_out_l, out_l1, frameCount, (float)tx_vol); if (mon && !vac_mon && (dsp_mode == DSPMode.CWL || dsp_mode == DSPMode.CWU)) { DttSP.CWMonitorExchange(out_l2, out_r2, frameCount); ScaleBuffer(out_l2, out_l2, frameCount, (float)monitor_volume_left); ScaleBuffer(out_r2, out_r2, frameCount, (float)monitor_volume_right); } else if (mon && !vac_mon) { ChangeVolume(tmp_out_l, out_l2, frameCount, (float)monitor_volume_left); ChangeVolume(tmp_out_r, out_r2, frameCount, (float)monitor_volume_right); } else { ClearBuffer(out_l2, frameCount); ClearBuffer(out_r2, frameCount); } } } if (soundcard != SoundCard.DELTA_44) { // scale FireBox monitor output to prevent overdrive ScaleBuffer(out_l1, out_l1, frameCount, (float)(1.5f / audio_volts1)); ScaleBuffer(out_r1, out_r1, frameCount, (float)(1.5f / audio_volts1)); } //audio_run.ReleaseMutex(); return callback_return; } catch (Exception ex) { //audio_run.ReleaseMutex(); Debug.Write(ex.ToString()); return 0; } }
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; } }
unsafe public static int output_Callback4Port(void* input, void* output, int frameCount,// yt7pwr PA19.PaStreamCallbackTimeInfo* timeInfo, int statusFlags, void* userData) { try { #if(WIN64) Int64* array_ptr = (Int64*)output; float* out_l_ptr1 = (float*)array_ptr[0]; float* out_r_ptr1 = (float*)array_ptr[1]; float* in_l_ptr1 = null; float* in_r_ptr1 = null; #endif #if(WIN32) int* array_ptr = (int*)output; float* out_l_ptr1 = (float*)array_ptr[0]; float* out_r_ptr1 = (float*)array_ptr[1]; float* in_l_ptr1 = null; float* in_r_ptr1 = null; #endif if (mox && (!TX_out_1_2 || num_channels == 4)) { float* in_l_VAC = null, in_r_VAC = null, out_l = null, out_r = null; if (!voice_message_record) { if (voice_message_playback) voice_msg_file_reader.GetPlayBuffer(in_l_ptr1, in_r_ptr1); if (!console.TX_IQ_channel_swap) { out_r = out_l_ptr1; out_l = out_r_ptr1; } else { out_l = out_l_ptr1; out_r = out_r_ptr1; } } else if (voice_message_record) { out_l = out_l_ptr1; out_r = out_r_ptr1; } switch (current_audio_state1) { case AudioState.DTTSP: if (dsp_mode == DSPMode.CWU || dsp_mode == DSPMode.CWL) { DttSP.CWtoneExchange(out_l_ptr1, out_r_ptr1, frameCount); } DttSP.ExchangeOutputSamples(thread_no, out_l, out_r, frameCount); #region Output Signal Source switch (current_output_signal) { case SignalSource.SOUNDCARD: break; case SignalSource.SINE: SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); break; case SignalSource.NOISE: Noise(out_l_ptr1, frameCount); Noise(out_r_ptr1, frameCount); break; case SignalSource.TRIANGLE: Triangle(out_l_ptr1, frameCount, sine_freq1); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); break; case SignalSource.SAWTOOTH: Sawtooth(out_l_ptr1, frameCount, sine_freq1); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); break; } #endregion break; case AudioState.CW: if (next_audio_state1 == AudioState.SWITCH) { DttSP.ExchangeOutputSamples(thread_no, out_l_ptr1, out_r_ptr1, frameCount); if (switch_count == 0) next_audio_state1 = AudioState.CW; switch_count--; } else DttSP.CWtoneExchange(out_l, out_r, frameCount); break; case AudioState.SINL_COSR: if (two_tone) { double dump; SineWave2Tone(out_l_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out dump, out dump); CosineWave2Tone(out_r_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); } else { SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); } break; case AudioState.SINL_SINR: if (two_tone) { SineWave2Tone(out_l_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); } else { phase_accumulator1 = SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); } break; case AudioState.SINL_NOR: if (two_tone) { SineWave2Tone(out_l_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); ClearBuffer(out_r_ptr1, frameCount); } else { phase_accumulator1 = SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); ClearBuffer(out_r_ptr1, frameCount); } break; case AudioState.CW_COSL_SINR: if (mox) { if (two_tone) { double dump; if (console.tx_IF) { CosineWave2Tone(out_r, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + console.TX_IF_shift * 1e5, sine_freq2 + console.TX_IF_shift * 1e5, out dump, out dump); SineWave2Tone(out_l, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + console.TX_IF_shift * 1e5, sine_freq2 + console.TX_IF_shift * 1e5, out phase_accumulator1, out phase_accumulator2); } else { double osc = (console.VFOAFreq - console.LOSCFreq) * 1e6; CosineWave2Tone(out_r, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + osc, sine_freq2 + osc, out dump, out dump); SineWave2Tone(out_l, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + osc, sine_freq2 + osc, out phase_accumulator1, out phase_accumulator2); } } else { if (console.tx_IF) { CosineWave(out_r, frameCount, phase_accumulator1, sine_freq1 + console.TX_IF_shift * 1e5); phase_accumulator1 = SineWave(out_l, frameCount, phase_accumulator1, sine_freq1 + console.TX_IF_shift * 1e5); } else { double osc = (console.VFOAFreq - console.LOSCFreq) * 1e6; CosineWave(out_r, frameCount, phase_accumulator1, sine_freq1 + osc); phase_accumulator1 = SineWave(out_l, frameCount, phase_accumulator1, sine_freq1 + osc); } } float iq_gain = 1.0f + (1.0f - (1.0f + 0.001f * (float)console.SetupForm.udDSPImageGainTX.Value)); float iq_phase = 0.001f * (float)console.SetupForm.udDSPImagePhaseTX.Value; CorrectIQBuffer(out_l, out_r, iq_gain, iq_phase, frameCount); } break; case AudioState.COSL_SINR: if (two_tone) { double dump; CosineWave2Tone(out_l_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out dump, out dump); SineWave2Tone(out_r_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); } else { CosineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = SineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); } break; case AudioState.NOL_SINR: if (two_tone) { ClearBuffer(out_l_ptr1, frameCount); SineWave2Tone(out_r_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); } else { ClearBuffer(out_l_ptr1, frameCount); phase_accumulator1 = SineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); } break; case AudioState.NOL_NOR: ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); break; case AudioState.PIPE: CopyBuffer(in_l_ptr1, out_l_ptr1, frameCount); CopyBuffer(in_r_ptr1, out_r_ptr1, frameCount); break; case AudioState.SWITCH: if (!ramp_down && !ramp_up) { ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); if (mox != next_mox) mox = next_mox; } DttSP.ExchangeOutputSamples(thread_no, out_l_ptr1, out_r_ptr1, frameCount); if (ramp_down) { int i; for (i = 0; i < frameCount; i++) { float w = (float)Math.Sin(ramp_val * Math.PI / 2.0); out_l_ptr1[i] *= w; out_r_ptr1[i] *= w; ramp_val += ramp_step; if (++ramp_count >= ramp_samples) { ramp_down = false; break; } } if (ramp_down) { for (; i < frameCount; i++) { out_l_ptr1[i] = 0.0f; out_r_ptr1[i] = 0.0f; } } } else if (ramp_up) { for (int i = 0; i < frameCount; i++) { float w = (float)Math.Sin(ramp_val * Math.PI / 2.0); out_l_ptr1[i] *= w; out_r_ptr1[i] *= w; ramp_val += ramp_step; if (++ramp_count >= ramp_samples) { ramp_up = false; break; } } } else { ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); } if (next_audio_state1 == AudioState.CW) { //cw_delay = 1; DttSP.CWtoneExchange(out_l_ptr1, out_r_ptr1, frameCount); } else if (switch_count == 1) DttSP.CWRingRestart(); switch_count--; if (switch_count == ramp_up_num) RampUp = true; if (switch_count == 0) current_audio_state1 = next_audio_state1; break; } if ((!mox || (mox && (!mon || !vac_mon))) && (vac_enabled && !loopDLL_enabled && rb_vacIN_l != null && rb_vacIN_r != null && rb_vacOUT_l != null && rb_vacOUT_r != null)) { fixed (float* outl_ptr = &(vac_outl[0])) fixed (float* outr_ptr = &(vac_outr[0])) { if (!mox) { ScaleBuffer(out_l, outl_ptr, frameCount, (float)vac_rx_scale); // RX gain ScaleBuffer(out_r, outr_ptr, frameCount, (float)vac_rx_scale); } else { ScaleBuffer(out_l_ptr1, out_l_ptr1, frameCount, (float)vac_preamp); // TX gain ScaleBuffer(out_r_ptr1, out_r_ptr1, frameCount, (float)vac_preamp); } if (!mox) { if (sample_rateVAC == sample_rate1) { if ((rb_vacOUT_l.WriteSpace() >= frameCount) && (rb_vacOUT_r.WriteSpace() >= frameCount)) { Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.WritePtr(out_l_ptr1, frameCount); rb_vacOUT_r.WritePtr(out_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { VACDebug("rb_vacOUT overflow outCB4"); } } else { fixed (float* res_outl_ptr = &(res_outl[0])) fixed (float* res_outr_ptr = &(res_outr[0])) { int outsamps; DttSP.DoResamplerF(out_l_ptr1, res_outl_ptr, frameCount, &outsamps, resampPtrOut_l); DttSP.DoResamplerF(out_r_ptr1, res_outr_ptr, frameCount, &outsamps, resampPtrOut_r); if ((rb_vacOUT_l.WriteSpace() >= outsamps) && (rb_vacOUT_r.WriteSpace() >= outsamps)) { Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.WritePtr(res_outl_ptr, outsamps); rb_vacOUT_r.WritePtr(res_outr_ptr, outsamps); Win32.LeaveCriticalSection(cs_vac); } else { VACDebug("rb_vacOUT overflow outCB4"); } } } } } } if ((wave_record && !mox && !record_rx_preprocessed) || (wave_record && mox && !record_tx_preprocessed)) wave_file_writer.AddWriteBuffer(out_l_ptr1, out_r_ptr1); if (console.CurrentDisplayMode == DisplayMode.SCOPE || console.CurrentDisplayMode == DisplayMode.PANASCOPE) DoScope(out_l, frameCount); double vol_l = monitor_volume_left; double vol_r = monitor_volume_right; if (mox) { vol_l = TXScale; vol_r = TXScale; if (high_pwr_am) { if (dsp_mode == DSPMode.AM || dsp_mode == DSPMode.SAM) { vol_l *= 1.414; vol_r *= 1.414; } } } ScaleBuffer(out_l, out_l, frameCount, (float)vol_l); ScaleBuffer(out_r, out_r, frameCount, (float)vol_r); } else { if ((wave_record && !mox && !record_rx_preprocessed) || (wave_record && mox && !record_tx_preprocessed)) wave_file_writer.AddWriteBuffer(out_l_ptr1, out_r_ptr1); if (mon && (dsp_mode == DSPMode.CWL || dsp_mode == DSPMode.CWU)) { DttSP.CWMonitorExchange(out_l_ptr1, out_r_ptr1, frameCount); ScaleBuffer(out_l_ptr1, out_l_ptr1, frameCount, (float)monitor_volume_left); ScaleBuffer(out_r_ptr1, out_r_ptr1, frameCount, (float)monitor_volume_right); } else { ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); } } return callback_return; } catch (Exception ex) { Debug.Write(ex.ToString()); return 0; } }
unsafe public static int Callback1(void* input, void* output, int frameCount, // changes yt7pwr PA19.PaStreamCallbackTimeInfo* timeInfo, int statusFlags, void* userData) { try { if (console.CurrentModel == Model.GENESIS_G6 || audio_stop) return callback_return; //audio_run.WaitOne(100); #if(WIN64) Int64* array_ptr = (Int64*)input; float* in_l_ptr1 = (float*)array_ptr[0]; float* in_r_ptr1 = (float*)array_ptr[1]; double* VAC_in = (double*)input; array_ptr = (Int64*)output; float* out_l_ptr1 = (float*)array_ptr[1]; float* out_r_ptr1 = (float*)array_ptr[0]; #endif #if(WIN32) int* array_ptr = (int*)input; float* in_l_ptr1 = (float*)array_ptr[0]; float* in_r_ptr1 = (float*)array_ptr[1]; double* VAC_in = (double*)input; array_ptr = (int*)output; float* out_l_ptr1 = (float*)array_ptr[1]; float* out_r_ptr1 = (float*)array_ptr[0]; #endif if (wave_playback) wave_file_reader.GetPlayBuffer(in_l_ptr1, in_r_ptr1); else if ((wave_record && !mox && record_rx_preprocessed && !vac_primary_audiodev) || (wave_record && mox && record_tx_preprocessed)) wave_file_writer.AddWriteBuffer(in_l_ptr1, in_r_ptr1); if (phase) { //phase_mutex.WaitOne(); Marshal.Copy(new IntPtr(in_l_ptr1), phase_buf_l, 0, frameCount); Marshal.Copy(new IntPtr(in_r_ptr1), phase_buf_r, 0, frameCount); //phase_mutex.ReleaseMutex(); } float* in_l = null, in_l_VAC = null, in_r = null, in_r_VAC = null, out_l = null, out_r = null; if (!mox && !voice_message_record) // rx { if (!console.RX_IQ_channel_swap) { in_l = in_l_ptr1; in_r = in_r_ptr1; out_l = out_l_ptr1; out_r = out_r_ptr1; } else { in_l = in_r_ptr1; in_r = in_l_ptr1; out_l = out_r_ptr1; out_r = out_l_ptr1; } } else if (mox && !voice_message_record) { // tx if (!console.TX_IQ_channel_swap) { in_r = in_l_ptr1; in_l = in_r_ptr1; out_r = out_l_ptr1; out_l = out_r_ptr1; } else { in_r = in_l_ptr1; in_l = in_r_ptr1; out_l = out_l_ptr1; out_r = out_r_ptr1; } if (voice_message_playback) { voice_msg_file_reader.GetPlayBuffer(in_l, in_r); } } else if (voice_message_record) { in_l = in_l_ptr1; in_r = in_r_ptr1; out_l = out_l_ptr1; out_r = out_r_ptr1; } if (voice_message_record) { try { if (vac_enabled) { if (rb_vacIN_l.ReadSpace() >= frameCount && rb_vacIN_r.ReadSpace() >= frameCount) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(in_l_ptr1, frameCount); rb_vacIN_r.ReadPtr(in_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { ClearBuffer(in_l_ptr1, frameCount); ClearBuffer(in_r_ptr1, frameCount); VACDebug("rb_vacIN underflow VoiceMsg record"); } } ScaleBuffer(in_l, in_l, frameCount, (float)mic_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)mic_preamp); voice_msg_file_writer.AddWriteBuffer(in_l, in_r); } catch (Exception ex) { VACDebug("Audio: " + ex.ToString()); } } if (!MultiPSK_server_enable && vac_enabled && loopDLL_enabled && mox) { in_l_VAC = in_l; // save pointer in_r_VAC = in_r; // save pointer fixed (double* loopDLL_inl_ptr = &(loopDLL_inl[0])) { if (console.loopDLL.ReadTXBuffer(loopDLL_inl_ptr)) { for (int i = 0; i < frameCount; i++) { in_l[0] = (float)(loopDLL_inl[i] / 1e5); in_r[0] = 0.0f; // (float)(loopDLL_inl[i] / 1e5); in_l++; in_r++; } } else { } } in_l = in_l_VAC; // restore pointer in_r = in_r_VAC; // restore pointer } else if (mox && MultiPSK_server_enable && console.MultiPSKServer.ClientConnected) { float* tmp_l = in_l; float* tmp_r = in_r; for (int i = 0; i < frameCount; i++) { in_l[0] = MultiPSK_output_bufer_l[i]; in_r[0] = 0.0f; in_l++; in_r++; } in_l = tmp_l; in_r = tmp_r; } switch (current_audio_state1) { case AudioState.DTTSP: // scale input with mic preamp if ((mox || voice_message_record) && !vac_enabled && (dsp_mode == DSPMode.LSB || dsp_mode == DSPMode.USB || dsp_mode == DSPMode.DSB || dsp_mode == DSPMode.AM || dsp_mode == DSPMode.SAM || dsp_mode == DSPMode.FMN)) { if (wave_playback) { ScaleBuffer(in_l, in_l, frameCount, (float)wave_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)wave_preamp); } else { ScaleBuffer(in_l, in_l, frameCount, (float)mic_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)mic_preamp); } if (echo_enable && (dsp_mode != DSPMode.DIGL || dsp_mode != DSPMode.DIGU)) { if (!echo_pause) { echoRB.WritePtr(in_l, frameCount); if (echoRB.ReadSpace() > echo_delay - 2) { EchoMixer(in_l, in_r, frameCount); } } } } #region Input Signal Source switch (current_input_signal) { case SignalSource.SOUNDCARD: break; case SignalSource.SINE: if (console.RX_IQ_channel_swap) { SineWave(in_r, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(in_l, frameCount, phase_accumulator1, sine_freq1); } else { SineWave(in_l, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(in_r, frameCount, phase_accumulator1 + 0.0001f, sine_freq1); } ScaleBuffer(in_l, in_l, frameCount, (float)input_source_scale); ScaleBuffer(in_r, in_r, frameCount, (float)input_source_scale); break; case SignalSource.NOISE: Noise(in_l, frameCount); Noise(in_r, frameCount); break; case SignalSource.TRIANGLE: Triangle(in_l, frameCount, sine_freq1); CopyBuffer(in_l, in_r, frameCount); break; case SignalSource.SAWTOOTH: Sawtooth(in_l, frameCount, sine_freq1); CopyBuffer(in_l, in_r, frameCount); break; } #endregion if (!loopDLL_enabled && vac_enabled && rb_vacIN_l != null && rb_vacIN_r != null && rb_vacOUT_l != null && rb_vacOUT_r != null && !voice_message_playback) { if (mox && !voice_message_record) { if (rb_vacIN_l.ReadSpace() >= frameCount && rb_vacIN_r.ReadSpace() >= frameCount) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(in_l, frameCount); rb_vacIN_r.ReadPtr(in_r, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { ClearBuffer(in_l, frameCount); ClearBuffer(in_r, frameCount); VACDebug("rb_vacIN underflow CB1"); } ScaleBuffer(in_l, in_l, frameCount, (float)vac_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)vac_preamp); if (echo_enable && (dsp_mode != DSPMode.DIGL || dsp_mode != DSPMode.DIGU)) { if (!echo_pause) { echoRB.WritePtr(in_l, frameCount); if (echoRB.ReadSpace() > echo_delay - 2) { EchoMixer(in_l, in_r, frameCount); } } } } else if (voice_message_record) { } } else if (!MultiPSK_server_enable && loopDLL_enabled && mox) { ScaleBuffer(in_l, in_l, frameCount, (float)vac_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)vac_preamp); } else if (mox && MultiPSK_server_enable && console.MultiPSKServer.ClientConnected) { ScaleBuffer(in_l, in_l, frameCount, (float)mic_preamp); ScaleBuffer(in_r, in_r, frameCount, (float)mic_preamp); } DttSP.ExchangeSamples(thread_no, in_l, in_r, out_l, out_r, frameCount); #region Output Signal Source switch (current_output_signal) { case SignalSource.SOUNDCARD: break; case SignalSource.SINE: switch (ChannelTest) { case TestChannels.Left: SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); break; case TestChannels.Right: SineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); break; case TestChannels.Both: SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); SineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator2 = CosineWave(out_r_ptr1, frameCount, phase_accumulator2, sine_freq1); break; } break; case SignalSource.NOISE: switch (ChannelTest) { case TestChannels.Both: Noise(out_l_ptr1, frameCount); Noise(out_r_ptr1, frameCount); break; case TestChannels.Left: Noise(out_l_ptr1, frameCount); break; case TestChannels.Right: Noise(out_r_ptr1, frameCount); break; } break; case SignalSource.TRIANGLE: switch (ChannelTest) { case TestChannels.Both: Triangle(out_l_ptr1, frameCount, sine_freq1); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); break; case TestChannels.Left: Triangle(out_l_ptr1, frameCount, sine_freq1); break; case TestChannels.Right: Triangle(out_r_ptr1, frameCount, sine_freq1); break; } break; case SignalSource.SAWTOOTH: switch (ChannelTest) { case TestChannels.Both: Sawtooth(out_l_ptr1, frameCount, sine_freq1); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); break; case TestChannels.Left: Sawtooth(out_l_ptr1, frameCount, sine_freq1); break; case TestChannels.Right: Sawtooth(out_r_ptr1, frameCount, sine_freq1); break; } break; } #endregion break; case AudioState.CW: if (next_audio_state1 == AudioState.SWITCH) { Win32.memset(in_l_ptr1, 0, frameCount * sizeof(float)); Win32.memset(in_r_ptr1, 0, frameCount * sizeof(float)); if (vac_enabled) { if ((rb_vacIN_l.ReadSpace() >= frameCount) && (rb_vacIN_r.ReadSpace() >= frameCount)) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(in_l_ptr1, frameCount); rb_vacIN_r.ReadPtr(in_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { VACDebug("rb_vacIN underflow Switch time CB1!"); } } ClearBuffer(out_l, frameCount); ClearBuffer(out_r, frameCount); if (switch_count == 0) next_audio_state1 = AudioState.CW; switch_count--; } else DttSP.CWtoneExchange(out_l, out_r, frameCount); break; case AudioState.SINL_COSR: if (two_tone) { double dump; SineWave2Tone(out_l_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out dump, out dump); CosineWave2Tone(out_r_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); } else { SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = CosineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); } break; case AudioState.SINL_SINR: if (two_tone) { SineWave2Tone(out_l_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); } else { phase_accumulator1 = SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); CopyBuffer(out_l_ptr1, out_r_ptr1, frameCount); } break; case AudioState.SINL_NOR: if (two_tone) { SineWave2Tone(out_l_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); ClearBuffer(out_r_ptr1, frameCount); } else { phase_accumulator1 = SineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); ClearBuffer(out_r_ptr1, frameCount); } break; case AudioState.CW_COSL_SINR: if (mox) { if (two_tone) { double dump; if (console.tx_IF) { CosineWave2Tone(out_r, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + console.TX_IF_shift * 1e5, sine_freq2 + console.TX_IF_shift * 1e5, out dump, out dump); SineWave2Tone(out_l, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + console.TX_IF_shift * 1e5, sine_freq2 + console.TX_IF_shift * 1e5, out phase_accumulator1, out phase_accumulator2); } else { double osc = (console.VFOAFreq - console.LOSCFreq) * 1e6; CosineWave2Tone(out_r, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + osc, sine_freq2 + osc, out dump, out dump); SineWave2Tone(out_l, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1 + osc, sine_freq2 + osc, out phase_accumulator1, out phase_accumulator2); } } else { if (console.tx_IF) { CosineWave(out_r, frameCount, phase_accumulator1, sine_freq1 + console.TX_IF_shift * 1e5); phase_accumulator1 = SineWave(out_l, frameCount, phase_accumulator1, sine_freq1 + console.TX_IF_shift * 1e5); } else { double osc = (console.VFOAFreq - console.LOSCFreq) * 1e6; CosineWave(out_r, frameCount, phase_accumulator1, sine_freq1 + osc); phase_accumulator1 = SineWave(out_l, frameCount, phase_accumulator1, sine_freq1 + osc); } } float iq_gain = 1.0f + (1.0f - (1.0f + 0.001f * (float)console.SetupForm.udDSPImageGainTX.Value)); float iq_phase = 0.001f * (float)console.SetupForm.udDSPImagePhaseTX.Value; CorrectIQBuffer(out_l, out_r, iq_gain, iq_phase, frameCount); } break; case AudioState.COSL_SINR: if (two_tone) { double dump; CosineWave2Tone(out_l_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out dump, out dump); SineWave2Tone(out_r_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); } else { CosineWave(out_l_ptr1, frameCount, phase_accumulator1, sine_freq1); phase_accumulator1 = SineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); } break; case AudioState.NOL_SINR: if (two_tone) { ClearBuffer(out_l_ptr1, frameCount); SineWave2Tone(out_r_ptr1, frameCount, phase_accumulator1, phase_accumulator2, sine_freq1, sine_freq2, out phase_accumulator1, out phase_accumulator2); } else { ClearBuffer(out_l_ptr1, frameCount); phase_accumulator1 = SineWave(out_r_ptr1, frameCount, phase_accumulator1, sine_freq1); } break; case AudioState.NOL_NOR: ClearBuffer(out_l_ptr1, frameCount); ClearBuffer(out_r_ptr1, frameCount); break; case AudioState.PIPE: CopyBuffer(in_l_ptr1, out_l_ptr1, frameCount); CopyBuffer(in_r_ptr1, out_r_ptr1, frameCount); break; case AudioState.SWITCH: if (!ramp_down && !ramp_up) { ClearBuffer(in_l, frameCount); ClearBuffer(in_r, frameCount); if (mox != next_mox) mox = next_mox; } if (vac_enabled) { if ((rb_vacIN_l.ReadSpace() >= frameCount) && (rb_vacIN_r.ReadSpace() >= frameCount)) { Win32.EnterCriticalSection(cs_vac); rb_vacIN_l.ReadPtr(in_l_ptr1, frameCount); rb_vacIN_r.ReadPtr(in_r_ptr1, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { VACDebug("rb_vacIN underflow switch time CB1!"); } } DttSP.ExchangeSamples(thread_no, in_l, in_r, out_l, out_r, frameCount); if (ramp_down) { int i; for (i = 0; i < frameCount; i++) { float w = (float)Math.Sin(ramp_val * Math.PI / 2.0); out_l_ptr1[i] *= w; out_r_ptr1[i] *= w; ramp_val += ramp_step; if (++ramp_count >= ramp_samples) { ramp_down = false; break; } } if (ramp_down) { for (; i < frameCount; i++) { out_l[i] = 0.0f; out_r[i] = 0.0f; } } } else if (ramp_up) { for (int i = 0; i < frameCount; i++) { float w = (float)Math.Sin(ramp_val * Math.PI / 2.0); out_l[i] *= w; out_r[i] *= w; ramp_val += ramp_step; if (++ramp_count >= ramp_samples) { ramp_up = false; break; } } } else { ClearBuffer(out_l, frameCount); ClearBuffer(out_r, frameCount); } if (next_audio_state1 == AudioState.CW) { //cw_delay = 1; DttSP.CWtoneExchange(out_l, out_r, frameCount); } else if (switch_count == 1) DttSP.CWRingRestart(); switch_count--; if (switch_count == ramp_up_num) RampUp = true; if (switch_count == 0) current_audio_state1 = next_audio_state1; break; } if (!MultiPSK_server_enable && vac_enabled && !loopDLL_enabled && rb_vacIN_l != null && rb_vacIN_r != null && rb_vacOUT_l != null && rb_vacOUT_r != null) { fixed (float* outl_ptr = &(vac_outl[0])) fixed (float* outr_ptr = &(vac_outr[0])) { if (!mox) { ScaleBuffer(out_l, outl_ptr, frameCount, (float)vac_rx_scale); ScaleBuffer(out_r, outr_ptr, frameCount, (float)vac_rx_scale); } else if (mox && vac_mon && (dsp_mode == DSPMode.CWU || dsp_mode == DSPMode.CWL)) { ScaleBuffer(out_l, outl_ptr, frameCount, 0.0f); ScaleBuffer(out_r, outr_ptr, frameCount, 0.0f); } else // zero samples going back to VAC since TX monitor is off { ScaleBuffer(out_l, outl_ptr, frameCount, 0.0f); ScaleBuffer(out_r, outr_ptr, frameCount, 0.0f); } int count = 0; while (!(rb_vacOUT_l.WriteSpace() >= frameCount && rb_vacOUT_r.WriteSpace() >= frameCount)) { Thread.Sleep(1); count++; if (count > latency1) break; } if (count > 0 && debug) VACDebug("VAC WriteSpace count: " + count.ToString()); if (!mox) { if (sample_rateVAC == sample_rate1) { if ((rb_vacOUT_l.WriteSpace() >= frameCount) && (rb_vacOUT_r.WriteSpace() >= frameCount)) { if (VACDirectI_Q) { if (vac_correct_iq) CorrectIQBuffer(in_l, in_r, vac_iq_gain, vac_iq_phase, frameCount); Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.WritePtr(in_l, frameCount); rb_vacOUT_r.WritePtr(in_r, frameCount); Win32.LeaveCriticalSection(cs_vac); } else { Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.WritePtr(outl_ptr, frameCount); rb_vacOUT_r.WritePtr(outr_ptr, frameCount); Win32.LeaveCriticalSection(cs_vac); } } else { VACDebug("rb_vacOUT overflow CB1"); } } else { fixed (float* res_outl_ptr = &(res_outl[0])) fixed (float* res_outr_ptr = &(res_outr[0])) { int outsamps; if (VACDirectI_Q) { DttSP.DoResamplerF(in_l_ptr1, res_outl_ptr, frameCount, &outsamps, resampPtrOut_l); DttSP.DoResamplerF(in_r_ptr1, res_outr_ptr, frameCount, &outsamps, resampPtrOut_r); if ((rb_vacOUT_l.WriteSpace() >= outsamps) && (rb_vacOUT_r.WriteSpace() >= outsamps)) { if (vac_correct_iq) CorrectIQBuffer(res_outl_ptr, res_outr_ptr, vac_iq_gain, vac_iq_phase, frameCount); Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.WritePtr(res_outl_ptr, outsamps); rb_vacOUT_r.WritePtr(res_outr_ptr, outsamps); Win32.LeaveCriticalSection(cs_vac); } else { VACDebug("rb_vacOUT overflow CB1"); } } else { DttSP.DoResamplerF(outl_ptr, res_outl_ptr, frameCount, &outsamps, resampPtrOut_l); DttSP.DoResamplerF(outr_ptr, res_outr_ptr, frameCount, &outsamps, resampPtrOut_r); if ((rb_vacOUT_l.WriteSpace() >= outsamps) && (rb_vacOUT_r.WriteSpace() >= outsamps)) { Win32.EnterCriticalSection(cs_vac); rb_vacOUT_l.WritePtr(res_outl_ptr, outsamps); rb_vacOUT_r.WritePtr(res_outr_ptr, outsamps); Win32.LeaveCriticalSection(cs_vac); } else { VACDebug("rb_vacOUT overflow CB1"); } } } } } } } if (console.CurrentDisplayMode == DisplayMode.SCOPE || console.CurrentDisplayMode == DisplayMode.PANASCOPE) DoScope(out_l, frameCount); double vol_l = monitor_volume_left; double vol_r = monitor_volume_right; if (mox) { vol_l = TXScale; vol_r = TXScale; if (high_pwr_am) { if (dsp_mode == DSPMode.AM || dsp_mode == DSPMode.SAM) { vol_l *= 1.414; vol_r *= 1.414; } } } if (wave_record && (!vac_primary_audiodev && !mox && !record_rx_preprocessed) || // post process audio (wave_record && mox && !record_tx_preprocessed)) wave_file_writer.AddWriteBuffer(out_r_ptr1, out_l_ptr1); if (PrimaryDirectI_Q && !mox) { if (primary_correct_iq) { CorrectIQBuffer(in_l, in_r, primary_iq_gain, primary_iq_phase, frameCount); } ScaleBuffer(in_l, out_r, frameCount, (float)vol_l); ScaleBuffer(in_r, out_l, frameCount, (float)vol_r); } else if (!MultiPSK_server_enable && loopDLL_enabled && vac_enabled && !mox) { int i; double[] buffer = new double[frameCount]; fixed (double* buffer_ptr = &(buffer[0])) fixed (float* res_outl_ptr = &(res_outl[0])) { ScaleBuffer(out_l, res_outl_ptr, frameCount, (float)vol_l); if (mon) { ScaleBuffer(out_l, out_l, frameCount, (float)monitor_volume_left); ScaleBuffer(out_r, out_r, frameCount, (float)monitor_volume_right); } else { ScaleBuffer(out_l, out_l, frameCount, 0.0f); ScaleBuffer(out_r, out_r, frameCount, 0.0f); } { for (i = 0; i < frameCount; i++) { buffer[i] = (double)1e5 * res_outl[i]; } console.loopDLL.WriteRXBuffer(buffer_ptr); } } } else if (!mox && MultiPSK_server_enable && run_MultiPSK_server_thread) { fixed (float* res_outl_ptr = &(MultiPSK_output_bufer_l[0])) { int outsamps; ScaleBuffer(out_l, out_l, frameCount, (float)vol_l); DttSP.DoResamplerF(out_l, res_outl_ptr, frameCount, &outsamps, resampPtrOut_l); ScaleBuffer(out_l, out_l, frameCount, 0.0f); ScaleBuffer(out_r, out_r, frameCount, 0.0f); } MultiPSK_event.Set(); } else { if (mox) { ScaleBuffer(out_l, out_l, frameCount, (float)vol_l); ScaleBuffer(out_r, out_r, frameCount, (float)vol_r); } else { switch (mute_ch) { case MuteChannels.Left: ScaleBuffer(out_r, out_r, frameCount, (float)vol_r); ScaleBuffer(out_r, out_l, frameCount, 1.0f); break; case MuteChannels.Right: ScaleBuffer(out_l, out_l, frameCount, (float)vol_l); ScaleBuffer(out_l, out_r, frameCount, 1.0f); break; case MuteChannels.Both: ClearBuffer(out_l, frameCount); ClearBuffer(out_r, frameCount); break; case MuteChannels.None: ScaleBuffer(out_l, out_l, frameCount, (float)vol_l); ScaleBuffer(out_r, out_r, frameCount, (float)vol_r); break; } } } return callback_return; } catch (Exception ex) { Debug.Write(ex.ToString()); return 0; } }
public static unsafe int StartAudio(int sample_rate, int samples_per_block, PA19.PaStreamCallback cb, int sample_bits, int no_send) { if ( !isOzyInitialized ) { // int rc; // oz_start(); // rc = JanusOzyIO.getJanusOzy().init(); // System.Console.WriteLine("JanusOzyIO.init returned: " + rc); // if ( rc != 0 ) // { // return 1; // } if ( initOzy() != 0 ) { return 1; } isOzyInitialized = true; } return StartAudioNative(sample_rate, samples_per_block, cb, sample_bits, no_send); }