2 * Audio support data for ISDN4Linux.
4 * Copyright 2002/2003 by Andreas Eversberg (jolly@eversberg.eu)
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
11 #define DEBUG_DSP_CTRL 0x0001
12 #define DEBUG_DSP_CORE 0x0002
13 #define DEBUG_DSP_DTMF 0x0004
14 #define DEBUG_DSP_CMX 0x0010
15 #define DEBUG_DSP_TONE 0x0020
16 #define DEBUG_DSP_BLOWFISH 0x0040
17 #define DEBUG_DSP_DELAY 0x0100
18 #define DEBUG_DSP_CLOCK 0x0200
19 #define DEBUG_DSP_DTMFCOEFF 0x8000 /* heavy output */
23 * bit 0 = use ulaw instead of alaw
24 * bit 1 = enable hfc hardware accelleration for all channels
27 #define DSP_OPT_ULAW (1<<0)
28 #define DSP_OPT_NOHARDWARE (1<<1)
30 #include <linux/timer.h>
31 #include <linux/workqueue.h>
33 #include "dsp_ecdis.h"
35 extern int dsp_options
;
39 extern spinlock_t dsp_lock
;
40 extern struct work_struct dsp_workq
;
41 extern u32 dsp_poll_diff
; /* calculated fix-comma corrected poll value */
47 extern s32 dsp_audio_alaw_to_s32
[256];
48 extern s32 dsp_audio_ulaw_to_s32
[256];
49 extern s32
*dsp_audio_law_to_s32
;
50 extern u8 dsp_audio_s16_to_law
[65536];
51 extern u8 dsp_audio_alaw_to_ulaw
[256];
52 extern u8 dsp_audio_mix_law
[65536];
53 extern u8 dsp_audio_seven2law
[128];
54 extern u8 dsp_audio_law2seven
[256];
55 extern void dsp_audio_generate_law_tables(void);
56 extern void dsp_audio_generate_s2law_table(void);
57 extern void dsp_audio_generate_seven(void);
58 extern void dsp_audio_generate_mix_table(void);
59 extern void dsp_audio_generate_ulaw_samples(void);
60 extern void dsp_audio_generate_volume_changes(void);
61 extern u8 dsp_silence
;
68 #define MAX_POLL 256 /* maximum number of send-chunks */
70 #define CMX_BUFF_SIZE 0x8000 /* must be 2**n (0x1000 about 1/2 second) */
71 #define CMX_BUFF_HALF 0x4000 /* CMX_BUFF_SIZE / 2 */
72 #define CMX_BUFF_MASK 0x7fff /* CMX_BUFF_SIZE - 1 */
74 /* how many seconds will we check the lowest delay until the jitter buffer
75 is reduced by that delay */
76 #define MAX_SECONDS_JITTER_CHECK 5
78 extern struct timer_list dsp_spl_tl
;
79 extern u32 dsp_spl_jiffies
;
81 /* the structure of conferences:
83 * each conference has a unique number, given by user space.
84 * the conferences are linked in a chain.
85 * each conference has members linked in a chain.
86 * each dsplayer points to a member, each member points to a dsplayer.
89 /* all members within a conference (this is linked 1:1 with the dsp) */
91 struct dsp_conf_member
{
92 struct list_head list
;
96 /* the list of all conferences */
98 struct list_head list
;
100 /* all cmx stacks with the same ID are
102 struct list_head mlist
;
103 int software
; /* conf is processed by software */
104 int hardware
; /* conf is processed by hardware */
105 /* note: if both unset, has only one member */
113 #define DSP_DTMF_NPOINTS 102
115 #define ECHOCAN_BUFLEN (4*128)
118 int treshold
; /* above this is dtmf (square of) */
119 int software
; /* dtmf uses software decoding */
120 int hardware
; /* dtmf uses hardware decoding */
121 int size
; /* number of bytes in buffer */
122 signed short buffer
[DSP_DTMF_NPOINTS
];
123 /* buffers one full dtmf frame */
124 u8 lastwhat
, lastdigit
;
126 u8 digits
[16]; /* just the dtmf result */
133 struct dsp_pipeline
{
135 struct list_head list
;
144 int software
; /* tones are generated by software */
145 int hardware
; /* tones are generated by hardware */
150 struct timer_list tl
;
158 struct list_head list
;
159 struct mISDNchannel ch
;
160 struct mISDNchannel
*up
;
161 unsigned char name
[64];
163 int echo
; /* echo is enabled */
164 int rx_disabled
; /* what the user wants */
165 int rx_is_off
; /* what the card is */
167 struct dsp_tone tone
;
168 struct dsp_dtmf dtmf
;
169 int tx_volume
, rx_volume
;
171 /* queue for sending frames */
172 struct work_struct workq
;
173 struct sk_buff_head sendq
;
174 int hdlc
; /* if mode is hdlc */
175 int data_pending
; /* currently an unconfirmed frame */
177 /* conference stuff */
179 struct dsp_conf
*conf
;
180 struct dsp_conf_member
184 int rx_W
; /* current write pos for data without timestamp */
185 int rx_R
; /* current read pos for transmit clock */
186 int rx_init
; /* if set, pointers will be adjusted first */
187 int tx_W
; /* current write pos for transmit data */
188 int tx_R
; /* current read pos for transmit clock */
189 int rx_delay
[MAX_SECONDS_JITTER_CHECK
];
190 int tx_delay
[MAX_SECONDS_JITTER_CHECK
];
191 u8 tx_buff
[CMX_BUFF_SIZE
];
192 u8 rx_buff
[CMX_BUFF_SIZE
];
193 int last_tx
; /* if set, we transmitted last poll interval */
194 int cmx_delay
; /* initial delay of buffers,
195 or 0 for dynamic jitter buffer */
196 int tx_dejitter
; /* if set, dejitter tx buffer */
197 int tx_data
; /* enables tx-data of CMX to upper layer */
200 struct dsp_features features
;
201 int features_rx_off
; /* set if rx_off is featured */
202 int features_fill_empty
; /* set if fill_empty is featured */
203 int pcm_slot_rx
; /* current PCM slot (or -1) */
207 int hfc_conf
; /* unique id of current conference (or -1) */
209 /* encryption stuff */
216 int bf_decrypt_in_pos
;
217 int bf_decrypt_out_pos
;
218 u8 bf_crypt_inring
[16];
228 extern void dsp_change_volume(struct sk_buff
*skb
, int volume
);
230 extern struct list_head dsp_ilist
;
231 extern struct list_head conf_ilist
;
232 extern void dsp_cmx_debug(struct dsp
*dsp
);
233 extern void dsp_cmx_hardware(struct dsp_conf
*conf
, struct dsp
*dsp
);
234 extern int dsp_cmx_conf(struct dsp
*dsp
, u32 conf_id
);
235 extern void dsp_cmx_receive(struct dsp
*dsp
, struct sk_buff
*skb
);
236 extern void dsp_cmx_hdlc(struct dsp
*dsp
, struct sk_buff
*skb
);
237 extern void dsp_cmx_send(void *arg
);
238 extern void dsp_cmx_transmit(struct dsp
*dsp
, struct sk_buff
*skb
);
239 extern int dsp_cmx_del_conf_member(struct dsp
*dsp
);
240 extern int dsp_cmx_del_conf(struct dsp_conf
*conf
);
242 extern void dsp_dtmf_goertzel_init(struct dsp
*dsp
);
243 extern void dsp_dtmf_hardware(struct dsp
*dsp
);
244 extern u8
*dsp_dtmf_goertzel_decode(struct dsp
*dsp
, u8
*data
, int len
,
247 extern int dsp_tone(struct dsp
*dsp
, int tone
);
248 extern void dsp_tone_copy(struct dsp
*dsp
, u8
*data
, int len
);
249 extern void dsp_tone_timeout(void *arg
);
251 extern void dsp_bf_encrypt(struct dsp
*dsp
, u8
*data
, int len
);
252 extern void dsp_bf_decrypt(struct dsp
*dsp
, u8
*data
, int len
);
253 extern int dsp_bf_init(struct dsp
*dsp
, const u8
*key
, unsigned int keylen
);
254 extern void dsp_bf_cleanup(struct dsp
*dsp
);
256 extern int dsp_pipeline_module_init(void);
257 extern void dsp_pipeline_module_exit(void);
258 extern int dsp_pipeline_init(struct dsp_pipeline
*pipeline
);
259 extern void dsp_pipeline_destroy(struct dsp_pipeline
*pipeline
);
260 extern int dsp_pipeline_build(struct dsp_pipeline
*pipeline
, const char *cfg
);
261 extern void dsp_pipeline_process_tx(struct dsp_pipeline
*pipeline
, u8
*data
,
263 extern void dsp_pipeline_process_rx(struct dsp_pipeline
*pipeline
, u8
*data
,