Example #1
0
        unsafe public static bool Start()           // changes yt7pwr
        {
            if (audio_stop || VAC_audio_stop)
                return false;

            bool retval = false;
            phase_buf_l = new float[block_size1];
            phase_buf_r = new float[block_size1];

            G6RB_right.Restart(65536);
            G6RB_left.Restart(65536);

            if(vac_enabled)
                InitVAC();
            else
                DttSP.EnableResamplerF(0, 0, 0);   //disable resampler

            if (console.CurrentModel == Model.RTL_SDR)
            {
                retval = true;
            }
            else if (console.CurrentModel != Model.GENESIS_G6)
            {
                retval = true;

                if (iq_data_l == null)
                    iq_data_l = new byte[32768];
                if (iq_data_r == null)
                    iq_data_r = new byte[32768];
                if (CATNetwork_mutex == null)
                    CATNetwork_mutex = new Mutex(false);
                if (MultiPSK_mutex == null)
                    MultiPSK_mutex = new Mutex(false);
                if (DttSP_mutex == null)
                    DttSP_mutex = new Mutex(false);
                if (echoRB == null)
                    echoRB = new RingBufferFloat(131072);

                echoRB.Restart(131072);
                echoRB.Reset();

                #region ethernet server
                if (enable_ethernet_server)         // act as network server
                {
                    if (num_channels == 2 && server_rf_spectar)
                        retval = StartAudio(ref ServerCallbackFullSpectar, (uint)block_size1, sample_rate1, host1,
                            input_dev1, output_dev1, num_channels, 0, latency1);
                    else if (num_channels == 2 && !server_rf_spectar)
                        retval = StartAudio(ref ServerCallbackAFSpectar, (uint)block_size1, sample_rate1, host1,
                            input_dev1, output_dev1, num_channels, 0, latency1);
                    else if (num_channels == 4 && server_rf_spectar)
                        retval = StartAudio(ref ServerCallback4portFullSpectar, (uint)block_size1, sample_rate1, host1,
                            input_dev1, output_dev1, num_channels, 0, latency1);
                    else if (num_channels == 4 && !server_rf_spectar)
                        retval = StartAudio(ref ServerCallback4portAFSpectar, (uint)block_size1, sample_rate1, host1,
                            input_dev1, output_dev1, num_channels, 0, latency1);
                }
                #endregion

                #region local host
                else if (enable_local_host)          // no network function
                {
                    if (audio_exclusive)
                    {
                        if (console.CurrentSoundCard == SoundCard.UNSUPPORTED_CARD &&
                            (console.WinVer == WindowsVersion.Windows7 || console.WinVer == WindowsVersion.Windows8 ||
                            console.WinVer == WindowsVersion.WindowsVista))
                        {
                            if (num_channels == 2)
                            {
                                retval = StartAudioExclusiveWin7(ref input_callback1, (uint)block_size1,
                                    sample_rate1, host1, input_dev1, 0xffff, 0, 0, latency1);
                                retval = StartAudioExclusiveWin7(ref output_callback1, (uint)block_size1,
                                    sample_rate1, host1, 0xffff, output_dev1, 1, 0, latency1);
                            }
                            else if (num_channels == 4 || num_channels == 6)
                            {
                                retval = StartAudioExclusiveWin7(ref input_callback1, (uint)block_size1,
                                    sample_rate1, host1, input_dev1, 0xffff, 0, 0, latency1);
                                retval = StartAudioExclusiveWin7(ref output_callback1, (uint)block_size1,
                                    sample_rate1, host1, 0xffff, output_dev1, 1, 0, latency1);
                                retval = StartAudioExclusiveWin7(ref input_callback4port, (uint)block_size1, sample_rate1,
                                    host1, input_dev3, 0xf0f0, 2, 0, latency1);
                                retval = StartAudioExclusiveWin7(ref output_callback4port, (uint)block_size1, sample_rate1,
                                    host1, 0xf0f0, output_dev3, 3, 0, latency1);
                            }
                        }
                        else if (console.CurrentSoundCard == SoundCard.UNSUPPORTED_CARD &&
                            (console.WinVer == WindowsVersion.Windows7 || console.WinVer == WindowsVersion.Windows8 ||
                            console.WinVer == WindowsVersion.WindowsVista))
                        {
                            if (num_channels == 2)
                            {
                                retval = StartAudioExclusiveWinXP(ref input_callback1, (uint)block_size1,
                                    sample_rate1, host1, input_dev1, 0xffff, 0, 0, latency1);
                                retval = StartAudioExclusiveWinXP(ref output_callback1, (uint)block_size1,
                                    sample_rate1, host1, 0xffff, output_dev1, 1, 0, latency1);
                            }
                            else if (num_channels == 4 || num_channels == 6)
                            {
                                retval = StartAudioExclusiveWinXP(ref input_callback1, (uint)block_size1,
                                    sample_rate1, host1, input_dev1, 0xffff, 0, 0, latency1);
                                retval = StartAudioExclusiveWinXP(ref output_callback1, (uint)block_size1,
                                    sample_rate1, host1, 0xffff, output_dev1, 1, 0, latency1);
                                retval = StartAudioExclusiveWinXP(ref input_callback4port, (uint)block_size1, sample_rate1,
                                    host1, input_dev3, 0xf0f0, 2, 0, latency1);
                                retval = StartAudioExclusiveWinXP(ref output_callback4port, (uint)block_size1, sample_rate1,
                                    host1, 0xf0f0, output_dev3, 3, 0, latency1);
                            }
                        }
                    }
                    else
                    {
                        if (num_channels == 2)
                        {
                            retval = StartAudio(ref callback1, (uint)block_size1,
                                sample_rate1, host1, input_dev1, output_dev1, num_channels, 0, latency1);
                        }
                        else if (num_channels == 4)
                        {
                            retval = StartAudio(ref callback4port, (uint)block_size1, sample_rate1,
                                host1, input_dev1, output_dev1, num_channels, 0, latency1);
                        }
                    }
                }
                #endregion

                #region ethernet client
                else if (enable_ethernet_client)    // act as network client
                {

                    network_input_bufer_l = new byte[block_size1 * sizeof(float) * 2];
                    network_input_bufer_r = new byte[block_size1 * sizeof(float) * 2];

                    if (client_rf_spectar)
                    {
                        retval = StartAudio(ref ClientCallback1, (uint)block_size1, sample_rate1,
                            host1, input_dev1, output_dev1, num_channels, 1, latency1);
                    }
                    else
                    {
                        retval = StartAudio(ref ClientCallback1, (uint)block_size1, sample_rate1,
                            host1, input_dev1, output_dev1, num_channels, 0, latency1);
                    }
                }
                #endregion

                if (!retval) return retval;

                #region MultiPSK server

                if (MultiPSK_server_enable)    // act as MultiPSK network server
                {
                    MultiPSK_input_bufer_l = new float[4096 * sizeof(float) * 2];
                    MultiPSK_input_bufer_r = new float[4096 * sizeof(float) * 2];
                    MultiPSK_output_bufer_l = new float[4096 * sizeof(float) * 2];
                    MultiPSK_output_bufer_r = new float[4096 * sizeof(float) * 2];
                    resampPtrIn_l = DttSP.NewResamplerF(11025, sample_rate1);
                    resampPtrIn_r = DttSP.NewResamplerF(11025, sample_rate1);
                    resampPtrOut_l = DttSP.NewResamplerF(sample_rate1, 11025);

                    if (sample_rate1 == 48000)
                        console.MultiPSKServer.send_bytes = 470;
                    else if (sample_rate1 == 96000)
                        console.MultiPSKServer.send_bytes = 235;
                    else
                        console.MultiPSKServer.send_bytes = 512;

                    run_MultiPSK_server_thread = true;
                    MultiPSK_thread = new Thread(new ThreadStart(MultiPSKServerThread));
                    MultiPSK_thread.Name = "MultiPSK Thread";
                    MultiPSK_thread.Priority = ThreadPriority.Normal;
                    MultiPSK_thread.IsBackground = true;
                    MultiPSK_thread.Start();
                }

                #endregion
            }

            #region VAC

            #region loop.dll

            if (vac_enabled && !enable_ethernet_server && !enable_ethernet_client && loopDLL_enabled)
            {
                if (loopDLL_inl == null)
                    loopDLL_inl = new double[block_size_vac];
                else
                {
                    loopDLL_inl = null;
                    loopDLL_inl = new double[block_size_vac];
                }
                if (loopDLL_inr == null)
                    loopDLL_inr = new double[block_size_vac];
                else
                {
                    loopDLL_inr = null;
                    loopDLL_inr = new double[block_size_vac];
                }
                if (loopDLL_outl == null)
                    loopDLL_outl = new double[block_size_vac];
                else
                {
                    loopDLL_outl = null;
                    loopDLL_outl = new double[block_size_vac];
                }
                if (loopDLL_outr == null)
                    loopDLL_outr = new double[block_size_vac];
                else
                {
                    loopDLL_outr = null;
                    loopDLL_outr = new double[block_size_vac];
                }

                console.loopDLL.InitRXPlay(sample_rate1, block_size1);
                console.loopDLL.InitRXRec(sample_rate1, block_size1);
                console.loopDLL.InitTXRec(sample_rate1, block_size1);
                console.loopDLL.InitTXPlay(sample_rate1, block_size1);

                resampPtrOut_l = DttSP.NewResamplerF(sample_rate1, 8000);
            }
            #endregion

            else if (vac_enabled && !enable_ethernet_server && !enable_ethernet_client)
            {
                int num_chan = console.SetupForm.VACchNumber;
                vac_rb_reset = true;

                if (VAC_audio_exclusive && (console.CurrentSoundCard == SoundCard.UNSUPPORTED_CARD ||
                    console.CurrentSoundCard == SoundCard.G6))
                {
                    retval = StartAudioExclusiveWin7(ref input_callbackVAC, (uint)block_size_vac, sample_rateVAC,
                        host2, input_dev2, 0xffff, 4, 1, latency2);
                    retval = StartAudioExclusiveWin7(ref output_callbackVAC, (uint)block_size_vac, sample_rateVAC,
                        host2, 0xffff, output_dev2, 5, 1, latency2);
                }
                else
                    retval = StartVACAudio(ref callbackVAC, (uint)block_size_vac, sample_rateVAC,
                        host2, input_dev2, output_dev2, num_chan, latency2);

                Thread.Sleep(100);
            }
            else if (vac_enabled && enable_ethernet_server && !enable_ethernet_client)
            {
                int num_chan = console.SetupForm.VACchNumber;
                vac_rb_reset = true;
                retval = StartVACAudio(ref ServerCallbackVACFullSpectar, (uint)block_size2, sample_rateVAC,
                    host2, input_dev2, output_dev2, num_chan, latency2);
                Thread.Sleep(100);
            }
            else if (vac_enabled && !enable_ethernet_server && enable_ethernet_client)
            {
                int num_chan = console.SetupForm.VACchNumber;
                vac_rb_reset = true;
                vac_callback = true;
                retval = StartVACAudio(ref callbackVAC, (uint)block_size2, sample_rateVAC,
                    host2, input_dev2, output_dev2, num_chan, latency2);
                Thread.Sleep(100);
                vac_callback = false;
            }
            #endregion

            return retval;
        }
Example #2
0
        unsafe private static void CleanUpVAC()
        {
            try
            {
                Win32.DeleteCriticalSection(cs_vac);
                Win32.DeleteCriticalSection(cs_g6_callback);
                rb_vacOUT_l = null;
                rb_vacOUT_r = null;
                rb_vacIN_l = null;
                rb_vacIN_r = null;

                res_outl = null;
                res_outr = null;
                res_inl = null;
                res_inr = null;

                resampPtrIn_l = null;
                resampPtrIn_r = null;
                resampPtrOut_l = null;
                resampPtrOut_r = null;

                loopDLL_inl = null;
                loopDLL_inr = null;
                loopDLL_outl = null;
                loopDLL_outr = null;
                Win32.DestroyCriticalSection(cs_vac);
                Win32.DestroyCriticalSection(cs_g6_callback);
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());

                if (debug)
                    VACDebug(ex.ToString());
            }
        }
Example #3
0
        unsafe private static void InitVAC()
        {
            try
            {
                int buf_size = block_size_vac*8;

                if (large_vac_buffer)
                    buf_size = 131072;

                if (rb_vacOUT_l == null || rb_vacOUT_l.Size() != buf_size) rb_vacOUT_l = new RingBufferFloat(buf_size);
                rb_vacOUT_l.Restart(buf_size);

                if (rb_vacOUT_r == null || rb_vacOUT_r.Size() != buf_size) rb_vacOUT_r = new RingBufferFloat(buf_size);
                rb_vacOUT_r.Restart(buf_size);

                if (rb_vacIN_l == null || rb_vacIN_l.Size() != buf_size) rb_vacIN_l = new RingBufferFloat(buf_size);
                rb_vacIN_l.Restart(buf_size);

                if (rb_vacIN_r == null || rb_vacIN_r.Size() != buf_size) rb_vacIN_r = new RingBufferFloat(buf_size);
                rb_vacIN_r.Restart(buf_size);

                if (sample_rateVAC != sample_rate1)
                {
                    vac_resample = true;
                    if (res_outl == null) res_outl = new float[buf_size];
                    if (res_outr == null) res_outr = new float[buf_size];
                    if (res_inl == null) res_inl = new float[2 * buf_size];
                    if (res_inr == null) res_inr = new float[2 * buf_size];

                    resampPtrIn_l = DttSP.NewResamplerF(sample_rateVAC, sample_rate1);
                    resampPtrIn_r = DttSP.NewResamplerF(sample_rateVAC, sample_rate1);

                    if (console.CurrentModel == Model.RTL_SDR)
                    {
                        resampPtrOut_l = DttSP.NewResamplerF(sample_rate1, sample_rateVAC + (int)console.SetupForm.udRTL_VACcorr.Value);
                        resampPtrOut_r = DttSP.NewResamplerF(sample_rate1, sample_rateVAC + (int)console.SetupForm.udRTL_VACcorr.Value);
                    }
                    else
                    {
                        resampPtrOut_l = DttSP.NewResamplerF(sample_rate1, sample_rateVAC);
                        resampPtrOut_r = DttSP.NewResamplerF(sample_rate1, sample_rateVAC);
                    }

                    //DttSP.SetResamplerF(0, 0, sample_rate1, sample_rateVAC);
                    //DttSP.EnableResamplerF(0, 0, 1);   // enable resampler
                }
                else
                {
                    vac_resample = false;
                    //DttSP.EnableResamplerF(0, 0, 0);   // disable resampler
                }

                cs_vac = (void*)0x0;
                cs_vac = Win32.NewCriticalSection();

                if (Win32.InitializeCriticalSectionAndSpinCount(cs_vac, 0x00000080) == 0)
                {
                    vac_enabled = false;
                    VACDebug("VAC CriticalSection Failed!");
                }

                cs_g6_callback = (void*)0x0;
                cs_g6_callback = Win32.NewCriticalSection();

                if (Win32.InitializeCriticalSectionAndSpinCount(cs_g6_callback, 0x00000080) == 0)
                {
                    VACDebug("G6 callback CriticalSection Failed!");
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());

                if (debug && console.ConsoleClosing)
                    VACDebug(ex.ToString());
            }
        }
Example #4
0
		public WaveFileReader(
			WaveControl form,
			int frames,
			int fmt,
			int samp_rate,
			int chan,
			ref BinaryReader binread)
		{
			wave_form = form;
			frames_per_buffer = frames;
			format = fmt;
			sample_rate = samp_rate;
			channels = chan;
			
			//OUT_BLOCK = 2048;
			//IN_BLOCK = (int)Math.Floor(OUT_BLOCK*(double)sample_rate/Audio.SampleRate1);
			//OUT_BLOCK = (int)Math.Ceiling(IN_BLOCK*Audio.SampleRate1/(double)sample_rate);
			IN_BLOCK = 2048;
			OUT_BLOCK = (int)Math.Ceiling(IN_BLOCK*Audio.SampleRate1/(double)sample_rate);
			rb_l = new RingBufferFloat(16*OUT_BLOCK);
			rb_r = new RingBufferFloat(16*OUT_BLOCK);
			buf_l_in = new float[IN_BLOCK];
			buf_r_in = new float[IN_BLOCK];
			buf_l_out = new float[OUT_BLOCK];
			buf_r_out = new float[OUT_BLOCK];
			if(format == 1)
			{
				io_buf_size = IN_BLOCK*2*2;
			}
			else if(format == 3)
			{
				io_buf_size = IN_BLOCK*4*2;
				if(sample_rate != Audio.SampleRate1)
				{
					resamp_l = DttSP.NewResamplerF(sample_rate, Audio.SampleRate1);
					if(channels > 1) resamp_r = DttSP.NewResamplerF(sample_rate, Audio.SampleRate1);
				}
			}
			io_buf = new byte[io_buf_size];

			playback = true;
			reader = binread;

			Thread t = new Thread(new ThreadStart(ProcessBuffers));
			t.Name = "Wave File Read Thread";
			t.IsBackground = true;
			t.Priority = ThreadPriority.Normal;

			do
			{
				ReadBuffer(ref reader);
			} while(rb_l.WriteSpace() > OUT_BLOCK && !eof);

			t.Start();
		}
Example #5
0
		public WaveFileWriter(int frames, short chan, int samp_rate, string file)
		{
			frames_per_buffer = frames;
			channels = chan;
			sample_rate = samp_rate;

			int OUT_BLOCK = (int)Math.Ceiling(IN_BLOCK*(double)sample_rate/Audio.SampleRate1);
			rb_l = new RingBufferFloat(IN_BLOCK*16);
			rb_r = new RingBufferFloat(IN_BLOCK*16);
			in_buf_l = new float[IN_BLOCK];
			in_buf_r = new float[IN_BLOCK];
			out_buf_l = new float[OUT_BLOCK];
			out_buf_r = new float[OUT_BLOCK];
			out_buf = new float[OUT_BLOCK*2];
			byte_buf = new byte[OUT_BLOCK*2*4];
			
			length_counter = 0;
			record = true;

			if(sample_rate != Audio.SampleRate1)
			{
				resamp_l = DttSP.NewResamplerF(Audio.SampleRate1, sample_rate);
				if(channels > 1) resamp_r = DttSP.NewResamplerF(Audio.SampleRate1, sample_rate);
			}

			writer = new BinaryWriter(File.Open(file, FileMode.Create));
			filename = file;

			Thread t = new Thread(new ThreadStart(ProcessRecordBuffers));
			t.Name = "Wave File Write Thread";
			t.IsBackground = true;
			t.Priority = ThreadPriority.Normal;
			t.Start();
		}
Example #6
0
        unsafe public VoiceMsgWaveFileReader(
            VoiceMessages form,
            int frames,
            int fmt,
            int samp_rate,
            int chan,
            ref BinaryReader binread,
            VoiceMessages voice_msg_form)
        {
            VoiceMsgForm = voice_msg_form;
            wave_form = form;
            frames_per_buffer = frames;
            format = fmt;
            sample_rate = samp_rate;
            channels = chan;
            IN_BLOCK = 2048;
            OUT_BLOCK = (int)Math.Ceiling(IN_BLOCK * Audio.SampleRate1 / (double)sample_rate);
            if (OUT_BLOCK < IN_BLOCK)
                OUT_BLOCK = IN_BLOCK;
            rb_l = new RingBufferFloat(16 * OUT_BLOCK);
            rb_r = new RingBufferFloat(16 * OUT_BLOCK);
            buf_l_in = new float[IN_BLOCK];
            buf_r_in = new float[IN_BLOCK];
            buf_l_out = new float[OUT_BLOCK];
            buf_r_out = new float[OUT_BLOCK];

            if (format == 1)
                io_buf_size = 2048 * 2 * 2;
            else if (format == 3)
            {
                io_buf_size = 2048 * 4 * 2;
                if (sample_rate != Audio.SampleRate1)
                {
                    resamp_l = DttSP.NewResamplerF(sample_rate, Audio.SampleRate1);
                    if (channels > 1) resamp_r = DttSP.NewResamplerF(sample_rate, Audio.SampleRate1);
                }
            }

            io_buf = new byte[io_buf_size];

            playback = true;
            reader = binread;

            cs_play_voice = (void*)0x0;
            cs_play_voice = Win32.NewCriticalSection();
            if (Win32.InitializeCriticalSectionAndSpinCount(cs_play_voice, 0x00000080) == 0)
            {
                Debug.WriteLine("Voice Play criticalSection Failed!\n");
            }

            Thread t = new Thread(new ThreadStart(ProcessBuffers));
            t.Name = "Wave File Read Thread";
            t.IsBackground = true;
            t.Priority = ThreadPriority.Normal;
            t.Start();
        }