dsp.h 7.8 KB

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