dsp.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 acceleration 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 enable; /* dtmf is enabled */
  99. int treshold; /* above this is dtmf (square of) */
  100. int software; /* dtmf uses software decoding */
  101. int hardware; /* dtmf uses hardware decoding */
  102. int size; /* number of bytes in buffer */
  103. signed short buffer[DSP_DTMF_NPOINTS];
  104. /* buffers one full dtmf frame */
  105. u8 lastwhat, lastdigit;
  106. int count;
  107. u8 digits[16]; /* dtmf result */
  108. };
  109. /******************
  110. * pipeline stuff *
  111. ******************/
  112. struct dsp_pipeline {
  113. rwlock_t lock;
  114. struct list_head list;
  115. int inuse;
  116. };
  117. /***************
  118. * tones stuff *
  119. ***************/
  120. struct dsp_tone {
  121. int software; /* tones are generated by software */
  122. int hardware; /* tones are generated by hardware */
  123. int tone;
  124. void *pattern;
  125. int count;
  126. int index;
  127. struct timer_list tl;
  128. };
  129. /***************
  130. * echo stuff *
  131. ***************/
  132. struct dsp_echo {
  133. int software; /* echo is generated by software */
  134. int hardware; /* echo is generated by hardware */
  135. };
  136. /*****************
  137. * general stuff *
  138. *****************/
  139. struct dsp {
  140. struct list_head list;
  141. struct mISDNchannel ch;
  142. struct mISDNchannel *up;
  143. unsigned char name[64];
  144. int b_active;
  145. struct dsp_echo echo;
  146. int rx_disabled; /* what the user wants */
  147. int rx_is_off; /* what the card is */
  148. int tx_mix;
  149. struct dsp_tone tone;
  150. struct dsp_dtmf dtmf;
  151. int tx_volume, rx_volume;
  152. /* queue for sending frames */
  153. struct work_struct workq;
  154. struct sk_buff_head sendq;
  155. int hdlc; /* if mode is hdlc */
  156. int data_pending; /* currently an unconfirmed frame */
  157. /* conference stuff */
  158. u32 conf_id;
  159. struct dsp_conf *conf;
  160. struct dsp_conf_member
  161. *member;
  162. /* buffer stuff */
  163. int rx_W; /* current write pos for data without timestamp */
  164. int rx_R; /* current read pos for transmit clock */
  165. int rx_init; /* if set, pointers will be adjusted first */
  166. int tx_W; /* current write pos for transmit data */
  167. int tx_R; /* current read pos for transmit clock */
  168. int rx_delay[MAX_SECONDS_JITTER_CHECK];
  169. int tx_delay[MAX_SECONDS_JITTER_CHECK];
  170. u8 tx_buff[CMX_BUFF_SIZE];
  171. u8 rx_buff[CMX_BUFF_SIZE];
  172. int last_tx; /* if set, we transmitted last poll interval */
  173. int cmx_delay; /* initial delay of buffers,
  174. or 0 for dynamic jitter buffer */
  175. int tx_dejitter; /* if set, dejitter tx buffer */
  176. int tx_data; /* enables tx-data of CMX to upper layer */
  177. /* hardware stuff */
  178. struct dsp_features features;
  179. int features_rx_off; /* set if rx_off is featured */
  180. int features_fill_empty; /* set if fill_empty is featured */
  181. int pcm_slot_rx; /* current PCM slot (or -1) */
  182. int pcm_bank_rx;
  183. int pcm_slot_tx;
  184. int pcm_bank_tx;
  185. int hfc_conf; /* unique id of current conference (or -1) */
  186. /* encryption stuff */
  187. int bf_enable;
  188. u32 bf_p[18];
  189. u32 bf_s[1024];
  190. int bf_crypt_pos;
  191. u8 bf_data_in[9];
  192. u8 bf_crypt_out[9];
  193. int bf_decrypt_in_pos;
  194. int bf_decrypt_out_pos;
  195. u8 bf_crypt_inring[16];
  196. u8 bf_data_out[9];
  197. int bf_sync;
  198. struct dsp_pipeline
  199. pipeline;
  200. };
  201. /* functions */
  202. extern void dsp_change_volume(struct sk_buff *skb, int volume);
  203. extern struct list_head dsp_ilist;
  204. extern struct list_head conf_ilist;
  205. extern void dsp_cmx_debug(struct dsp *dsp);
  206. extern void dsp_cmx_hardware(struct dsp_conf *conf, struct dsp *dsp);
  207. extern int dsp_cmx_conf(struct dsp *dsp, u32 conf_id);
  208. extern void dsp_cmx_receive(struct dsp *dsp, struct sk_buff *skb);
  209. extern void dsp_cmx_hdlc(struct dsp *dsp, struct sk_buff *skb);
  210. extern void dsp_cmx_send(void *arg);
  211. extern void dsp_cmx_transmit(struct dsp *dsp, struct sk_buff *skb);
  212. extern int dsp_cmx_del_conf_member(struct dsp *dsp);
  213. extern int dsp_cmx_del_conf(struct dsp_conf *conf);
  214. extern void dsp_dtmf_goertzel_init(struct dsp *dsp);
  215. extern void dsp_dtmf_hardware(struct dsp *dsp);
  216. extern u8 *dsp_dtmf_goertzel_decode(struct dsp *dsp, u8 *data, int len,
  217. int fmt);
  218. extern int dsp_tone(struct dsp *dsp, int tone);
  219. extern void dsp_tone_copy(struct dsp *dsp, u8 *data, int len);
  220. extern void dsp_tone_timeout(void *arg);
  221. extern void dsp_bf_encrypt(struct dsp *dsp, u8 *data, int len);
  222. extern void dsp_bf_decrypt(struct dsp *dsp, u8 *data, int len);
  223. extern int dsp_bf_init(struct dsp *dsp, const u8 *key, unsigned int keylen);
  224. extern void dsp_bf_cleanup(struct dsp *dsp);
  225. extern int dsp_pipeline_module_init(void);
  226. extern void dsp_pipeline_module_exit(void);
  227. extern int dsp_pipeline_init(struct dsp_pipeline *pipeline);
  228. extern void dsp_pipeline_destroy(struct dsp_pipeline *pipeline);
  229. extern int dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg);
  230. extern void dsp_pipeline_process_tx(struct dsp_pipeline *pipeline, u8 *data,
  231. int len);
  232. extern void dsp_pipeline_process_rx(struct dsp_pipeline *pipeline, u8 *data,
  233. int len, unsigned int txlen);