分支自 DSP/ADSP21569/DSP-21569

graydon
2024-02-28 420778fcee054257d540cf24fbf1b1e3f9fc0d9f
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
#include <string.h>
#include "config.h"
#include "f2f.h"
#include "../drv/sport.h"
 
extern u16 mCodecNum ;
extern struct AudioCodec mAudioCodec[16];
 
static u16    mInputNum = 0;
static u16    mOutputNum = 0;
static ufloat* mRxChannel[MAX_INPUT_NUM];
static ufloat* mTxChannel[MAX_OUTPUT_NUM];
 
 
uvoid SetNumOfChannels(u16 rxNum, u16 txNum)
{
    if(rxNum > MAX_INPUT_NUM) rxNum = MAX_INPUT_NUM;
    if(txNum > MAX_OUTPUT_NUM) txNum = MAX_OUTPUT_NUM;
 
    mInputNum = rxNum;
    mOutputNum = txNum;
}
 
 
inline uvoid floatData(ufloat *output, const s32 *input, u32 instep, u32 length)
{
    for(u32 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 uvoid fixData(s32 *output, const ufloat *input, u32 outstep, u32 length)
{
    for(u32 i = 0; i < length; i++)
    {
        output[outstep*i] = __builtin_conv_FtoR(input[i]);
    }
}
 
 
 
uvoid SetRxChannelPtr(u32 channel ,ufloat* rxBuffer)
{
    if (channel < MAX_INPUT_NUM) {
        mRxChannel[channel] = rxBuffer;
    }
}
 
uvoid SetTxChannelPtr(u32 channel, ufloat* txBuffer)
{
    if (channel < MAX_OUTPUT_NUM) {
        mTxChannel[channel] = txBuffer;
    }
}
 
 
uvoid SetTxRxNullBufferPtr()
{
    memset(mRxChannel, 0, sizeof(ufloat*)*MAX_INPUT_NUM);
    memset(mTxChannel, 0, sizeof(ufloat*)*MAX_OUTPUT_NUM);
}
 
uvoid MuteOutput()
{
//    for(u32 i =0 ;i< mOutputNum;i++) {
//        memset(mTxChannel[i],0 , SAMPLE_NUM*sizeof(ufloat));
//    }
    for(u32 i =0 ;i < mCodecNum ;i++) {
        struct AudioCodec* codec = &mAudioCodec[i];
 
        if(codec->rx == ufalse) {
            s32* dataPtr0 = codec->dataPtr[0] ;
            s32* dataPtr1 = codec->dataPtr[1] ;
 
            if(codec->enable_sec){
                memset(dataPtr0, 0 ,sizeof(s32)*codec->slot_num*2*SAMPLE_NUM);
                memset(dataPtr1, 0 ,sizeof(s32)*codec->slot_num*2*SAMPLE_NUM);
            }
            else{
                memset(dataPtr0, 0 ,sizeof(s32)*codec->slot_num*SAMPLE_NUM);
                memset(dataPtr1, 0 ,sizeof(s32)*codec->slot_num*SAMPLE_NUM);
            }
        }
    }
}
 
#define CHANNEL_OF(c) (2*((c)&(codec->slot_num-1))+ (c)/codec->slot_num)
#define OFFSET(j) (j<codec->channel_num?CHANNEL_OF(j): CHANNEL_OF(j-codec->channel_num+codec->slot_num))
/*
 * sec ÅÅÁз½Ê½: 0,16,1,17,2,18,...,15,31
 */
uvoid UpdateInput(u32 blockIndex)
{
    u32 channel = 0;
 
    for(u32 i =0 ;i < mCodecNum ;i++) {
        struct AudioCodec* codec = &mAudioCodec[i];
 
        if(codec->rx) {
            s32* dataPtr = codec->dataPtr[blockIndex] ;
 
            if(codec->enable_sec){
                for(u32 j = 0; channel < mInputNum && j < codec->channel_num*2 ;j ++,channel++) {
                    if(mRxChannel[channel] != NULL)
                        floatData(mRxChannel[channel], dataPtr + OFFSET(j),codec->slot_num*2, SAMPLE_NUM);
                }
            }
            else{
                for(u32 j = 0; channel < mInputNum && j < codec->channel_num ;j ++,channel++) {
                    if(mRxChannel[channel] != NULL)
                        floatData(mRxChannel[channel], dataPtr + j,codec->slot_num, SAMPLE_NUM);
                }
            }
        }
    }
 
}
 
uvoid UpdateOutput(u32 blockIndex)
{
    u32 channel = 0;
 
    for(u32 i =0 ;i < mCodecNum ;i++) {
        struct AudioCodec* codec = &mAudioCodec[i];
 
        if(codec->rx == ufalse) {
            s32* dataPtr = codec->dataPtr[blockIndex] ;
 
            if(codec->enable_sec){
                for(u32 j = 0; channel < mOutputNum && j < codec->channel_num*2 ;j ++,channel++) {
                    if(mTxChannel[channel] != NULL)
                        fixData(dataPtr +OFFSET(j), mTxChannel[channel], codec->slot_num*2, SAMPLE_NUM);
                }
            }
            else{
                for(u32 j = 0; channel < mOutputNum && j < codec->channel_num ;j ++,channel++) {
                    if(mTxChannel[channel] != NULL)
                        fixData(dataPtr + j, mTxChannel[channel], codec->slot_num, SAMPLE_NUM);
                }
            }
        }
    }
}