#include <string.h>
|
#include "drv/global.h"
|
#include "f2f.h"
|
#include "jitter.h"
|
#include <alg.h>
|
#include <math.h>
|
|
|
#define MAX_LOGIC_CHANNEL 36
|
|
extern int dual_dsp;
|
extern int dsp_index;
|
|
static float rx_channel[MAX_LOGIC_CHANNEL][NUM_SAMPLES];
|
static float tx_channel[MAX_LOGIC_CHANNEL][NUM_SAMPLES];
|
|
extern int sport1a_buf[2][NUM_SAMPLES*SLOTS];
|
extern int sport1b_buf[2][NUM_SAMPLES*SLOTS];
|
|
//usb
|
extern int sport2a_buf[2][NUM_SAMPLES*2];
|
extern int sport4a_buf[2][NUM_SAMPLES*2];
|
extern int sport5a_buf[2][NUM_SAMPLES*2];
|
|
extern int sport0a_buf[2][NUM_SAMPLES*SLOTS];
|
extern int sport0b_buf[2][NUM_SAMPLES*SLOTS];
|
|
|
|
|
extern int local_input_channels_num ;
|
extern int local_output_channels_num ;
|
extern int dante_input_channels_num ;
|
extern int dante_output_channels_num ;
|
|
|
//extern jitter_mem* pusb_input_jitter ;
|
//extern jitter_mem* pusb_output_jitter ;
|
float usb_input[NUM_SAMPLES], usb_output[NUM_SAMPLES];
|
|
|
float* rx_channel_ptr[]={
|
rx_channel[0],rx_channel[1],rx_channel[2],rx_channel[3]
|
,rx_channel[4],rx_channel[5],rx_channel[6],rx_channel[7]
|
,rx_channel[8],rx_channel[9],rx_channel[10] , rx_channel[11]
|
,rx_channel[12],rx_channel[13], rx_channel[14] ,rx_channel[15]
|
,rx_channel[16] ,rx_channel[17], rx_channel[18], rx_channel[19]
|
,rx_channel[20] ,rx_channel[21] ,rx_channel[22] ,rx_channel[23]
|
,rx_channel[24] ,rx_channel[25] ,rx_channel[26] ,rx_channel[27]
|
,rx_channel[28] ,rx_channel[29] ,rx_channel[30] ,rx_channel[31]
|
,rx_channel[32] ,rx_channel[33], rx_channel[34] ,rx_channel[35]
|
};
|
|
float* tx_channel_ptr[]={
|
tx_channel[0] ,tx_channel[1] ,tx_channel[2] ,tx_channel[3]
|
,tx_channel[4] ,tx_channel[5] ,tx_channel[6] ,tx_channel[7]
|
,tx_channel[8] ,tx_channel[9] ,tx_channel[10] ,tx_channel[11]
|
,tx_channel[12] ,tx_channel[13] ,tx_channel[14] ,tx_channel[15]
|
,tx_channel[16] ,tx_channel[17], tx_channel[18] ,tx_channel[19]
|
,tx_channel[20] ,tx_channel[21] ,tx_channel[22] ,tx_channel[23]
|
,tx_channel[24] ,tx_channel[25] ,tx_channel[26] ,tx_channel[27]
|
,tx_channel[28] ,tx_channel[29] ,tx_channel[30] ,tx_channel[31]
|
,tx_channel[32] ,tx_channel[33], tx_channel[34] ,tx_channel[35]
|
};
|
|
// Structures to hold floating point data for each AD1939
|
//ad1939_float_data fBlockA;
|
|
inline void floatData(float *output, const int *input, unsigned int instep, unsigned int length)
|
{
|
int i;
|
|
|
for(i = 0; i < length; i++)
|
{
|
output[i] = __builtin_conv_RtoF(input[instep*i]);
|
}
|
}
|
|
|
// Unoptimized function to convert the outgoing floating-point data to 1.31 fixed-point format.
|
inline void fixData(int *output, const float *input, unsigned int outstep, unsigned int length)
|
{
|
int i;
|
|
for(i = 0; i < length; i++)
|
{
|
output[outstep*i] = __builtin_conv_FtoR(input[i]);
|
}
|
}
|
|
|
void input_fflush(const unsigned int blockIndex)
|
{
|
extern int input_num_channels;
|
extern int usb_dma_count, dma_count;
|
|
floatData( get_rx_channel(0), sport1a_buf[blockIndex]+7,SLOTS, NUM_SAMPLES);
|
floatData( get_rx_channel(1), sport1a_buf[blockIndex]+6,SLOTS, NUM_SAMPLES);
|
|
floatData( get_rx_channel(2), sport1a_buf[blockIndex]+5,SLOTS, NUM_SAMPLES);
|
floatData( get_rx_channel(3), sport1a_buf[blockIndex]+4,SLOTS, NUM_SAMPLES);
|
|
if(input_num_channels > 4){
|
floatData( get_rx_channel(4), sport1a_buf[blockIndex]+3,SLOTS, NUM_SAMPLES);
|
floatData( get_rx_channel(5), sport1a_buf[blockIndex]+2,SLOTS, NUM_SAMPLES);
|
|
floatData( get_rx_channel(6), sport1a_buf[blockIndex]+1,SLOTS, NUM_SAMPLES);
|
floatData( get_rx_channel(7), sport1a_buf[blockIndex]+0,SLOTS, NUM_SAMPLES);
|
}
|
|
if(input_num_channels > 8) {
|
floatData( get_rx_channel(8), sport1b_buf[blockIndex]+7,SLOTS, NUM_SAMPLES);
|
floatData( get_rx_channel(9), sport1b_buf[blockIndex]+6,SLOTS, NUM_SAMPLES);
|
|
floatData( get_rx_channel(10), sport1b_buf[blockIndex]+5,SLOTS, NUM_SAMPLES);
|
floatData( get_rx_channel(11), sport1b_buf[blockIndex]+4,SLOTS, NUM_SAMPLES);
|
|
floatData( get_rx_channel(12), sport1b_buf[blockIndex]+3,SLOTS, NUM_SAMPLES);
|
floatData( get_rx_channel(13), sport1b_buf[blockIndex]+2,SLOTS, NUM_SAMPLES);
|
|
floatData( get_rx_channel(14), sport1b_buf[blockIndex]+1,SLOTS, NUM_SAMPLES);
|
floatData( get_rx_channel(15), sport1b_buf[blockIndex]+0,SLOTS, NUM_SAMPLES);
|
}
|
|
memcpy(get_rx_channel(input_num_channels+1), usb_input, NUM_SAMPLES);
|
|
}
|
|
|
void usb_input_fflush(const unsigned int blockIndex)
|
{
|
int i=0;
|
float diff =0;
|
float f =0;
|
|
floatData(usb_input, sport5a_buf[blockIndex]+0,2, NUM_SAMPLES);//
|
|
for(i=1;i<NUM_SAMPLES;i++) {
|
f = fabs(usb_input[i] - usb_input[i-1]);
|
if(f > diff){
|
diff = f;
|
}
|
}
|
|
if(diff <= 0.00001){
|
memset(usb_input, 0, NUM_SAMPLES);
|
}
|
}
|
|
|
void usb_output_fflush(const unsigned int blockIndex)
|
{
|
|
fixData(sport4a_buf[blockIndex]+0, usb_output, 2, NUM_SAMPLES);
|
fixData(sport4a_buf[blockIndex]+1, usb_output, 2, NUM_SAMPLES);
|
}
|
|
void output_empty(void)
|
{
|
int i;
|
|
for(i=0;i<MAX_LOGIC_CHANNEL;i++){
|
memset(get_rx_channel(i),0,NUM_SAMPLES);
|
}
|
}
|
|
|
|
void output_fflush(const unsigned int blockIndex)
|
{
|
extern int output_num_channels;
|
|
#if 0
|
#include <math.h>
|
int i;
|
float pcm[NUM_SAMPLES];
|
// float pcm2[NUM_SAMPLES];
|
static int t=0;
|
|
for(i=0;i<NUM_SAMPLES;i++){
|
pcm[i] = 0.5*sinf(2*3.1415926*1000*t/48000);
|
// pcm2[i]=0xbebeafad;
|
t++;
|
}
|
if(t>=48000){
|
t =0;
|
}
|
#endif
|
fixData(sport0a_buf[blockIndex]+7, get_rx_channel(0), SLOTS, NUM_SAMPLES);
|
fixData(sport0a_buf[blockIndex]+6, get_rx_channel(1), SLOTS, NUM_SAMPLES);
|
fixData(sport0a_buf[blockIndex]+5, get_rx_channel(2), SLOTS, NUM_SAMPLES);
|
fixData(sport0a_buf[blockIndex]+4, get_rx_channel(3), SLOTS, NUM_SAMPLES);
|
fixData(sport0a_buf[blockIndex]+3, get_rx_channel(4), SLOTS, NUM_SAMPLES);
|
fixData(sport0a_buf[blockIndex]+2, get_rx_channel(5), SLOTS, NUM_SAMPLES);
|
fixData(sport0a_buf[blockIndex]+1, get_rx_channel(6), SLOTS, NUM_SAMPLES);
|
fixData(sport0a_buf[blockIndex]+0, get_rx_channel(7), SLOTS, NUM_SAMPLES);
|
|
if(output_num_channels > 8) {
|
fixData(sport0b_buf[blockIndex]+7, get_rx_channel(8), SLOTS, NUM_SAMPLES);
|
fixData(sport0b_buf[blockIndex]+6, get_rx_channel(9), SLOTS, NUM_SAMPLES);
|
fixData(sport0b_buf[blockIndex]+5, get_rx_channel(10), SLOTS, NUM_SAMPLES);
|
fixData(sport0b_buf[blockIndex]+4, get_rx_channel(11), SLOTS, NUM_SAMPLES);
|
fixData(sport0b_buf[blockIndex]+3, get_rx_channel(12), SLOTS, NUM_SAMPLES);
|
fixData(sport0b_buf[blockIndex]+2, get_rx_channel(13), SLOTS, NUM_SAMPLES);
|
fixData(sport0b_buf[blockIndex]+1, get_rx_channel(14), SLOTS, NUM_SAMPLES);
|
fixData(sport0b_buf[blockIndex]+0, get_rx_channel(15), SLOTS, NUM_SAMPLES);
|
}
|
|
//to usb.
|
memcpy(usb_output,get_rx_channel(output_num_channels) ,NUM_SAMPLES);
|
}
|