dsp.h 7.3 KB

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