dsp_tones.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /*
  2. * Audio support data for ISDN4Linux.
  3. *
  4. * Copyright 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. #include <linux/mISDNif.h>
  11. #include <linux/mISDNdsp.h>
  12. #include "core.h"
  13. #include "dsp.h"
  14. #define DATA_S sample_silence
  15. #define SIZE_S (&sizeof_silence)
  16. #define DATA_GA sample_german_all
  17. #define SIZE_GA (&sizeof_german_all)
  18. #define DATA_GO sample_german_old
  19. #define SIZE_GO (&sizeof_german_old)
  20. #define DATA_DT sample_american_dialtone
  21. #define SIZE_DT (&sizeof_american_dialtone)
  22. #define DATA_RI sample_american_ringing
  23. #define SIZE_RI (&sizeof_american_ringing)
  24. #define DATA_BU sample_american_busy
  25. #define SIZE_BU (&sizeof_american_busy)
  26. #define DATA_S1 sample_special1
  27. #define SIZE_S1 (&sizeof_special1)
  28. #define DATA_S2 sample_special2
  29. #define SIZE_S2 (&sizeof_special2)
  30. #define DATA_S3 sample_special3
  31. #define SIZE_S3 (&sizeof_special3)
  32. /***************/
  33. /* tones loops */
  34. /***************/
  35. /* all tones are alaw encoded */
  36. /* the last sample+1 is in phase with the first sample. the error is low */
  37. static u8 sample_german_all[] = {
  38. 0x80, 0xab, 0x81, 0x6d, 0xfd, 0xdd, 0x5d, 0x9d,
  39. 0x4d, 0xd1, 0x89, 0x88, 0xd0, 0x4c, 0x9c, 0x5c,
  40. 0xdc, 0xfc, 0x6c,
  41. 0x80, 0xab, 0x81, 0x6d, 0xfd, 0xdd, 0x5d, 0x9d,
  42. 0x4d, 0xd1, 0x89, 0x88, 0xd0, 0x4c, 0x9c, 0x5c,
  43. 0xdc, 0xfc, 0x6c,
  44. 0x80, 0xab, 0x81, 0x6d, 0xfd, 0xdd, 0x5d, 0x9d,
  45. 0x4d, 0xd1, 0x89, 0x88, 0xd0, 0x4c, 0x9c, 0x5c,
  46. 0xdc, 0xfc, 0x6c,
  47. 0x80, 0xab, 0x81, 0x6d, 0xfd, 0xdd, 0x5d, 0x9d,
  48. 0x4d, 0xd1, 0x89, 0x88, 0xd0, 0x4c, 0x9c, 0x5c,
  49. 0xdc, 0xfc, 0x6c,
  50. };
  51. static u32 sizeof_german_all = sizeof(sample_german_all);
  52. static u8 sample_german_old[] = {
  53. 0xec, 0x68, 0xe1, 0x6d, 0x6d, 0x91, 0x51, 0xed,
  54. 0x6d, 0x01, 0x1e, 0x10, 0x0c, 0x90, 0x60, 0x70,
  55. 0x8c,
  56. 0xec, 0x68, 0xe1, 0x6d, 0x6d, 0x91, 0x51, 0xed,
  57. 0x6d, 0x01, 0x1e, 0x10, 0x0c, 0x90, 0x60, 0x70,
  58. 0x8c,
  59. 0xec, 0x68, 0xe1, 0x6d, 0x6d, 0x91, 0x51, 0xed,
  60. 0x6d, 0x01, 0x1e, 0x10, 0x0c, 0x90, 0x60, 0x70,
  61. 0x8c,
  62. 0xec, 0x68, 0xe1, 0x6d, 0x6d, 0x91, 0x51, 0xed,
  63. 0x6d, 0x01, 0x1e, 0x10, 0x0c, 0x90, 0x60, 0x70,
  64. 0x8c,
  65. };
  66. static u32 sizeof_german_old = sizeof(sample_german_old);
  67. static u8 sample_american_dialtone[] = {
  68. 0x2a, 0x18, 0x90, 0x6c, 0x4c, 0xbc, 0x4c, 0x6c,
  69. 0x10, 0x58, 0x32, 0xb9, 0x31, 0x2d, 0x8d, 0x0d,
  70. 0x8d, 0x2d, 0x31, 0x99, 0x0f, 0x28, 0x60, 0xf0,
  71. 0xd0, 0x50, 0xd0, 0x30, 0x60, 0x08, 0x8e, 0x67,
  72. 0x09, 0x19, 0x21, 0xe1, 0xd9, 0xb9, 0x29, 0x67,
  73. 0x83, 0x02, 0xce, 0xbe, 0xee, 0x1a, 0x1b, 0xef,
  74. 0xbf, 0xcf, 0x03, 0x82, 0x66, 0x28, 0xb8, 0xd8,
  75. 0xe0, 0x20, 0x18, 0x08, 0x66, 0x8f, 0x09, 0x61,
  76. 0x31, 0xd1, 0x51, 0xd1, 0xf1, 0x61, 0x29, 0x0e,
  77. 0x98, 0x30, 0x2c, 0x8c, 0x0c, 0x8c, 0x2c, 0x30,
  78. 0xb8, 0x33, 0x59, 0x11, 0x6d, 0x4d, 0xbd, 0x4d,
  79. 0x6d, 0x91, 0x19,
  80. };
  81. static u32 sizeof_american_dialtone = sizeof(sample_american_dialtone);
  82. static u8 sample_american_ringing[] = {
  83. 0x2a, 0xe0, 0xac, 0x0c, 0xbc, 0x4c, 0x8c, 0x90,
  84. 0x48, 0xc7, 0xc1, 0xed, 0xcd, 0x4d, 0xcd, 0xed,
  85. 0xc1, 0xb7, 0x08, 0x30, 0xec, 0xcc, 0xcc, 0x8c,
  86. 0x10, 0x58, 0x1a, 0x99, 0x71, 0xed, 0x8d, 0x8d,
  87. 0x2d, 0x41, 0x89, 0x9e, 0x20, 0x70, 0x2c, 0xec,
  88. 0x2c, 0x70, 0x20, 0x86, 0x77, 0xe1, 0x31, 0x11,
  89. 0xd1, 0xf1, 0x81, 0x09, 0xa3, 0x56, 0x58, 0x00,
  90. 0x40, 0xc0, 0x60, 0x38, 0x46, 0x43, 0x57, 0x39,
  91. 0xd9, 0x59, 0x99, 0xc9, 0x77, 0x2f, 0x2e, 0xc6,
  92. 0xd6, 0x28, 0xd6, 0x36, 0x26, 0x2e, 0x8a, 0xa3,
  93. 0x43, 0x63, 0x4b, 0x4a, 0x62, 0x42, 0xa2, 0x8b,
  94. 0x2f, 0x27, 0x37, 0xd7, 0x29, 0xd7, 0xc7, 0x2f,
  95. 0x2e, 0x76, 0xc8, 0x98, 0x58, 0xd8, 0x38, 0x56,
  96. 0x42, 0x47, 0x39, 0x61, 0xc1, 0x41, 0x01, 0x59,
  97. 0x57, 0xa2, 0x08, 0x80, 0xf0, 0xd0, 0x10, 0x30,
  98. 0xe0, 0x76, 0x87, 0x21, 0x71, 0x2d, 0xed, 0x2d,
  99. 0x71, 0x21, 0x9f, 0x88, 0x40, 0x2c, 0x8c, 0x8c,
  100. 0xec, 0x70, 0x98, 0x1b, 0x59, 0x11, 0x8d, 0xcd,
  101. 0xcd, 0xed, 0x31, 0x09, 0xb6, 0xc0, 0xec, 0xcc,
  102. 0x4c, 0xcc, 0xec, 0xc0, 0xc6, 0x49, 0x91, 0x8d,
  103. 0x4d, 0xbd, 0x0d, 0xad, 0xe1,
  104. };
  105. static u32 sizeof_american_ringing = sizeof(sample_american_ringing);
  106. static u8 sample_american_busy[] = {
  107. 0x2a, 0x00, 0x6c, 0x4c, 0x4c, 0x6c, 0xb0, 0x66,
  108. 0x99, 0x11, 0x6d, 0x8d, 0x2d, 0x41, 0xd7, 0x96,
  109. 0x60, 0xf0, 0x70, 0x40, 0x58, 0xf6, 0x53, 0x57,
  110. 0x09, 0x89, 0xd7, 0x5f, 0xe3, 0x2a, 0xe3, 0x5f,
  111. 0xd7, 0x89, 0x09, 0x57, 0x53, 0xf6, 0x58, 0x40,
  112. 0x70, 0xf0, 0x60, 0x96, 0xd7, 0x41, 0x2d, 0x8d,
  113. 0x6d, 0x11, 0x99, 0x66, 0xb0, 0x6c, 0x4c, 0x4c,
  114. 0x6c, 0x00, 0x2a, 0x01, 0x6d, 0x4d, 0x4d, 0x6d,
  115. 0xb1, 0x67, 0x98, 0x10, 0x6c, 0x8c, 0x2c, 0x40,
  116. 0xd6, 0x97, 0x61, 0xf1, 0x71, 0x41, 0x59, 0xf7,
  117. 0x52, 0x56, 0x08, 0x88, 0xd6, 0x5e, 0xe2, 0x2a,
  118. 0xe2, 0x5e, 0xd6, 0x88, 0x08, 0x56, 0x52, 0xf7,
  119. 0x59, 0x41, 0x71, 0xf1, 0x61, 0x97, 0xd6, 0x40,
  120. 0x2c, 0x8c, 0x6c, 0x10, 0x98, 0x67, 0xb1, 0x6d,
  121. 0x4d, 0x4d, 0x6d, 0x01,
  122. };
  123. static u32 sizeof_american_busy = sizeof(sample_american_busy);
  124. static u8 sample_special1[] = {
  125. 0x2a, 0x2c, 0xbc, 0x6c, 0xd6, 0x71, 0xbd, 0x0d,
  126. 0xd9, 0x80, 0xcc, 0x4c, 0x40, 0x39, 0x0d, 0xbd,
  127. 0x11, 0x86, 0xec, 0xbc, 0xec, 0x0e, 0x51, 0xbd,
  128. 0x8d, 0x89, 0x30, 0x4c, 0xcc, 0xe0, 0xe1, 0xcd,
  129. 0x4d, 0x31, 0x88, 0x8c, 0xbc, 0x50, 0x0f, 0xed,
  130. 0xbd, 0xed, 0x87, 0x10, 0xbc, 0x0c, 0x38, 0x41,
  131. 0x4d, 0xcd, 0x81, 0xd8, 0x0c, 0xbc, 0x70, 0xd7,
  132. 0x6d, 0xbd, 0x2d,
  133. };
  134. static u32 sizeof_special1 = sizeof(sample_special1);
  135. static u8 sample_special2[] = {
  136. 0x2a, 0xcc, 0x8c, 0xd7, 0x4d, 0x2d, 0x18, 0xbc,
  137. 0x10, 0xc1, 0xbd, 0xc1, 0x10, 0xbc, 0x18, 0x2d,
  138. 0x4d, 0xd7, 0x8c, 0xcc, 0x2a, 0xcd, 0x8d, 0xd6,
  139. 0x4c, 0x2c, 0x19, 0xbd, 0x11, 0xc0, 0xbc, 0xc0,
  140. 0x11, 0xbd, 0x19, 0x2c, 0x4c, 0xd6, 0x8d, 0xcd,
  141. 0x2a, 0xcc, 0x8c, 0xd7, 0x4d, 0x2d, 0x18, 0xbc,
  142. 0x10, 0xc1, 0xbd, 0xc1, 0x10, 0xbc, 0x18, 0x2d,
  143. 0x4d, 0xd7, 0x8c, 0xcc, 0x2a, 0xcd, 0x8d, 0xd6,
  144. 0x4c, 0x2c, 0x19, 0xbd, 0x11, 0xc0, 0xbc, 0xc0,
  145. 0x11, 0xbd, 0x19, 0x2c, 0x4c, 0xd6, 0x8d, 0xcd,
  146. };
  147. static u32 sizeof_special2 = sizeof(sample_special2);
  148. static u8 sample_special3[] = {
  149. 0x2a, 0xbc, 0x18, 0xcd, 0x11, 0x2c, 0x8c, 0xc1,
  150. 0x4d, 0xd6, 0xbc, 0xd6, 0x4d, 0xc1, 0x8c, 0x2c,
  151. 0x11, 0xcd, 0x18, 0xbc, 0x2a, 0xbd, 0x19, 0xcc,
  152. 0x10, 0x2d, 0x8d, 0xc0, 0x4c, 0xd7, 0xbd, 0xd7,
  153. 0x4c, 0xc0, 0x8d, 0x2d, 0x10, 0xcc, 0x19, 0xbd,
  154. 0x2a, 0xbc, 0x18, 0xcd, 0x11, 0x2c, 0x8c, 0xc1,
  155. 0x4d, 0xd6, 0xbc, 0xd6, 0x4d, 0xc1, 0x8c, 0x2c,
  156. 0x11, 0xcd, 0x18, 0xbc, 0x2a, 0xbd, 0x19, 0xcc,
  157. 0x10, 0x2d, 0x8d, 0xc0, 0x4c, 0xd7, 0xbd, 0xd7,
  158. 0x4c, 0xc0, 0x8d, 0x2d, 0x10, 0xcc, 0x19, 0xbd,
  159. };
  160. static u32 sizeof_special3 = sizeof(sample_special3);
  161. static u8 sample_silence[] = {
  162. 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
  163. 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
  164. 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
  165. 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
  166. 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
  167. 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
  168. 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
  169. 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
  170. 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
  171. 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
  172. 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
  173. 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a,
  174. };
  175. static u32 sizeof_silence = sizeof(sample_silence);
  176. struct tones_samples {
  177. u32 *len;
  178. u8 *data;
  179. };
  180. static struct
  181. tones_samples samples[] = {
  182. {&sizeof_german_all, sample_german_all},
  183. {&sizeof_german_old, sample_german_old},
  184. {&sizeof_american_dialtone, sample_american_dialtone},
  185. {&sizeof_american_ringing, sample_american_ringing},
  186. {&sizeof_american_busy, sample_american_busy},
  187. {&sizeof_special1, sample_special1},
  188. {&sizeof_special2, sample_special2},
  189. {&sizeof_special3, sample_special3},
  190. {NULL, NULL},
  191. };
  192. /***********************************
  193. * generate ulaw from alaw samples *
  194. ***********************************/
  195. void
  196. dsp_audio_generate_ulaw_samples(void)
  197. {
  198. int i, j;
  199. i = 0;
  200. while (samples[i].len) {
  201. j = 0;
  202. while (j < (*samples[i].len)) {
  203. samples[i].data[j] =
  204. dsp_audio_alaw_to_ulaw[samples[i].data[j]];
  205. j++;
  206. }
  207. i++;
  208. }
  209. }
  210. /****************************
  211. * tone sequence definition *
  212. ****************************/
  213. static struct pattern {
  214. int tone;
  215. u8 *data[10];
  216. u32 *siz[10];
  217. u32 seq[10];
  218. } pattern[] = {
  219. {TONE_GERMAN_DIALTONE,
  220. {DATA_GA, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  221. {SIZE_GA, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  222. {1900, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
  223. {TONE_GERMAN_OLDDIALTONE,
  224. {DATA_GO, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  225. {SIZE_GO, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  226. {1998, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
  227. {TONE_AMERICAN_DIALTONE,
  228. {DATA_DT, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  229. {SIZE_DT, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  230. {8000, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
  231. {TONE_GERMAN_DIALPBX,
  232. {DATA_GA, DATA_S, DATA_GA, DATA_S, DATA_GA, DATA_S, NULL, NULL, NULL, NULL},
  233. {SIZE_GA, SIZE_S, SIZE_GA, SIZE_S, SIZE_GA, SIZE_S, NULL, NULL, NULL, NULL},
  234. {2000, 2000, 2000, 2000, 2000, 12000, 0, 0, 0, 0} },
  235. {TONE_GERMAN_OLDDIALPBX,
  236. {DATA_GO, DATA_S, DATA_GO, DATA_S, DATA_GO, DATA_S, NULL, NULL, NULL, NULL},
  237. {SIZE_GO, SIZE_S, SIZE_GO, SIZE_S, SIZE_GO, SIZE_S, NULL, NULL, NULL, NULL},
  238. {2000, 2000, 2000, 2000, 2000, 12000, 0, 0, 0, 0} },
  239. {TONE_AMERICAN_DIALPBX,
  240. {DATA_DT, DATA_S, DATA_DT, DATA_S, DATA_DT, DATA_S, NULL, NULL, NULL, NULL},
  241. {SIZE_DT, SIZE_S, SIZE_DT, SIZE_S, SIZE_DT, SIZE_S, NULL, NULL, NULL, NULL},
  242. {2000, 2000, 2000, 2000, 2000, 12000, 0, 0, 0, 0} },
  243. {TONE_GERMAN_RINGING,
  244. {DATA_GA, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  245. {SIZE_GA, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  246. {8000, 32000, 0, 0, 0, 0, 0, 0, 0, 0} },
  247. {TONE_GERMAN_OLDRINGING,
  248. {DATA_GO, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  249. {SIZE_GO, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  250. {8000, 40000, 0, 0, 0, 0, 0, 0, 0, 0} },
  251. {TONE_AMERICAN_RINGING,
  252. {DATA_RI, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  253. {SIZE_RI, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  254. {8000, 32000, 0, 0, 0, 0, 0, 0, 0, 0} },
  255. {TONE_GERMAN_RINGPBX,
  256. {DATA_GA, DATA_S, DATA_GA, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL},
  257. {SIZE_GA, SIZE_S, SIZE_GA, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL},
  258. {4000, 4000, 4000, 28000, 0, 0, 0, 0, 0, 0} },
  259. {TONE_GERMAN_OLDRINGPBX,
  260. {DATA_GO, DATA_S, DATA_GO, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL},
  261. {SIZE_GO, SIZE_S, SIZE_GO, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL},
  262. {4000, 4000, 4000, 28000, 0, 0, 0, 0, 0, 0} },
  263. {TONE_AMERICAN_RINGPBX,
  264. {DATA_RI, DATA_S, DATA_RI, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL},
  265. {SIZE_RI, SIZE_S, SIZE_RI, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL},
  266. {4000, 4000, 4000, 28000, 0, 0, 0, 0, 0, 0} },
  267. {TONE_GERMAN_BUSY,
  268. {DATA_GA, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  269. {SIZE_GA, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  270. {4000, 4000, 0, 0, 0, 0, 0, 0, 0, 0} },
  271. {TONE_GERMAN_OLDBUSY,
  272. {DATA_GO, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  273. {SIZE_GO, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  274. {1000, 5000, 0, 0, 0, 0, 0, 0, 0, 0} },
  275. {TONE_AMERICAN_BUSY,
  276. {DATA_BU, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  277. {SIZE_BU, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  278. {4000, 4000, 0, 0, 0, 0, 0, 0, 0, 0} },
  279. {TONE_GERMAN_HANGUP,
  280. {DATA_GA, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  281. {SIZE_GA, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  282. {4000, 4000, 0, 0, 0, 0, 0, 0, 0, 0} },
  283. {TONE_GERMAN_OLDHANGUP,
  284. {DATA_GO, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  285. {SIZE_GO, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  286. {1000, 5000, 0, 0, 0, 0, 0, 0, 0, 0} },
  287. {TONE_AMERICAN_HANGUP,
  288. {DATA_DT, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  289. {SIZE_DT, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  290. {8000, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
  291. {TONE_SPECIAL_INFO,
  292. {DATA_S1, DATA_S2, DATA_S3, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL},
  293. {SIZE_S1, SIZE_S2, SIZE_S3, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL},
  294. {2666, 2666, 2666, 8002, 0, 0, 0, 0, 0, 0} },
  295. {TONE_GERMAN_GASSENBESETZT,
  296. {DATA_GA, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  297. {SIZE_GA, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  298. {2000, 2000, 0, 0, 0, 0, 0, 0, 0, 0} },
  299. {TONE_GERMAN_AUFSCHALTTON,
  300. {DATA_GO, DATA_S, DATA_GO, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL},
  301. {SIZE_GO, SIZE_S, SIZE_GO, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL},
  302. {1000, 5000, 1000, 17000, 0, 0, 0, 0, 0, 0} },
  303. {0,
  304. {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  305. {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  306. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
  307. };
  308. /******************
  309. * copy tone data *
  310. ******************/
  311. /* an sk_buff is generated from the number of samples needed.
  312. * the count will be changed and may begin from 0 each pattern period.
  313. * the clue is to precalculate the pointers and legths to use only one
  314. * memcpy per function call, or two memcpy if the tone sequence changes.
  315. *
  316. * pattern - the type of the pattern
  317. * count - the sample from the beginning of the pattern (phase)
  318. * len - the number of bytes
  319. *
  320. * return - the sk_buff with the sample
  321. *
  322. * if tones has finished (e.g. knocking tone), dsp->tones is turned off
  323. */
  324. void dsp_tone_copy(struct dsp *dsp, u8 *data, int len)
  325. {
  326. int index, count, start, num;
  327. struct pattern *pat;
  328. struct dsp_tone *tone = &dsp->tone;
  329. /* if we have no tone, we copy silence */
  330. if (!tone->tone) {
  331. memset(data, dsp_silence, len);
  332. return;
  333. }
  334. /* process pattern */
  335. pat = (struct pattern *)tone->pattern;
  336. /* points to the current pattern */
  337. index = tone->index; /* gives current sequence index */
  338. count = tone->count; /* gives current sample */
  339. /* copy sample */
  340. while (len) {
  341. /* find sample to start with */
  342. while (42) {
  343. /* warp arround */
  344. if (!pat->seq[index]) {
  345. count = 0;
  346. index = 0;
  347. }
  348. /* check if we are currently playing this tone */
  349. if (count < pat->seq[index])
  350. break;
  351. if (dsp_debug & DEBUG_DSP_TONE)
  352. printk(KERN_DEBUG "%s: reaching next sequence "
  353. "(index=%d)\n", __func__, index);
  354. count -= pat->seq[index];
  355. index++;
  356. }
  357. /* calculate start and number of samples */
  358. start = count % (*(pat->siz[index]));
  359. num = len;
  360. if (num+count > pat->seq[index])
  361. num = pat->seq[index] - count;
  362. if (num+start > (*(pat->siz[index])))
  363. num = (*(pat->siz[index])) - start;
  364. /* copy memory */
  365. memcpy(data, pat->data[index]+start, num);
  366. /* reduce length */
  367. data += num;
  368. count += num;
  369. len -= num;
  370. }
  371. tone->index = index;
  372. tone->count = count;
  373. /* return sk_buff */
  374. return;
  375. }
  376. /*******************************
  377. * send HW message to hfc card *
  378. *******************************/
  379. static void
  380. dsp_tone_hw_message(struct dsp *dsp, u8 *sample, int len)
  381. {
  382. struct sk_buff *nskb;
  383. /* unlocking is not required, because we don't expect a response */
  384. nskb = _alloc_mISDN_skb(PH_CONTROL_REQ,
  385. (len)?HFC_SPL_LOOP_ON:HFC_SPL_LOOP_OFF, len, sample,
  386. GFP_ATOMIC);
  387. if (nskb) {
  388. if (dsp->ch.peer) {
  389. if (dsp->ch.recv(dsp->ch.peer, nskb))
  390. dev_kfree_skb(nskb);
  391. } else
  392. dev_kfree_skb(nskb);
  393. }
  394. }
  395. /*****************
  396. * timer expires *
  397. *****************/
  398. void
  399. dsp_tone_timeout(void *arg)
  400. {
  401. struct dsp *dsp = arg;
  402. struct dsp_tone *tone = &dsp->tone;
  403. struct pattern *pat = (struct pattern *)tone->pattern;
  404. int index = tone->index;
  405. if (!tone->tone)
  406. return;
  407. index++;
  408. if (!pat->seq[index])
  409. index = 0;
  410. tone->index = index;
  411. /* set next tone */
  412. if (pat->data[index] == DATA_S)
  413. dsp_tone_hw_message(dsp, NULL, 0);
  414. else
  415. dsp_tone_hw_message(dsp, pat->data[index], *(pat->siz[index]));
  416. /* set timer */
  417. init_timer(&tone->tl);
  418. tone->tl.expires = jiffies + (pat->seq[index] * HZ) / 8000;
  419. add_timer(&tone->tl);
  420. }
  421. /********************
  422. * set/release tone *
  423. ********************/
  424. /*
  425. * tones are relaized by streaming or by special loop commands if supported
  426. * by hardware. when hardware is used, the patterns will be controlled by
  427. * timers.
  428. */
  429. int
  430. dsp_tone(struct dsp *dsp, int tone)
  431. {
  432. struct pattern *pat;
  433. int i;
  434. struct dsp_tone *tonet = &dsp->tone;
  435. tonet->software = 0;
  436. tonet->hardware = 0;
  437. /* we turn off the tone */
  438. if (!tone) {
  439. if (dsp->features.hfc_loops)
  440. if (timer_pending(&tonet->tl))
  441. del_timer(&tonet->tl);
  442. if (dsp->features.hfc_loops)
  443. dsp_tone_hw_message(dsp, NULL, 0);
  444. tonet->tone = 0;
  445. return 0;
  446. }
  447. pat = NULL;
  448. i = 0;
  449. while (pattern[i].tone) {
  450. if (pattern[i].tone == tone) {
  451. pat = &pattern[i];
  452. break;
  453. }
  454. i++;
  455. }
  456. if (!pat) {
  457. printk(KERN_WARNING "dsp: given tone 0x%x is invalid\n", tone);
  458. return -EINVAL;
  459. }
  460. if (dsp_debug & DEBUG_DSP_TONE)
  461. printk(KERN_DEBUG "%s: now starting tone %d (index=%d)\n",
  462. __func__, tone, 0);
  463. tonet->tone = tone;
  464. tonet->pattern = pat;
  465. tonet->index = 0;
  466. tonet->count = 0;
  467. if (dsp->features.hfc_loops) {
  468. tonet->hardware = 1;
  469. /* set first tone */
  470. dsp_tone_hw_message(dsp, pat->data[0], *(pat->siz[0]));
  471. /* set timer */
  472. if (timer_pending(&tonet->tl))
  473. del_timer(&tonet->tl);
  474. init_timer(&tonet->tl);
  475. tonet->tl.expires = jiffies + (pat->seq[0] * HZ) / 8000;
  476. add_timer(&tonet->tl);
  477. } else {
  478. tonet->software = 1;
  479. }
  480. return 0;
  481. }