dsp.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * Audio support data for ISDN4Linux.
  3. *
  4. * Copyright 2002/2003 by Andreas Eversberg (jolly@eversberg.eu)
  5. *
  6. * This software may be used and distributed according to the terms
  7. * of the GNU General Public License, incorporated herein by reference.
  8. *
  9. */
  10. #define DEBUG_DSP_CTRL 0x0001
  11. #define DEBUG_DSP_CORE 0x0002
  12. #define DEBUG_DSP_DTMF 0x0004
  13. #define DEBUG_DSP_CMX 0x0010
  14. #define DEBUG_DSP_TONE 0x0020
  15. #define DEBUG_DSP_BLOWFISH 0x0040
  16. #define DEBUG_DSP_DELAY 0x0100
  17. #define DEBUG_DSP_CLOCK 0x0200
  18. #define DEBUG_DSP_DTMFCOEFF 0x8000 /* heavy output */
  19. /* options may be:
  20. *
  21. * bit 0 = use ulaw instead of alaw
  22. * bit 1 = enable hfc hardware accelleration for all channels
  23. *
  24. */
  25. #define DSP_OPT_ULAW (1<<0)
  26. #define DSP_OPT_NOHARDWARE (1<<1)
  27. #include <linux/timer.h>
  28. #include <linux/workqueue.h>
  29. #include "dsp_ecdis.h"
  30. extern int dsp_options;
  31. extern int dsp_debug;
  32. extern int dsp_poll;
  33. extern int dsp_tics;
  34. extern spinlock_t dsp_lock;
  35. extern struct work_struct dsp_workq;
  36. extern u32 dsp_poll_diff; /* calculated fix-comma corrected poll value */
  37. /***************
  38. * audio stuff *
  39. ***************/
  40. extern s32 dsp_audio_alaw_to_s32[256];
  41. extern s32 dsp_audio_ulaw_to_s32[256];
  42. extern s32 *dsp_audio_law_to_s32;
  43. extern u8 dsp_audio_s16_to_law[65536];
  44. extern u8 dsp_audio_alaw_to_ulaw[256];
  45. extern u8 dsp_audio_mix_law[65536];
  46. extern u8 dsp_audio_seven2law[128];
  47. extern u8 dsp_audio_law2seven[256];
  48. extern void dsp_audio_generate_law_tables(void);
  49. extern void dsp_audio_generate_s2law_table(void);
  50. extern void dsp_audio_generate_seven(void);
  51. extern void dsp_audio_generate_mix_table(void);
  52. extern void dsp_audio_generate_ulaw_samples(void);
  53. extern void dsp_audio_generate_volume_changes(void);
  54. extern u8 dsp_silence;
  55. /*************
  56. * cmx stuff *
  57. *************/
  58. #define MAX_POLL 256 /* maximum number of send-chunks */
  59. #define CMX_BUFF_SIZE 0x8000 /* must be 2**n (0x1000 about 1/2 second) */
  60. #define CMX_BUFF_HALF 0x4000 /* CMX_BUFF_SIZE / 2 */
  61. #define CMX_BUFF_MASK 0x7fff /* CMX_BUFF_SIZE - 1 */
  62. /* how many seconds will we check the lowest delay until the jitter buffer
  63. is reduced by that delay */
  64. #define MAX_SECONDS_JITTER_CHECK 5
  65. extern struct timer_list dsp_spl_tl;
  66. extern u32 dsp_spl_jiffies;
  67. /* the structure of conferences:
  68. *
  69. * each conference has a unique number, given by user space.
  70. * the conferences are linked in a chain.
  71. * each conference has members linked in a chain.
  72. * each dsplayer points to a member, each member points to a dsplayer.
  73. */
  74. /* all members within a conference (this is linked 1:1 with the dsp) */
  75. struct dsp;
  76. struct dsp_conf_member {
  77. struct list_head list;
  78. struct dsp *dsp;
  79. };
  80. /* the list of all conferences */
  81. struct dsp_conf {
  82. struct list_head list;
  83. u32 id;
  84. /* all cmx stacks with the same ID are
  85. connected */
  86. struct list_head mlist;
  87. int software; /* conf is processed by software */
  88. int hardware; /* conf is processed by hardware */
  89. /* note: if both unset, has only one member */
  90. };
  91. /**************
  92. * DTMF stuff *
  93. **************/
  94. #define DSP_DTMF_NPOINTS 102
  95. #define ECHOCAN_BUFF_SIZE 0x400 /* must be 2**n */
  96. #define ECHOCAN_BUFF_MASK 0x3ff /* -1 */
  97. struct dsp_dtmf {
  98. int treshold; /* above this is dtmf (square of) */
  99. int software; /* dtmf uses software decoding */
  100. int hardware; /* dtmf uses hardware decoding */
  101. int size; /* number of bytes in buffer */
  102. signed short buffer[DSP_DTMF_NPOINTS];
  103. /* buffers one full dtmf frame */
  104. u8 lastwhat, lastdigit;
  105. int count;
  106. u8 digits[16]; /* dtmf result */
  107. };
  108. /******************
  109. * pipeline stuff *
  110. ******************/
  111. struct dsp_pipeline {
  112. rwlock_t lock;
  113. struct list_head list;
  114. int inuse;
  115. };
  116. /***************
  117. * tones stuff *
  118. ***************/
  119. struct dsp_tone {
  120. int software; /* tones are generated by software */
  121. int hardware; /* tones are generated by hardware */
  122. int tone;
  123. void *pattern;
  124. int count;
  125. int index;
  126. struct timer_list tl;
  127. };
  128. /*****************
  129. * general stuff *
  130. *****************/
  131. struct dsp {
  132. struct list_head list;
  133. struct mISDNchannel ch;
  134. struct mISDNchannel *up;
  135. unsigned char name[64];
  136. int b_active;
  137. int echo; /* echo is enabled */
  138. int rx_disabled; /* what the user wants */
  139. int rx_is_off; /* what the card is */
  140. int tx_mix;
  141. struct dsp_tone tone;
  142. struct dsp_dtmf dtmf;
  143. int tx_volume, rx_volume;
  144. /* queue for sending frames */
  145. struct work_struct workq;
  146. struct sk_buff_head sendq;
  147. int hdlc; /* if mode is hdlc */
  148. int data_pending; /* currently an unconfirmed frame */
  149. /* conference stuff */
  150. u32 conf_id;
  151. struct dsp_conf *conf;
  152. struct dsp_conf_member
  153. *member;
  154. /* buffer stuff */
  155. int rx_W; /* current write pos for data without timestamp */
  156. int rx_R; /* current read pos for transmit clock */
  157. int rx_init; /* if set, pointers will be adjusted first */
  158. int tx_W; /* current write pos for transmit data */
  159. int tx_R; /* current read pos for transmit clock */
  160. int rx_delay[MAX_SECONDS_JITTER_CHECK];
  161. int tx_delay[MAX_SECONDS_JITTER_CHECK];
  162. u8 tx_buff[CMX_BUFF_SIZE];
  163. u8 rx_buff[CMX_BUFF_SIZE];
  164. int last_tx; /* if set, we transmitted last poll interval */
  165. int cmx_delay; /* initial delay of buffers,
  166. or 0 for dynamic jitter buffer */
  167. int tx_dejitter; /* if set, dejitter tx buffer */
  168. int tx_data; /* enables tx-data of CMX to upper layer */
  169. /* hardware stuff */
  170. struct dsp_features features;
  171. int features_rx_off; /* set if rx_off is featured */
  172. int features_fill_empty; /* set if fill_empty is featured */
  173. int pcm_slot_rx; /* current PCM slot (or -1) */
  174. int pcm_bank_rx;
  175. int pcm_slot_tx;
  176. int pcm_bank_tx;
  177. int hfc_conf; /* unique id of current conference (or -1) */
  178. /* encryption stuff */
  179. int bf_enable;
  180. u32 bf_p[18];
  181. u32 bf_s[1024];
  182. int bf_crypt_pos;
  183. u8 bf_data_in[9];
  184. u8 bf_crypt_out[9];
  185. int bf_decrypt_in_pos;
  186. int bf_decrypt_out_pos;
  187. u8 bf_crypt_inring[16];
  188. u8 bf_data_out[9];
  189. int bf_sync;
  190. struct dsp_pipeline
  191. pipeline;
  192. };
  193. /* functions */
  194. extern void dsp_change_volume(struct sk_buff *skb, int volume);
  195. extern struct list_head dsp_ilist;
  196. extern struct list_head conf_ilist;
  197. extern void dsp_cmx_debug(struct dsp *dsp);
  198. extern void dsp_cmx_hardware(struct dsp_conf *conf, struct dsp *dsp);
  199. extern int dsp_cmx_conf(struct dsp *dsp, u32 conf_id);
  200. extern void dsp_cmx_receive(struct dsp *dsp, struct sk_buff *skb);
  201. extern void dsp_cmx_hdlc(struct dsp *dsp, struct sk_buff *skb);
  202. extern void dsp_cmx_send(void *arg);
  203. extern void dsp_cmx_transmit(struct dsp *dsp, struct sk_buff *skb);
  204. extern int dsp_cmx_del_conf_member(struct dsp *dsp);
  205. extern int dsp_cmx_del_conf(struct dsp_conf *conf);
  206. extern void dsp_dtmf_goertzel_init(struct dsp *dsp);
  207. extern void dsp_dtmf_hardware(struct dsp *dsp);
  208. extern u8 *dsp_dtmf_goertzel_decode(struct dsp *dsp, u8 *data, int len,
  209. int fmt);
  210. extern int dsp_tone(struct dsp *dsp, int tone);
  211. extern void dsp_tone_copy(struct dsp *dsp, u8 *data, int len);
  212. extern void dsp_tone_timeout(void *arg);
  213. extern void dsp_bf_encrypt(struct dsp *dsp, u8 *data, int len);
  214. extern void dsp_bf_decrypt(struct dsp *dsp, u8 *data, int len);
  215. extern int dsp_bf_init(struct dsp *dsp, const u8 *key, unsigned int keylen);
  216. extern void dsp_bf_cleanup(struct dsp *dsp);
  217. extern int dsp_pipeline_module_init(void);
  218. extern void dsp_pipeline_module_exit(void);
  219. extern int dsp_pipeline_init(struct dsp_pipeline *pipeline);
  220. extern void dsp_pipeline_destroy(struct dsp_pipeline *pipeline);
  221. extern int dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg);
  222. extern void dsp_pipeline_process_tx(struct dsp_pipeline *pipeline, u8 *data,
  223. int len);
  224. extern void dsp_pipeline_process_rx(struct dsp_pipeline *pipeline, u8 *data,
  225. int len, unsigned int txlen);