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_DTMFCOEFF 0x8000 /* heavy output */
22 * bit 0 = use ulaw instead of alaw
23 * bit 1 = enable hfc hardware accelleration for all channels
26 #define DSP_OPT_ULAW (1<<0)
27 #define DSP_OPT_NOHARDWARE (1<<1)
29 #include <linux/timer.h>
30 #include <linux/workqueue.h>
32 #include "dsp_ecdis.h"
34 extern int dsp_options;
38 extern spinlock_t dsp_lock;
39 extern struct work_struct dsp_workq;
40 extern u32 dsp_poll_diff; /* calculated fix-comma corrected poll value */
46 extern s32 dsp_audio_alaw_to_s32[256];
47 extern s32 dsp_audio_ulaw_to_s32[256];
48 extern s32 *dsp_audio_law_to_s32;
49 extern u8 dsp_audio_s16_to_law[65536];
50 extern u8 dsp_audio_alaw_to_ulaw[256];
51 extern u8 dsp_audio_mix_law[65536];
52 extern u8 dsp_audio_seven2law[128];
53 extern u8 dsp_audio_law2seven[256];
54 extern void dsp_audio_generate_law_tables(void);
55 extern void dsp_audio_generate_s2law_table(void);
56 extern void dsp_audio_generate_seven(void);
57 extern void dsp_audio_generate_mix_table(void);
58 extern void dsp_audio_generate_ulaw_samples(void);
59 extern void dsp_audio_generate_volume_changes(void);
60 extern u8 dsp_silence;
67 #define MAX_POLL 256 /* maximum number of send-chunks */
69 #define CMX_BUFF_SIZE 0x8000 /* must be 2**n (0x1000 about 1/2 second) */
70 #define CMX_BUFF_HALF 0x4000 /* CMX_BUFF_SIZE / 2 */
71 #define CMX_BUFF_MASK 0x7fff /* CMX_BUFF_SIZE - 1 */
73 /* how many seconds will we check the lowest delay until the jitter buffer
74 is reduced by that delay */
75 #define MAX_SECONDS_JITTER_CHECK 5
77 extern struct timer_list dsp_spl_tl;
78 extern u32 dsp_spl_jiffies;
80 /* the structure of conferences:
82 * each conference has a unique number, given by user space.
83 * the conferences are linked in a chain.
84 * each conference has members linked in a chain.
85 * each dsplayer points to a member, each member points to a dsplayer.
88 /* all members within a conference (this is linked 1:1 with the dsp) */
90 struct dsp_conf_member {
91 struct list_head list;
95 /* the list of all conferences */
97 struct list_head list;
99 /* all cmx stacks with the same ID are
101 struct list_head mlist;
102 int software; /* conf is processed by software */
103 int hardware; /* conf is processed by hardware */
104 /* note: if both unset, has only one member */
112 #define DSP_DTMF_NPOINTS 102
114 #define ECHOCAN_BUFLEN (4*128)
117 int treshold; /* above this is dtmf (square of) */
118 int software; /* dtmf uses software decoding */
119 int hardware; /* dtmf uses hardware decoding */
120 int size; /* number of bytes in buffer */
121 signed short buffer[DSP_DTMF_NPOINTS];
122 /* buffers one full dtmf frame */
123 u8 lastwhat, lastdigit;
125 u8 digits[16]; /* just the dtmf result */
132 struct dsp_pipeline {
134 struct list_head list;
143 int software; /* tones are generated by software */
144 int hardware; /* tones are generated by hardware */
149 struct timer_list tl;
157 struct list_head list;
158 struct mISDNchannel ch;
159 struct mISDNchannel *up;
160 unsigned char name[64];
162 int echo; /* echo is enabled */
163 int rx_disabled; /* what the user wants */
164 int rx_is_off; /* what the card is */
166 struct dsp_tone tone;
167 struct dsp_dtmf dtmf;
168 int tx_volume, rx_volume;
170 /* queue for sending frames */
171 struct work_struct workq;
172 struct sk_buff_head sendq;
173 int hdlc; /* if mode is hdlc */
174 int data_pending; /* currently an unconfirmed frame */
176 /* conference stuff */
178 struct dsp_conf *conf;
179 struct dsp_conf_member
183 int rx_W; /* current write pos for data without timestamp */
184 int rx_R; /* current read pos for transmit clock */
185 int rx_init; /* if set, pointers will be adjusted first */
186 int tx_W; /* current write pos for transmit data */
187 int tx_R; /* current read pos for transmit clock */
188 int rx_delay[MAX_SECONDS_JITTER_CHECK];
189 int tx_delay[MAX_SECONDS_JITTER_CHECK];
190 u8 tx_buff[CMX_BUFF_SIZE];
191 u8 rx_buff[CMX_BUFF_SIZE];
192 int last_tx; /* if set, we transmitted last poll interval */
193 int cmx_delay; /* initial delay of buffers,
194 or 0 for dynamic jitter buffer */
195 int tx_dejitter; /* if set, dejitter tx buffer */
196 int tx_data; /* enables tx-data of CMX to upper layer */
199 struct dsp_features features;
200 int features_rx_off; /* set if rx_off is featured */
201 int pcm_slot_rx; /* current PCM slot (or -1) */
205 int hfc_conf; /* unique id of current conference (or -1) */
207 /* encryption stuff */
214 int bf_decrypt_in_pos;
215 int bf_decrypt_out_pos;
216 u8 bf_crypt_inring[16];
226 extern void dsp_change_volume(struct sk_buff *skb, int volume);
228 extern struct list_head dsp_ilist;
229 extern struct list_head conf_ilist;
230 extern void dsp_cmx_debug(struct dsp *dsp);
231 extern void dsp_cmx_hardware(struct dsp_conf *conf, struct dsp *dsp);
232 extern int dsp_cmx_conf(struct dsp *dsp, u32 conf_id);
233 extern void dsp_cmx_receive(struct dsp *dsp, struct sk_buff *skb);
234 extern void dsp_cmx_hdlc(struct dsp *dsp, struct sk_buff *skb);
235 extern void dsp_cmx_send(void *arg);
236 extern void dsp_cmx_transmit(struct dsp *dsp, struct sk_buff *skb);
237 extern int dsp_cmx_del_conf_member(struct dsp *dsp);
238 extern int dsp_cmx_del_conf(struct dsp_conf *conf);
240 extern void dsp_dtmf_goertzel_init(struct dsp *dsp);
241 extern void dsp_dtmf_hardware(struct dsp *dsp);
242 extern u8 *dsp_dtmf_goertzel_decode(struct dsp *dsp, u8 *data, int len,
245 extern int dsp_tone(struct dsp *dsp, int tone);
246 extern void dsp_tone_copy(struct dsp *dsp, u8 *data, int len);
247 extern void dsp_tone_timeout(void *arg);
249 extern void dsp_bf_encrypt(struct dsp *dsp, u8 *data, int len);
250 extern void dsp_bf_decrypt(struct dsp *dsp, u8 *data, int len);
251 extern int dsp_bf_init(struct dsp *dsp, const u8 *key, unsigned int keylen);
252 extern void dsp_bf_cleanup(struct dsp *dsp);
254 extern int dsp_pipeline_module_init(void);
255 extern void dsp_pipeline_module_exit(void);
256 extern int dsp_pipeline_init(struct dsp_pipeline *pipeline);
257 extern void dsp_pipeline_destroy(struct dsp_pipeline *pipeline);
258 extern int dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg);
259 extern void dsp_pipeline_process_tx(struct dsp_pipeline *pipeline, u8 *data,
261 extern void dsp_pipeline_process_rx(struct dsp_pipeline *pipeline, u8 *data,