From aa5176e7b43cce014b3077ac7fab6f8f2d124825 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 12 Jan 2017 22:57:53 -0800 Subject: [PATCH] cleanup ptt audio thread when application closed --- audio_ptt_win.c | 5 +++-- config.c | 6 ++++++ ptt.c | 18 +++++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/audio_ptt_win.c b/audio_ptt_win.c index dce3f66..2b044d7 100644 --- a/audio_ptt_win.c +++ b/audio_ptt_win.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -115,13 +116,13 @@ unsigned __stdcall ptt_thread (void *arg) if( save_audio_config_p->adev[a].num_channels == 1 ) { for( i = 0; i < nsamples; i++ ) { - sample = (SHORT)( 32000.0 * sin( ( (double)i / (double)nsamples ) * 2.0 * M_PI ) ); + sample = (SHORT)( (double)SHRT_MAX * sin( ( (double)i / (double)nsamples ) * 2.0 * M_PI ) ); pnData[i] = sample; } } else { for( i = 0; i < nsamples; i++ ) { - sample = (SHORT)( 32000.0 * sin( ( (double)i / (double)nsamples ) * 2.0 * M_PI ) ); + sample = (SHORT)( (double)SHRT_MAX * sin( ( (double)i / (double)nsamples ) * 2.0 * M_PI ) ); if( channel == ADEVFIRSTCHAN( a ) ) { // Stereo, left channel. diff --git a/config.c b/config.c index 0dbe29b..e8b828d 100644 --- a/config.c +++ b/config.c @@ -668,6 +668,12 @@ void config_init (char *fname, struct audio_s *p_audio_config, p_audio_config->achan[channel].octrl[ot].ptt_invert2 = 0; p_audio_config->achan[channel].octrl[ot].ptt_channel = 0; p_audio_config->achan[channel].octrl[ot].ptt_frequency = PTT_FREQ_DEFAULT; +#ifdef __WIN32__ + p_audio_config->achan[channel].octrl[ot].ptt_start = NULL; + p_audio_config->achan[channel].octrl[ot].ptt_stop = NULL; + p_audio_config->achan[channel].octrl[ot].ptt_close = NULL; +#else +#endif } p_audio_config->achan[channel].dwait = DEFAULT_DWAIT; diff --git a/ptt.c b/ptt.c index 73f122e..c948a0b 100644 --- a/ptt.c +++ b/ptt.c @@ -1008,11 +1008,16 @@ void ptt_set (int ot, int chan, int ptt_signal) } #endif + /* + * Using audio channel? + */ + if( save_audio_config_p->achan[chan].octrl[ot].ptt_method == PTT_METHOD_AUDIO ) { if( ptt_signal ) { #ifdef __WIN32__ SetEvent( save_audio_config_p->achan[chan].octrl[ot].ptt_start ); #else + #endif } else @@ -1020,6 +1025,7 @@ void ptt_set (int ot, int chan, int ptt_signal) #ifdef __WIN32__ SetEvent( save_audio_config_p->achan[chan].octrl[ot].ptt_stop ); #else + #endif } } @@ -1110,7 +1116,7 @@ void ptt_term (void) ptt_set (ot, n, 0); } } - } + } for (n = 0; n < MAX_CHANS; n++) { if (save_audio_config_p->achan[n].valid) { @@ -1128,6 +1134,16 @@ void ptt_term (void) } } + for (n = 0; n < MAX_CHANS; n++) { + if (save_audio_config_p->achan[n].octrl[OCTYPE_PTT].ptt_method == PTT_METHOD_AUDIO) { +#ifdef __WIN32__ + SetEvent (save_audio_config_p->achan[n].octrl[OCTYPE_PTT].ptt_close) ; +#else + +#endif + } + } + #ifdef USE_HAMLIB for (n = 0; n < MAX_CHANS; n++) {