qipp
2025-11-07 744722688187eb4991c72464e2bb5e06b244fee7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#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);
}