trans_16.c 23 KB

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