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