Reading and generating square waves at the same time.

I am about to pull my hair out over this. I found a different library that uses the input capture function of timer one to measure frequency and it works great....for reading the frequency that got rid of all my input jitter and is accurate to less than .5 HZ at 6kh...good enough for me. But now i cant use timer 1 to generate the square wave output. I am using it with the blink without delay code and it is causing a glitch every time an edge of the square wave from the input and out put happen at the same time. The library seems to pause the code for a second while it is taking a measurement.

I have been through 10 revisions on the code and I can either get the input solid or the out put solid but not both at the same time. I have tried 3 different ways to read input, Timer 1 input capture, Poling and Using hardware interrupts. And of the 3 input capture is working the best but on its own. With the output I have tried Timer 1 CTC mode(works great), Blink without delay(jitter when code get to long), and timer 2(not enough resolution).

The best i have so far is Input capture timer 1 with blink without delay output but over 1khz the latency and jitter gets bad. The best option would be to use Input capture with timer 1 interrupts on the output but i do think i can use timer 1 twice?

Does anyone have any ideas? My best idea now is to use a DDS generating chip controlled by the arduino to generate the output and the arduino to read the input frequency and do the math. Although i would like to do it all with the arduino.

Here is the code using blink without delay and timer 1 input capture.

#include <FreqPeriod.h>

double inputfrequency;
long int inputperiod;

const byte Speed_output = 8; // the output pin to speedometer

unsigned long previoustime;
unsigned long timeout;

unsigned long period ;
unsigned long interval  = 0 ;      // interval to toggle output
double x = 1.194;        // Correction Factor of Output to 

void setup() 
{  
  pinMode(Speed_output, OUTPUT);      // Output pin 7 to sink current from speedometer
  FreqPeriod::begin(); 
}

void loop()
{ 
  
   inputperiod=FreqPeriod::getPeriod();
   
  if (inputperiod )
  {
    inputfrequency= 15972400.0 / inputperiod;
    timeout =millis();
    period = (inputperiod/16);
    interval=(period/2);  
  }
  
  unsigned long currenttime = micros();
  if(currenttime - previoustime >= interval) 
   {
      previoustime += interval;   // save the last time you change state
      PINB = 0b00000001; // toggle output pin D8 
   }
  
  unsigned long CT = millis(); // time out if no signal
   if (CT - timeout > 600)
  {
   interval=1000000000;
  } 
}