DttSP_EXP void NewKeyer (REAL freq, BOOLEAN niambic, REAL gain, REAL ramp, REAL wpm, REAL SampleRate) { BOOL out; //fprintf(stderr,"NewKeyer\n"); kl = newKeyerLogic (); ks = newKeyerState (); ks->flag.iambic = niambic; ks->flag.revpdl = TRUE; // depends on port wiring ks->flag.autospace.khar = ks->flag.autospace.word = FALSE; ks->flag.mdlmdB = TRUE; ks->flag.memory.dah = TRUE; ks->flag.memory.dit = TRUE; ks->debounce = 1; // could be more if sampled faster ks->mode = MODE_B; ks->weight = 50; ks->wpm = wpm; iambic = niambic; cs_cw = &CS_CW; out = InitializeCriticalSectionAndSpinCount (cs_cw, 0x00000080); update_ok = &UPDATE_OK; out = InitializeCriticalSectionAndSpinCount (update_ok, 0x00000080); #ifndef INTERLEAVED lring = ringb_float_create (RING_SIZE); rring = ringb_float_create (RING_SIZE); #else lring = ringb_float_create (2 * RING_SIZE); #endif sem_init (&clock_fired, 0, 0); sem_init (&poll_fired, 0, 0); sem_init (&keyer_started, 0, 0); if (HiPerformance) { key_poll_period = 1; TONE_SIZE = 48 * (int) (uni[0].samplerate / 48000.0); } else { key_poll_period = 5; TONE_SIZE = 240 * (int) (uni[0].samplerate / 48000.0); } //------------------------------------------------------------ SAMP_RATE = SampleRate; delCWToneGen(gen); gen = newCWToneGen (gain, freq, ramp, ramp, TONE_SIZE, SampleRate); //------------------------------------------------------------ // if (timeSetEvent(5,1,(LPTIMECALLBACK)timer_callback,(DWORD_PTR)NULL,TIME_PERIODIC) == (MMRESULT)NULL) { // fprintf(stderr,"Timer failed\n"),fflush(stderr); // } }
DttSP_EXP void SetKeyerPerf (BOOLEAN hiperf) { int rc; pthread_t tmp_timer; //fprintf(stderr,"SetKeyerPerf\n"); tmp_timer = timerid; if (timerid != 0) { EnterCriticalSection(update_ok); timeKillEvent ((UINT) timerid); timerid = 0; sleep (11); LeaveCriticalSection(update_ok); } delCWToneGen (gen); if (hiperf) { HiPerformance = TRUE; key_poll_period = 1; TONE_SIZE = 48; } else { HiPerformance = FALSE; key_poll_period = 5; TONE_SIZE = 240; } gen = newCWToneGen (gain, freq, ramp, ramp, TONE_SIZE, SAMP_RATE); if (tmp_timer != 0) { #ifndef INTERLEAVED EnterCriticalSection(cs_cw); ringb_float_restart (lring, SIZEBUF); ringb_float_restart (rring, SIZEBUF); LeaveCriticalSection(cs_cw); #else ringb_float_restart (lring, SIZEBUF); #endif rc=pthread_create(&timerid,NULL,timer_thread,NULL); //if ((timerid = // timeSetEvent (key_poll_period, 1, // (LPTIMECALLBACK) timer_callback, // (DWORD_PTR) NULL, TIME_PERIODIC)) == (MMRESULT) NULL) if(rc!=0) fprintf (stderr, "Timer failed\n"), fflush (stderr); } }
DttSP_EXP void SetKeyerSampleRate (REAL sr) { int factor = (int) (sr / 48000.0f); if (HiPerformance) { key_poll_period = 1; TONE_SIZE = 48 * factor; } else { key_poll_period = 5; TONE_SIZE = 240 * factor; } SIZEBUF = 768 * factor; delCWToneGen (gen); gen = newCWToneGen (gain, freq, ramp, ramp, TONE_SIZE, sr); }