dsp_tones.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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,
  233. NULL},
  234. {SIZE_GA, SIZE_S, SIZE_GA, SIZE_S, SIZE_GA, SIZE_S, NULL, NULL, NULL,
  235. NULL},
  236. {2000, 2000, 2000, 2000, 2000, 12000, 0, 0, 0, 0} },
  237. {TONE_GERMAN_OLDDIALPBX,
  238. {DATA_GO, DATA_S, DATA_GO, DATA_S, DATA_GO, DATA_S, NULL, NULL, NULL,
  239. NULL},
  240. {SIZE_GO, SIZE_S, SIZE_GO, SIZE_S, SIZE_GO, SIZE_S, NULL, NULL, NULL,
  241. NULL},
  242. {2000, 2000, 2000, 2000, 2000, 12000, 0, 0, 0, 0} },
  243. {TONE_AMERICAN_DIALPBX,
  244. {DATA_DT, DATA_S, DATA_DT, DATA_S, DATA_DT, DATA_S, NULL, NULL, NULL,
  245. NULL},
  246. {SIZE_DT, SIZE_S, SIZE_DT, SIZE_S, SIZE_DT, SIZE_S, NULL, NULL, NULL,
  247. NULL},
  248. {2000, 2000, 2000, 2000, 2000, 12000, 0, 0, 0, 0} },
  249. {TONE_GERMAN_RINGING,
  250. {DATA_GA, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  251. {SIZE_GA, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  252. {8000, 32000, 0, 0, 0, 0, 0, 0, 0, 0} },
  253. {TONE_GERMAN_OLDRINGING,
  254. {DATA_GO, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  255. {SIZE_GO, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  256. {8000, 40000, 0, 0, 0, 0, 0, 0, 0, 0} },
  257. {TONE_AMERICAN_RINGING,
  258. {DATA_RI, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  259. {SIZE_RI, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  260. {8000, 32000, 0, 0, 0, 0, 0, 0, 0, 0} },
  261. {TONE_GERMAN_RINGPBX,
  262. {DATA_GA, DATA_S, DATA_GA, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL},
  263. {SIZE_GA, SIZE_S, SIZE_GA, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL},
  264. {4000, 4000, 4000, 28000, 0, 0, 0, 0, 0, 0} },
  265. {TONE_GERMAN_OLDRINGPBX,
  266. {DATA_GO, DATA_S, DATA_GO, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL},
  267. {SIZE_GO, SIZE_S, SIZE_GO, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL},
  268. {4000, 4000, 4000, 28000, 0, 0, 0, 0, 0, 0} },
  269. {TONE_AMERICAN_RINGPBX,
  270. {DATA_RI, DATA_S, DATA_RI, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL},
  271. {SIZE_RI, SIZE_S, SIZE_RI, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL},
  272. {4000, 4000, 4000, 28000, 0, 0, 0, 0, 0, 0} },
  273. {TONE_GERMAN_BUSY,
  274. {DATA_GA, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  275. {SIZE_GA, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  276. {4000, 4000, 0, 0, 0, 0, 0, 0, 0, 0} },
  277. {TONE_GERMAN_OLDBUSY,
  278. {DATA_GO, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  279. {SIZE_GO, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  280. {1000, 5000, 0, 0, 0, 0, 0, 0, 0, 0} },
  281. {TONE_AMERICAN_BUSY,
  282. {DATA_BU, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  283. {SIZE_BU, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  284. {4000, 4000, 0, 0, 0, 0, 0, 0, 0, 0} },
  285. {TONE_GERMAN_HANGUP,
  286. {DATA_GA, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  287. {SIZE_GA, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  288. {4000, 4000, 0, 0, 0, 0, 0, 0, 0, 0} },
  289. {TONE_GERMAN_OLDHANGUP,
  290. {DATA_GO, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  291. {SIZE_GO, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  292. {1000, 5000, 0, 0, 0, 0, 0, 0, 0, 0} },
  293. {TONE_AMERICAN_HANGUP,
  294. {DATA_DT, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  295. {SIZE_DT, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  296. {8000, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
  297. {TONE_SPECIAL_INFO,
  298. {DATA_S1, DATA_S2, DATA_S3, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL},
  299. {SIZE_S1, SIZE_S2, SIZE_S3, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL},
  300. {2666, 2666, 2666, 8002, 0, 0, 0, 0, 0, 0} },
  301. {TONE_GERMAN_GASSENBESETZT,
  302. {DATA_GA, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  303. {SIZE_GA, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  304. {2000, 2000, 0, 0, 0, 0, 0, 0, 0, 0} },
  305. {TONE_GERMAN_AUFSCHALTTON,
  306. {DATA_GO, DATA_S, DATA_GO, DATA_S, NULL, NULL, NULL, NULL, NULL, NULL},
  307. {SIZE_GO, SIZE_S, SIZE_GO, SIZE_S, NULL, NULL, NULL, NULL, NULL, NULL},
  308. {1000, 5000, 1000, 17000, 0, 0, 0, 0, 0, 0} },
  309. {0,
  310. {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  311. {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  312. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
  313. };
  314. /******************
  315. * copy tone data *
  316. ******************/
  317. /* an sk_buff is generated from the number of samples needed.
  318. * the count will be changed and may begin from 0 each pattern period.
  319. * the clue is to precalculate the pointers and legths to use only one
  320. * memcpy per function call, or two memcpy if the tone sequence changes.
  321. *
  322. * pattern - the type of the pattern
  323. * count - the sample from the beginning of the pattern (phase)
  324. * len - the number of bytes
  325. *
  326. * return - the sk_buff with the sample
  327. *
  328. * if tones has finished (e.g. knocking tone), dsp->tones is turned off
  329. */
  330. void dsp_tone_copy(struct dsp *dsp, u8 *data, int len)
  331. {
  332. int index, count, start, num;
  333. struct pattern *pat;
  334. struct dsp_tone *tone = &dsp->tone;
  335. /* if we have no tone, we copy silence */
  336. if (!tone->tone) {
  337. memset(data, dsp_silence, len);
  338. return;
  339. }
  340. /* process pattern */
  341. pat = (struct pattern *)tone->pattern;
  342. /* points to the current pattern */
  343. index = tone->index; /* gives current sequence index */
  344. count = tone->count; /* gives current sample */
  345. /* copy sample */
  346. while (len) {
  347. /* find sample to start with */
  348. while (42) {
  349. /* warp arround */
  350. if (!pat->seq[index]) {
  351. count = 0;
  352. index = 0;
  353. }
  354. /* check if we are currently playing this tone */
  355. if (count < pat->seq[index])
  356. break;
  357. if (dsp_debug & DEBUG_DSP_TONE)
  358. printk(KERN_DEBUG "%s: reaching next sequence "
  359. "(index=%d)\n", __func__, index);
  360. count -= pat->seq[index];
  361. index++;
  362. }
  363. /* calculate start and number of samples */
  364. start = count % (*(pat->siz[index]));
  365. num = len;
  366. if (num+count > pat->seq[index])
  367. num = pat->seq[index] - count;
  368. if (num+start > (*(pat->siz[index])))
  369. num = (*(pat->siz[index])) - start;
  370. /* copy memory */
  371. memcpy(data, pat->data[index]+start, num);
  372. /* reduce length */
  373. data += num;
  374. count += num;
  375. len -= num;
  376. }
  377. tone->index = index;
  378. tone->count = count;
  379. /* return sk_buff */
  380. return;
  381. }
  382. /*******************************
  383. * send HW message to hfc card *
  384. *******************************/
  385. static void
  386. dsp_tone_hw_message(struct dsp *dsp, u8 *sample, int len)
  387. {
  388. struct sk_buff *nskb;
  389. /* unlocking is not required, because we don't expect a response */
  390. nskb = _alloc_mISDN_skb(PH_CONTROL_REQ,
  391. (len) ? HFC_SPL_LOOP_ON : HFC_SPL_LOOP_OFF, len, sample,
  392. GFP_ATOMIC);
  393. if (nskb) {
  394. if (dsp->ch.peer) {
  395. if (dsp->ch.recv(dsp->ch.peer, nskb))
  396. dev_kfree_skb(nskb);
  397. } else
  398. dev_kfree_skb(nskb);
  399. }
  400. }
  401. /*****************
  402. * timer expires *
  403. *****************/
  404. void
  405. dsp_tone_timeout(void *arg)
  406. {
  407. struct dsp *dsp = arg;
  408. struct dsp_tone *tone = &dsp->tone;
  409. struct pattern *pat = (struct pattern *)tone->pattern;
  410. int index = tone->index;
  411. if (!tone->tone)
  412. return;
  413. index++;
  414. if (!pat->seq[index])
  415. index = 0;
  416. tone->index = index;
  417. /* set next tone */
  418. if (pat->data[index] == DATA_S)
  419. dsp_tone_hw_message(dsp, NULL, 0);
  420. else
  421. dsp_tone_hw_message(dsp, pat->data[index], *(pat->siz[index]));
  422. /* set timer */
  423. init_timer(&tone->tl);
  424. tone->tl.expires = jiffies + (pat->seq[index] * HZ) / 8000;
  425. add_timer(&tone->tl);
  426. }
  427. /********************
  428. * set/release tone *
  429. ********************/
  430. /*
  431. * tones are relaized by streaming or by special loop commands if supported
  432. * by hardware. when hardware is used, the patterns will be controlled by
  433. * timers.
  434. */
  435. int
  436. dsp_tone(struct dsp *dsp, int tone)
  437. {
  438. struct pattern *pat;
  439. int i;
  440. struct dsp_tone *tonet = &dsp->tone;
  441. tonet->software = 0;
  442. tonet->hardware = 0;
  443. /* we turn off the tone */
  444. if (!tone) {
  445. if (dsp->features.hfc_loops && timer_pending(&tonet->tl))
  446. del_timer(&tonet->tl);
  447. if (dsp->features.hfc_loops)
  448. dsp_tone_hw_message(dsp, NULL, 0);
  449. tonet->tone = 0;
  450. return 0;
  451. }
  452. pat = NULL;
  453. i = 0;
  454. while (pattern[i].tone) {
  455. if (pattern[i].tone == tone) {
  456. pat = &pattern[i];
  457. break;
  458. }
  459. i++;
  460. }
  461. if (!pat) {
  462. printk(KERN_WARNING "dsp: given tone 0x%x is invalid\n", tone);
  463. return -EINVAL;
  464. }
  465. if (dsp_debug & DEBUG_DSP_TONE)
  466. printk(KERN_DEBUG "%s: now starting tone %d (index=%d)\n",
  467. __func__, tone, 0);
  468. tonet->tone = tone;
  469. tonet->pattern = pat;
  470. tonet->index = 0;
  471. tonet->count = 0;
  472. if (dsp->features.hfc_loops) {
  473. tonet->hardware = 1;
  474. /* set first tone */
  475. dsp_tone_hw_message(dsp, pat->data[0], *(pat->siz[0]));
  476. /* set timer */
  477. if (timer_pending(&tonet->tl))
  478. del_timer(&tonet->tl);
  479. init_timer(&tonet->tl);
  480. tonet->tl.expires = jiffies + (pat->seq[0] * HZ) / 8000;
  481. add_timer(&tonet->tl);
  482. } else {
  483. tonet->software = 1;
  484. }
  485. return 0;
  486. }