trans_16.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. /*
  2. * linux/sound/oss/dmasound/trans_16.c
  3. *
  4. * 16 bit translation routines. Only used by Power mac at present.
  5. *
  6. * See linux/sound/oss/dmasound/dmasound_core.c for copyright and
  7. * history prior to 08/02/2001.
  8. *
  9. * 08/02/2001 Iain Sandoe
  10. * split from dmasound_awacs.c
  11. * 11/29/2003 Renzo Davoli (King Enzo)
  12. * - input resampling (for soft rate < hard rate)
  13. * - software line in gain control
  14. */
  15. #include <linux/soundcard.h>
  16. #include <asm/uaccess.h>
  17. #include "dmasound.h"
  18. static short dmasound_alaw2dma16[] ;
  19. static short dmasound_ulaw2dma16[] ;
  20. static ssize_t pmac_ct_law(const u_char __user *userPtr, size_t userCount,
  21. u_char frame[], ssize_t *frameUsed,
  22. ssize_t frameLeft);
  23. static ssize_t pmac_ct_s8(const u_char __user *userPtr, size_t userCount,
  24. u_char frame[], ssize_t *frameUsed,
  25. ssize_t frameLeft);
  26. static ssize_t pmac_ct_u8(const u_char __user *userPtr, size_t userCount,
  27. u_char frame[], ssize_t *frameUsed,
  28. ssize_t frameLeft);
  29. static ssize_t pmac_ct_s16(const u_char __user *userPtr, size_t userCount,
  30. u_char frame[], ssize_t *frameUsed,
  31. ssize_t frameLeft);
  32. static ssize_t pmac_ct_u16(const u_char __user *userPtr, size_t userCount,
  33. u_char frame[], ssize_t *frameUsed,
  34. ssize_t frameLeft);
  35. static ssize_t pmac_ctx_law(const u_char __user *userPtr, size_t userCount,
  36. u_char frame[], ssize_t *frameUsed,
  37. ssize_t frameLeft);
  38. static ssize_t pmac_ctx_s8(const u_char __user *userPtr, size_t userCount,
  39. u_char frame[], ssize_t *frameUsed,
  40. ssize_t frameLeft);
  41. static ssize_t pmac_ctx_u8(const u_char __user *userPtr, size_t userCount,
  42. u_char frame[], ssize_t *frameUsed,
  43. ssize_t frameLeft);
  44. static ssize_t pmac_ctx_s16(const u_char __user *userPtr, size_t userCount,
  45. u_char frame[], ssize_t *frameUsed,
  46. ssize_t frameLeft);
  47. static ssize_t pmac_ctx_u16(const u_char __user *userPtr, size_t userCount,
  48. u_char frame[], ssize_t *frameUsed,
  49. ssize_t frameLeft);
  50. static ssize_t pmac_ct_s16_read(const u_char __user *userPtr, size_t userCount,
  51. u_char frame[], ssize_t *frameUsed,
  52. ssize_t frameLeft);
  53. static ssize_t pmac_ct_u16_read(const u_char __user *userPtr, size_t userCount,
  54. u_char frame[], ssize_t *frameUsed,
  55. ssize_t frameLeft);
  56. /*** Translations ************************************************************/
  57. static int expand_data; /* Data for expanding */
  58. static ssize_t pmac_ct_law(const u_char __user *userPtr, size_t userCount,
  59. u_char frame[], ssize_t *frameUsed,
  60. ssize_t frameLeft)
  61. {
  62. short *table = dmasound.soft.format == AFMT_MU_LAW
  63. ? dmasound_ulaw2dma16 : dmasound_alaw2dma16;
  64. ssize_t count, used;
  65. short *p = (short *) &frame[*frameUsed];
  66. int val, stereo = dmasound.soft.stereo;
  67. frameLeft >>= 2;
  68. if (stereo)
  69. userCount >>= 1;
  70. used = count = min_t(unsigned long, userCount, frameLeft);
  71. while (count > 0) {
  72. u_char data;
  73. if (get_user(data, userPtr++))
  74. return -EFAULT;
  75. val = table[data];
  76. *p++ = val;
  77. if (stereo) {
  78. if (get_user(data, userPtr++))
  79. return -EFAULT;
  80. val = table[data];
  81. }
  82. *p++ = val;
  83. count--;
  84. }
  85. *frameUsed += used * 4;
  86. return stereo? used * 2: used;
  87. }
  88. static ssize_t pmac_ct_s8(const u_char __user *userPtr, size_t userCount,
  89. u_char frame[], ssize_t *frameUsed,
  90. ssize_t frameLeft)
  91. {
  92. ssize_t count, used;
  93. short *p = (short *) &frame[*frameUsed];
  94. int val, stereo = dmasound.soft.stereo;
  95. frameLeft >>= 2;
  96. if (stereo)
  97. userCount >>= 1;
  98. used = count = min_t(unsigned long, userCount, frameLeft);
  99. while (count > 0) {
  100. u_char data;
  101. if (get_user(data, userPtr++))
  102. return -EFAULT;
  103. val = data << 8;
  104. *p++ = val;
  105. if (stereo) {
  106. if (get_user(data, userPtr++))
  107. return -EFAULT;
  108. val = data << 8;
  109. }
  110. *p++ = val;
  111. count--;
  112. }
  113. *frameUsed += used * 4;
  114. return stereo? used * 2: used;
  115. }
  116. static ssize_t pmac_ct_u8(const u_char __user *userPtr, size_t userCount,
  117. u_char frame[], ssize_t *frameUsed,
  118. ssize_t frameLeft)
  119. {
  120. ssize_t count, used;
  121. short *p = (short *) &frame[*frameUsed];
  122. int val, stereo = dmasound.soft.stereo;
  123. frameLeft >>= 2;
  124. if (stereo)
  125. userCount >>= 1;
  126. used = count = min_t(unsigned long, userCount, frameLeft);
  127. while (count > 0) {
  128. u_char data;
  129. if (get_user(data, userPtr++))
  130. return -EFAULT;
  131. val = (data ^ 0x80) << 8;
  132. *p++ = val;
  133. if (stereo) {
  134. if (get_user(data, userPtr++))
  135. return -EFAULT;
  136. val = (data ^ 0x80) << 8;
  137. }
  138. *p++ = val;
  139. count--;
  140. }
  141. *frameUsed += used * 4;
  142. return stereo? used * 2: used;
  143. }
  144. static ssize_t pmac_ct_s16(const u_char __user *userPtr, size_t userCount,
  145. u_char frame[], ssize_t *frameUsed,
  146. ssize_t frameLeft)
  147. {
  148. ssize_t count, used;
  149. int stereo = dmasound.soft.stereo;
  150. short *fp = (short *) &frame[*frameUsed];
  151. frameLeft >>= 2;
  152. userCount >>= (stereo? 2: 1);
  153. used = count = min_t(unsigned long, userCount, frameLeft);
  154. if (!stereo) {
  155. short __user *up = (short __user *) userPtr;
  156. while (count > 0) {
  157. short data;
  158. if (get_user(data, up++))
  159. return -EFAULT;
  160. *fp++ = data;
  161. *fp++ = data;
  162. count--;
  163. }
  164. } else {
  165. if (copy_from_user(fp, userPtr, count * 4))
  166. return -EFAULT;
  167. }
  168. *frameUsed += used * 4;
  169. return stereo? used * 4: used * 2;
  170. }
  171. static ssize_t pmac_ct_u16(const u_char __user *userPtr, size_t userCount,
  172. u_char frame[], ssize_t *frameUsed,
  173. ssize_t frameLeft)
  174. {
  175. ssize_t count, used;
  176. int mask = (dmasound.soft.format == AFMT_U16_LE? 0x0080: 0x8000);
  177. int stereo = dmasound.soft.stereo;
  178. short *fp = (short *) &frame[*frameUsed];
  179. short __user *up = (short __user *) userPtr;
  180. frameLeft >>= 2;
  181. userCount >>= (stereo? 2: 1);
  182. used = count = min_t(unsigned long, userCount, frameLeft);
  183. while (count > 0) {
  184. short data;
  185. if (get_user(data, up++))
  186. return -EFAULT;
  187. data ^= mask;
  188. *fp++ = data;
  189. if (stereo) {
  190. if (get_user(data, up++))
  191. return -EFAULT;
  192. data ^= mask;
  193. }
  194. *fp++ = data;
  195. count--;
  196. }
  197. *frameUsed += used * 4;
  198. return stereo? used * 4: used * 2;
  199. }
  200. static ssize_t pmac_ctx_law(const u_char __user *userPtr, size_t userCount,
  201. u_char frame[], ssize_t *frameUsed,
  202. ssize_t frameLeft)
  203. {
  204. unsigned short *table = (unsigned short *)
  205. (dmasound.soft.format == AFMT_MU_LAW
  206. ? dmasound_ulaw2dma16 : dmasound_alaw2dma16);
  207. unsigned int data = expand_data;
  208. unsigned int *p = (unsigned int *) &frame[*frameUsed];
  209. int bal = expand_bal;
  210. int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
  211. int utotal, ftotal;
  212. int stereo = dmasound.soft.stereo;
  213. frameLeft >>= 2;
  214. if (stereo)
  215. userCount >>= 1;
  216. ftotal = frameLeft;
  217. utotal = userCount;
  218. while (frameLeft) {
  219. u_char c;
  220. if (bal < 0) {
  221. if (userCount == 0)
  222. break;
  223. if (get_user(c, userPtr++))
  224. return -EFAULT;
  225. data = table[c];
  226. if (stereo) {
  227. if (get_user(c, userPtr++))
  228. return -EFAULT;
  229. data = (data << 16) + table[c];
  230. } else
  231. data = (data << 16) + data;
  232. userCount--;
  233. bal += hSpeed;
  234. }
  235. *p++ = data;
  236. frameLeft--;
  237. bal -= sSpeed;
  238. }
  239. expand_bal = bal;
  240. expand_data = data;
  241. *frameUsed += (ftotal - frameLeft) * 4;
  242. utotal -= userCount;
  243. return stereo? utotal * 2: utotal;
  244. }
  245. static ssize_t pmac_ctx_s8(const u_char __user *userPtr, size_t userCount,
  246. u_char frame[], ssize_t *frameUsed,
  247. ssize_t frameLeft)
  248. {
  249. unsigned int *p = (unsigned int *) &frame[*frameUsed];
  250. unsigned int data = expand_data;
  251. int bal = expand_bal;
  252. int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
  253. int stereo = dmasound.soft.stereo;
  254. int utotal, ftotal;
  255. frameLeft >>= 2;
  256. if (stereo)
  257. userCount >>= 1;
  258. ftotal = frameLeft;
  259. utotal = userCount;
  260. while (frameLeft) {
  261. u_char c;
  262. if (bal < 0) {
  263. if (userCount == 0)
  264. break;
  265. if (get_user(c, userPtr++))
  266. return -EFAULT;
  267. data = c << 8;
  268. if (stereo) {
  269. if (get_user(c, userPtr++))
  270. return -EFAULT;
  271. data = (data << 16) + (c << 8);
  272. } else
  273. data = (data << 16) + data;
  274. userCount--;
  275. bal += hSpeed;
  276. }
  277. *p++ = data;
  278. frameLeft--;
  279. bal -= sSpeed;
  280. }
  281. expand_bal = bal;
  282. expand_data = data;
  283. *frameUsed += (ftotal - frameLeft) * 4;
  284. utotal -= userCount;
  285. return stereo? utotal * 2: utotal;
  286. }
  287. static ssize_t pmac_ctx_u8(const u_char __user *userPtr, size_t userCount,
  288. u_char frame[], ssize_t *frameUsed,
  289. ssize_t frameLeft)
  290. {
  291. unsigned int *p = (unsigned int *) &frame[*frameUsed];
  292. unsigned int data = expand_data;
  293. int bal = expand_bal;
  294. int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
  295. int stereo = dmasound.soft.stereo;
  296. int utotal, ftotal;
  297. frameLeft >>= 2;
  298. if (stereo)
  299. userCount >>= 1;
  300. ftotal = frameLeft;
  301. utotal = userCount;
  302. while (frameLeft) {
  303. u_char c;
  304. if (bal < 0) {
  305. if (userCount == 0)
  306. break;
  307. if (get_user(c, userPtr++))
  308. return -EFAULT;
  309. data = (c ^ 0x80) << 8;
  310. if (stereo) {
  311. if (get_user(c, userPtr++))
  312. return -EFAULT;
  313. data = (data << 16) + ((c ^ 0x80) << 8);
  314. } else
  315. data = (data << 16) + data;
  316. userCount--;
  317. bal += hSpeed;
  318. }
  319. *p++ = data;
  320. frameLeft--;
  321. bal -= sSpeed;
  322. }
  323. expand_bal = bal;
  324. expand_data = data;
  325. *frameUsed += (ftotal - frameLeft) * 4;
  326. utotal -= userCount;
  327. return stereo? utotal * 2: utotal;
  328. }
  329. static ssize_t pmac_ctx_s16(const u_char __user *userPtr, size_t userCount,
  330. u_char frame[], ssize_t *frameUsed,
  331. ssize_t frameLeft)
  332. {
  333. unsigned int *p = (unsigned int *) &frame[*frameUsed];
  334. unsigned int data = expand_data;
  335. unsigned short __user *up = (unsigned short __user *) userPtr;
  336. int bal = expand_bal;
  337. int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
  338. int stereo = dmasound.soft.stereo;
  339. int utotal, ftotal;
  340. frameLeft >>= 2;
  341. userCount >>= (stereo? 2: 1);
  342. ftotal = frameLeft;
  343. utotal = userCount;
  344. while (frameLeft) {
  345. unsigned short c;
  346. if (bal < 0) {
  347. if (userCount == 0)
  348. break;
  349. if (get_user(data, up++))
  350. return -EFAULT;
  351. if (stereo) {
  352. if (get_user(c, up++))
  353. return -EFAULT;
  354. data = (data << 16) + c;
  355. } else
  356. data = (data << 16) + data;
  357. userCount--;
  358. bal += hSpeed;
  359. }
  360. *p++ = data;
  361. frameLeft--;
  362. bal -= sSpeed;
  363. }
  364. expand_bal = bal;
  365. expand_data = data;
  366. *frameUsed += (ftotal - frameLeft) * 4;
  367. utotal -= userCount;
  368. return stereo? utotal * 4: utotal * 2;
  369. }
  370. static ssize_t pmac_ctx_u16(const u_char __user *userPtr, size_t userCount,
  371. u_char frame[], ssize_t *frameUsed,
  372. ssize_t frameLeft)
  373. {
  374. int mask = (dmasound.soft.format == AFMT_U16_LE? 0x0080: 0x8000);
  375. unsigned int *p = (unsigned int *) &frame[*frameUsed];
  376. unsigned int data = expand_data;
  377. unsigned short __user *up = (unsigned short __user *) userPtr;
  378. int bal = expand_bal;
  379. int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
  380. int stereo = dmasound.soft.stereo;
  381. int utotal, ftotal;
  382. frameLeft >>= 2;
  383. userCount >>= (stereo? 2: 1);
  384. ftotal = frameLeft;
  385. utotal = userCount;
  386. while (frameLeft) {
  387. unsigned short c;
  388. if (bal < 0) {
  389. if (userCount == 0)
  390. break;
  391. if (get_user(data, up++))
  392. return -EFAULT;
  393. data ^= mask;
  394. if (stereo) {
  395. if (get_user(c, up++))
  396. return -EFAULT;
  397. data = (data << 16) + (c ^ mask);
  398. } else
  399. data = (data << 16) + data;
  400. userCount--;
  401. bal += hSpeed;
  402. }
  403. *p++ = data;
  404. frameLeft--;
  405. bal -= sSpeed;
  406. }
  407. expand_bal = bal;
  408. expand_data = data;
  409. *frameUsed += (ftotal - frameLeft) * 4;
  410. utotal -= userCount;
  411. return stereo? utotal * 4: utotal * 2;
  412. }
  413. /* data in routines... */
  414. static ssize_t pmac_ct_s8_read(const u_char __user *userPtr, size_t userCount,
  415. u_char frame[], ssize_t *frameUsed,
  416. ssize_t frameLeft)
  417. {
  418. ssize_t count, used;
  419. short *p = (short *) &frame[*frameUsed];
  420. int val, stereo = dmasound.soft.stereo;
  421. frameLeft >>= 2;
  422. if (stereo)
  423. userCount >>= 1;
  424. used = count = min_t(unsigned long, userCount, frameLeft);
  425. while (count > 0) {
  426. u_char data;
  427. val = *p++;
  428. val = (val * software_input_volume) >> 7;
  429. data = val >> 8;
  430. if (put_user(data, (u_char __user *)userPtr++))
  431. return -EFAULT;
  432. if (stereo) {
  433. val = *p;
  434. val = (val * software_input_volume) >> 7;
  435. data = val >> 8;
  436. if (put_user(data, (u_char __user *)userPtr++))
  437. return -EFAULT;
  438. }
  439. p++;
  440. count--;
  441. }
  442. *frameUsed += used * 4;
  443. return stereo? used * 2: used;
  444. }
  445. static ssize_t pmac_ct_u8_read(const u_char __user *userPtr, size_t userCount,
  446. u_char frame[], ssize_t *frameUsed,
  447. ssize_t frameLeft)
  448. {
  449. ssize_t count, used;
  450. short *p = (short *) &frame[*frameUsed];
  451. int val, stereo = dmasound.soft.stereo;
  452. frameLeft >>= 2;
  453. if (stereo)
  454. userCount >>= 1;
  455. used = count = min_t(unsigned long, userCount, frameLeft);
  456. while (count > 0) {
  457. u_char data;
  458. val = *p++;
  459. val = (val * software_input_volume) >> 7;
  460. data = (val >> 8) ^ 0x80;
  461. if (put_user(data, (u_char __user *)userPtr++))
  462. return -EFAULT;
  463. if (stereo) {
  464. val = *p;
  465. val = (val * software_input_volume) >> 7;
  466. data = (val >> 8) ^ 0x80;
  467. if (put_user(data, (u_char __user *)userPtr++))
  468. return -EFAULT;
  469. }
  470. p++;
  471. count--;
  472. }
  473. *frameUsed += used * 4;
  474. return stereo? used * 2: used;
  475. }
  476. static ssize_t pmac_ct_s16_read(const u_char __user *userPtr, size_t userCount,
  477. u_char frame[], ssize_t *frameUsed,
  478. ssize_t frameLeft)
  479. {
  480. ssize_t count, used;
  481. int stereo = dmasound.soft.stereo;
  482. short *fp = (short *) &frame[*frameUsed];
  483. short __user *up = (short __user *) userPtr;
  484. frameLeft >>= 2;
  485. userCount >>= (stereo? 2: 1);
  486. used = count = min_t(unsigned long, userCount, frameLeft);
  487. while (count > 0) {
  488. short data;
  489. data = *fp++;
  490. data = (data * software_input_volume) >> 7;
  491. if (put_user(data, up++))
  492. return -EFAULT;
  493. if (stereo) {
  494. data = *fp;
  495. data = (data * software_input_volume) >> 7;
  496. if (put_user(data, up++))
  497. return -EFAULT;
  498. }
  499. fp++;
  500. count--;
  501. }
  502. *frameUsed += used * 4;
  503. return stereo? used * 4: used * 2;
  504. }
  505. static ssize_t pmac_ct_u16_read(const u_char __user *userPtr, size_t userCount,
  506. u_char frame[], ssize_t *frameUsed,
  507. ssize_t frameLeft)
  508. {
  509. ssize_t count, used;
  510. int mask = (dmasound.soft.format == AFMT_U16_LE? 0x0080: 0x8000);
  511. int stereo = dmasound.soft.stereo;
  512. short *fp = (short *) &frame[*frameUsed];
  513. short __user *up = (short __user *) userPtr;
  514. frameLeft >>= 2;
  515. userCount >>= (stereo? 2: 1);
  516. used = count = min_t(unsigned long, userCount, frameLeft);
  517. while (count > 0) {
  518. int data;
  519. data = *fp++;
  520. data = (data * software_input_volume) >> 7;
  521. data ^= mask;
  522. if (put_user(data, up++))
  523. return -EFAULT;
  524. if (stereo) {
  525. data = *fp;
  526. data = (data * software_input_volume) >> 7;
  527. data ^= mask;
  528. if (put_user(data, up++))
  529. return -EFAULT;
  530. }
  531. fp++;
  532. count--;
  533. }
  534. *frameUsed += used * 4;
  535. return stereo? used * 4: used * 2;
  536. }
  537. /* data in routines (reducing speed)... */
  538. static ssize_t pmac_ctx_s8_read(const u_char __user *userPtr, size_t userCount,
  539. u_char frame[], ssize_t *frameUsed,
  540. ssize_t frameLeft)
  541. {
  542. short *p = (short *) &frame[*frameUsed];
  543. int bal = expand_read_bal;
  544. int vall,valr, stereo = dmasound.soft.stereo;
  545. int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
  546. int utotal, ftotal;
  547. frameLeft >>= 2;
  548. if (stereo)
  549. userCount >>= 1;
  550. ftotal = frameLeft;
  551. utotal = userCount;
  552. while (frameLeft) {
  553. u_char data;
  554. if (bal<0 && userCount == 0)
  555. break;
  556. vall = *p++;
  557. vall = (vall * software_input_volume) >> 7;
  558. if (stereo) {
  559. valr = *p;
  560. valr = (valr * software_input_volume) >> 7;
  561. }
  562. p++;
  563. if (bal < 0) {
  564. data = vall >> 8;
  565. if (put_user(data, (u_char __user *)userPtr++))
  566. return -EFAULT;
  567. if (stereo) {
  568. data = valr >> 8;
  569. if (put_user(data, (u_char __user *)userPtr++))
  570. return -EFAULT;
  571. }
  572. userCount--;
  573. bal += hSpeed;
  574. }
  575. frameLeft--;
  576. bal -= sSpeed;
  577. }
  578. expand_read_bal=bal;
  579. *frameUsed += (ftotal - frameLeft) * 4;
  580. utotal -= userCount;
  581. return stereo? utotal * 2: utotal;
  582. }
  583. static ssize_t pmac_ctx_u8_read(const u_char __user *userPtr, size_t userCount,
  584. u_char frame[], ssize_t *frameUsed,
  585. ssize_t frameLeft)
  586. {
  587. short *p = (short *) &frame[*frameUsed];
  588. int bal = expand_read_bal;
  589. int vall,valr, stereo = dmasound.soft.stereo;
  590. int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
  591. int utotal, ftotal;
  592. frameLeft >>= 2;
  593. if (stereo)
  594. userCount >>= 1;
  595. ftotal = frameLeft;
  596. utotal = userCount;
  597. while (frameLeft) {
  598. u_char data;
  599. if (bal<0 && userCount == 0)
  600. break;
  601. vall = *p++;
  602. vall = (vall * software_input_volume) >> 7;
  603. if (stereo) {
  604. valr = *p;
  605. valr = (valr * software_input_volume) >> 7;
  606. }
  607. p++;
  608. if (bal < 0) {
  609. data = (vall >> 8) ^ 0x80;
  610. if (put_user(data, (u_char __user *)userPtr++))
  611. return -EFAULT;
  612. if (stereo) {
  613. data = (valr >> 8) ^ 0x80;
  614. if (put_user(data, (u_char __user *)userPtr++))
  615. return -EFAULT;
  616. }
  617. userCount--;
  618. bal += hSpeed;
  619. }
  620. frameLeft--;
  621. bal -= sSpeed;
  622. }
  623. expand_read_bal=bal;
  624. *frameUsed += (ftotal - frameLeft) * 4;
  625. utotal -= userCount;
  626. return stereo? utotal * 2: utotal;
  627. }
  628. static ssize_t pmac_ctx_s16_read(const u_char __user *userPtr, size_t userCount,
  629. u_char frame[], ssize_t *frameUsed,
  630. ssize_t frameLeft)
  631. {
  632. int bal = expand_read_bal;
  633. short *fp = (short *) &frame[*frameUsed];
  634. short __user *up = (short __user *) userPtr;
  635. int stereo = dmasound.soft.stereo;
  636. int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
  637. int utotal, ftotal;
  638. frameLeft >>= 2;
  639. userCount >>= (stereo? 2: 1);
  640. ftotal = frameLeft;
  641. utotal = userCount;
  642. while (frameLeft) {
  643. int datal,datar;
  644. if (bal<0 && userCount == 0)
  645. break;
  646. datal = *fp++;
  647. datal = (datal * software_input_volume) >> 7;
  648. if (stereo) {
  649. datar = *fp;
  650. datar = (datar * software_input_volume) >> 7;
  651. }
  652. fp++;
  653. if (bal < 0) {
  654. if (put_user(datal, up++))
  655. return -EFAULT;
  656. if (stereo) {
  657. if (put_user(datar, up++))
  658. return -EFAULT;
  659. }
  660. userCount--;
  661. bal += hSpeed;
  662. }
  663. frameLeft--;
  664. bal -= sSpeed;
  665. }
  666. expand_read_bal=bal;
  667. *frameUsed += (ftotal - frameLeft) * 4;
  668. utotal -= userCount;
  669. return stereo? utotal * 4: utotal * 2;
  670. }
  671. static ssize_t pmac_ctx_u16_read(const u_char __user *userPtr, size_t userCount,
  672. u_char frame[], ssize_t *frameUsed,
  673. ssize_t frameLeft)
  674. {
  675. int bal = expand_read_bal;
  676. int mask = (dmasound.soft.format == AFMT_U16_LE? 0x0080: 0x8000);
  677. short *fp = (short *) &frame[*frameUsed];
  678. short __user *up = (short __user *) userPtr;
  679. int stereo = dmasound.soft.stereo;
  680. int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
  681. int utotal, ftotal;
  682. frameLeft >>= 2;
  683. userCount >>= (stereo? 2: 1);
  684. ftotal = frameLeft;
  685. utotal = userCount;
  686. while (frameLeft) {
  687. int datal,datar;
  688. if (bal<0 && userCount == 0)
  689. break;
  690. datal = *fp++;
  691. datal = (datal * software_input_volume) >> 7;
  692. datal ^= mask;
  693. if (stereo) {
  694. datar = *fp;
  695. datar = (datar * software_input_volume) >> 7;
  696. datar ^= mask;
  697. }
  698. fp++;
  699. if (bal < 0) {
  700. if (put_user(datal, up++))
  701. return -EFAULT;
  702. if (stereo) {
  703. if (put_user(datar, up++))
  704. return -EFAULT;
  705. }
  706. userCount--;
  707. bal += hSpeed;
  708. }
  709. frameLeft--;
  710. bal -= sSpeed;
  711. }
  712. expand_read_bal=bal;
  713. *frameUsed += (ftotal - frameLeft) * 4;
  714. utotal -= userCount;
  715. return stereo? utotal * 4: utotal * 2;
  716. }
  717. TRANS transAwacsNormal = {
  718. .ct_ulaw= pmac_ct_law,
  719. .ct_alaw= pmac_ct_law,
  720. .ct_s8= pmac_ct_s8,
  721. .ct_u8= pmac_ct_u8,
  722. .ct_s16be= pmac_ct_s16,
  723. .ct_u16be= pmac_ct_u16,
  724. .ct_s16le= pmac_ct_s16,
  725. .ct_u16le= pmac_ct_u16,
  726. };
  727. TRANS transAwacsExpand = {
  728. .ct_ulaw= pmac_ctx_law,
  729. .ct_alaw= pmac_ctx_law,
  730. .ct_s8= pmac_ctx_s8,
  731. .ct_u8= pmac_ctx_u8,
  732. .ct_s16be= pmac_ctx_s16,
  733. .ct_u16be= pmac_ctx_u16,
  734. .ct_s16le= pmac_ctx_s16,
  735. .ct_u16le= pmac_ctx_u16,
  736. };
  737. TRANS transAwacsNormalRead = {
  738. .ct_s8= pmac_ct_s8_read,
  739. .ct_u8= pmac_ct_u8_read,
  740. .ct_s16be= pmac_ct_s16_read,
  741. .ct_u16be= pmac_ct_u16_read,
  742. .ct_s16le= pmac_ct_s16_read,
  743. .ct_u16le= pmac_ct_u16_read,
  744. };
  745. TRANS transAwacsExpandRead = {
  746. .ct_s8= pmac_ctx_s8_read,
  747. .ct_u8= pmac_ctx_u8_read,
  748. .ct_s16be= pmac_ctx_s16_read,
  749. .ct_u16be= pmac_ctx_u16_read,
  750. .ct_s16le= pmac_ctx_s16_read,
  751. .ct_u16le= pmac_ctx_u16_read,
  752. };
  753. /* translation tables */
  754. /* 16 bit mu-law */
  755. static short dmasound_ulaw2dma16[] = {
  756. -32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956,
  757. -23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764,
  758. -15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412,
  759. -11900, -11388, -10876, -10364, -9852, -9340, -8828, -8316,
  760. -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
  761. -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
  762. -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
  763. -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
  764. -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
  765. -1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
  766. -876, -844, -812, -780, -748, -716, -684, -652,
  767. -620, -588, -556, -524, -492, -460, -428, -396,
  768. -372, -356, -340, -324, -308, -292, -276, -260,
  769. -244, -228, -212, -196, -180, -164, -148, -132,
  770. -120, -112, -104, -96, -88, -80, -72, -64,
  771. -56, -48, -40, -32, -24, -16, -8, 0,
  772. 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
  773. 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
  774. 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
  775. 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
  776. 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
  777. 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
  778. 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
  779. 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
  780. 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436,
  781. 1372, 1308, 1244, 1180, 1116, 1052, 988, 924,
  782. 876, 844, 812, 780, 748, 716, 684, 652,
  783. 620, 588, 556, 524, 492, 460, 428, 396,
  784. 372, 356, 340, 324, 308, 292, 276, 260,
  785. 244, 228, 212, 196, 180, 164, 148, 132,
  786. 120, 112, 104, 96, 88, 80, 72, 64,
  787. 56, 48, 40, 32, 24, 16, 8, 0,
  788. };
  789. /* 16 bit A-law */
  790. static short dmasound_alaw2dma16[] = {
  791. -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736,
  792. -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784,
  793. -2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368,
  794. -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392,
  795. -22016, -20992, -24064, -23040, -17920, -16896, -19968, -18944,
  796. -30208, -29184, -32256, -31232, -26112, -25088, -28160, -27136,
  797. -11008, -10496, -12032, -11520, -8960, -8448, -9984, -9472,
  798. -15104, -14592, -16128, -15616, -13056, -12544, -14080, -13568,
  799. -344, -328, -376, -360, -280, -264, -312, -296,
  800. -472, -456, -504, -488, -408, -392, -440, -424,
  801. -88, -72, -120, -104, -24, -8, -56, -40,
  802. -216, -200, -248, -232, -152, -136, -184, -168,
  803. -1376, -1312, -1504, -1440, -1120, -1056, -1248, -1184,
  804. -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696,
  805. -688, -656, -752, -720, -560, -528, -624, -592,
  806. -944, -912, -1008, -976, -816, -784, -880, -848,
  807. 5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736,
  808. 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784,
  809. 2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368,
  810. 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392,
  811. 22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944,
  812. 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136,
  813. 11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472,
  814. 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568,
  815. 344, 328, 376, 360, 280, 264, 312, 296,
  816. 472, 456, 504, 488, 408, 392, 440, 424,
  817. 88, 72, 120, 104, 24, 8, 56, 40,
  818. 216, 200, 248, 232, 152, 136, 184, 168,
  819. 1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184,
  820. 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696,
  821. 688, 656, 752, 720, 560, 528, 624, 592,
  822. 944, 912, 1008, 976, 816, 784, 880, 848,
  823. };