dsp_tones.c 17 KB

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