pcm-indirect2.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /*
  2. * Helper functions for indirect PCM data transfer to a simple FIFO in
  3. * hardware (small, no possibility to read "hardware io position",
  4. * updating position done by interrupt, ...)
  5. *
  6. * Copyright (c) by 2007 Joachim Foerster <JOFT@gmx.de>
  7. *
  8. * Based on "pcm-indirect.h" (alsa-driver-1.0.13) by
  9. *
  10. * Copyright (c) by Takashi Iwai <tiwai@suse.de>
  11. * Jaroslav Kysela <perex@suse.cz>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. */
  27. /* #dependency of sound/core.h# */
  28. #include <sound/driver.h>
  29. /* snd_printk/d() */
  30. #include <sound/core.h>
  31. /* struct snd_pcm_substream, struct snd_pcm_runtime, snd_pcm_uframes_t
  32. * snd_pcm_period_elapsed() */
  33. #include <sound/pcm.h>
  34. #include "pcm-indirect2.h"
  35. #ifdef SND_PCM_INDIRECT2_STAT
  36. /* jiffies */
  37. #include <linux/jiffies.h>
  38. void snd_pcm_indirect2_stat(struct snd_pcm_substream *substream,
  39. struct snd_pcm_indirect2 *rec)
  40. {
  41. struct snd_pcm_runtime *runtime = substream->runtime;
  42. int i;
  43. int j;
  44. int k;
  45. int seconds = (rec->lastbytetime - rec->firstbytetime) / HZ;
  46. snd_printk(KERN_DEBUG "STAT: mul_elapsed: %u, mul_elapsed_real: %d, "
  47. "irq_occured: %d\n",
  48. rec->mul_elapsed, rec->mul_elapsed_real, rec->irq_occured);
  49. snd_printk(KERN_DEBUG "STAT: min_multiple: %d (irqs/period)\n",
  50. rec->min_multiple);
  51. snd_printk(KERN_DEBUG "STAT: firstbytetime: %lu, lastbytetime: %lu, "
  52. "firstzerotime: %lu\n",
  53. rec->firstbytetime, rec->lastbytetime, rec->firstzerotime);
  54. snd_printk(KERN_DEBUG "STAT: bytes2hw: %u Bytes => (by runtime->rate) "
  55. "length: %d s\n",
  56. rec->bytes2hw, rec->bytes2hw / 2 / 2 / runtime->rate);
  57. snd_printk(KERN_DEBUG "STAT: (by measurement) length: %d => "
  58. "rate: %d Bytes/s = %d Frames/s|Hz\n",
  59. seconds, rec->bytes2hw / seconds,
  60. rec->bytes2hw / 2 / 2 / seconds);
  61. snd_printk(KERN_DEBUG
  62. "STAT: zeros2hw: %u = %d ms ~ %d * %d zero copies\n",
  63. rec->zeros2hw, ((rec->zeros2hw / 2 / 2) * 1000) /
  64. runtime->rate,
  65. rec->zeros2hw / (rec->hw_buffer_size / 2),
  66. (rec->hw_buffer_size / 2));
  67. snd_printk(KERN_DEBUG "STAT: pointer_calls: %u, lastdifftime: %u\n",
  68. rec->pointer_calls, rec->lastdifftime);
  69. snd_printk(KERN_DEBUG "STAT: sw_io: %d, sw_data: %d\n", rec->sw_io,
  70. rec->sw_data);
  71. snd_printk(KERN_DEBUG "STAT: byte_sizes[]:\n");
  72. k = 0;
  73. for (j = 0; j < 8; j++) {
  74. for (i = j * 8; i < (j + 1) * 8; i++)
  75. if (rec->byte_sizes[i] != 0) {
  76. snd_printk(KERN_DEBUG "%u: %u",
  77. i, rec->byte_sizes[i]);
  78. k++;
  79. }
  80. if (((k % 8) == 0) && (k != 0)) {
  81. snd_printk(KERN_DEBUG "\n");
  82. k = 0;
  83. }
  84. }
  85. snd_printk(KERN_DEBUG "\n");
  86. snd_printk(KERN_DEBUG "STAT: zero_sizes[]:\n");
  87. for (j = 0; j < 8; j++) {
  88. k = 0;
  89. for (i = j * 8; i < (j + 1) * 8; i++)
  90. if (rec->zero_sizes[i] != 0)
  91. snd_printk(KERN_DEBUG "%u: %u",
  92. i, rec->zero_sizes[i]);
  93. else
  94. k++;
  95. if (!k)
  96. snd_printk(KERN_DEBUG "\n");
  97. }
  98. snd_printk(KERN_DEBUG "\n");
  99. snd_printk(KERN_DEBUG "STAT: min_adds[]:\n");
  100. for (j = 0; j < 8; j++) {
  101. if (rec->min_adds[j] != 0)
  102. snd_printk(KERN_DEBUG "%u: %u", j, rec->min_adds[j]);
  103. }
  104. snd_printk(KERN_DEBUG "\n");
  105. snd_printk(KERN_DEBUG "STAT: mul_adds[]:\n");
  106. for (j = 0; j < 8; j++) {
  107. if (rec->mul_adds[j] != 0)
  108. snd_printk(KERN_DEBUG "%u: %u", j, rec->mul_adds[j]);
  109. }
  110. snd_printk(KERN_DEBUG "\n");
  111. snd_printk(KERN_DEBUG
  112. "STAT: zero_times_saved: %d, zero_times_notsaved: %d\n",
  113. rec->zero_times_saved, rec->zero_times_notsaved);
  114. /* snd_printk(KERN_DEBUG "STAT: zero_times[]\n");
  115. i = 0;
  116. for (j = 0; j < 3750; j++) {
  117. if (rec->zero_times[j] != 0) {
  118. snd_printk(KERN_DEBUG "%u: %u", j, rec->zero_times[j]);
  119. i++;
  120. }
  121. if (((i % 8) == 0) && (i != 0))
  122. snd_printk(KERN_DEBUG "\n");
  123. }
  124. snd_printk(KERN_DEBUG "\n"); */
  125. return;
  126. }
  127. #endif
  128. /*
  129. * _internal_ helper function for playback/capture transfer function
  130. */
  131. static void
  132. snd_pcm_indirect2_increase_min_periods(struct snd_pcm_substream *substream,
  133. struct snd_pcm_indirect2 *rec,
  134. int isplay, int iscopy,
  135. unsigned int bytes)
  136. {
  137. if (rec->min_periods >= 0) {
  138. if (iscopy) {
  139. rec->sw_io += bytes;
  140. if (rec->sw_io >= rec->sw_buffer_size)
  141. rec->sw_io -= rec->sw_buffer_size;
  142. } else if (isplay) {
  143. /* If application does not write data in multiples of
  144. * a period, move sw_data to the next correctly aligned
  145. * position, so that sw_io can converge to it (in the
  146. * next step).
  147. */
  148. if (!rec->check_alignment) {
  149. if (rec->bytes2hw %
  150. snd_pcm_lib_period_bytes(substream)) {
  151. unsigned bytes2hw_aligned =
  152. (1 +
  153. (rec->bytes2hw /
  154. snd_pcm_lib_period_bytes
  155. (substream))) *
  156. snd_pcm_lib_period_bytes
  157. (substream);
  158. rec->sw_data =
  159. bytes2hw_aligned %
  160. rec->sw_buffer_size;
  161. #ifdef SND_PCM_INDIRECT2_STAT
  162. snd_printk(KERN_DEBUG
  163. "STAT: @re-align: aligned "
  164. "bytes2hw to next period "
  165. "size boundary: %d "
  166. "(instead of %d)\n",
  167. bytes2hw_aligned,
  168. rec->bytes2hw);
  169. snd_printk(KERN_DEBUG
  170. "STAT: @re-align: sw_data "
  171. "moves to: %d\n",
  172. rec->sw_data);
  173. #endif
  174. }
  175. rec->check_alignment = 1;
  176. }
  177. /* We are at the end and are copying zeros into the
  178. * fifo.
  179. * Now, we have to make sure that sw_io is increased
  180. * until the position of sw_data: Filling the fifo with
  181. * the first zeros means, the last bytes were played.
  182. */
  183. if (rec->sw_io != rec->sw_data) {
  184. unsigned int diff;
  185. if (rec->sw_data > rec->sw_io)
  186. diff = rec->sw_data - rec->sw_io;
  187. else
  188. diff = (rec->sw_buffer_size -
  189. rec->sw_io) +
  190. rec->sw_data;
  191. if (bytes >= diff)
  192. rec->sw_io = rec->sw_data;
  193. else {
  194. rec->sw_io += bytes;
  195. if (rec->sw_io >= rec->sw_buffer_size)
  196. rec->sw_io -=
  197. rec->sw_buffer_size;
  198. }
  199. }
  200. }
  201. rec->min_period_count += bytes;
  202. if (rec->min_period_count >= (rec->hw_buffer_size / 2)) {
  203. rec->min_periods += (rec->min_period_count /
  204. (rec->hw_buffer_size / 2));
  205. #ifdef SND_PCM_INDIRECT2_STAT
  206. if ((rec->min_period_count /
  207. (rec->hw_buffer_size / 2)) > 7)
  208. snd_printk(KERN_DEBUG
  209. "STAT: more than 7 (%d) min_adds "
  210. "at once - too big to save!\n",
  211. (rec->min_period_count /
  212. (rec->hw_buffer_size / 2)));
  213. else
  214. rec->min_adds[(rec->min_period_count /
  215. (rec->hw_buffer_size / 2))]++;
  216. #endif
  217. rec->min_period_count = (rec->min_period_count %
  218. (rec->hw_buffer_size / 2));
  219. }
  220. } else if (isplay && iscopy)
  221. rec->min_periods = 0;
  222. }
  223. /*
  224. * helper function for playback/capture pointer callback
  225. */
  226. snd_pcm_uframes_t
  227. snd_pcm_indirect2_pointer(struct snd_pcm_substream *substream,
  228. struct snd_pcm_indirect2 *rec)
  229. {
  230. #ifdef SND_PCM_INDIRECT2_STAT
  231. rec->pointer_calls++;
  232. #endif
  233. return bytes_to_frames(substream->runtime, rec->sw_io);
  234. }
  235. /*
  236. * _internal_ helper function for playback interrupt callback
  237. */
  238. static void
  239. snd_pcm_indirect2_playback_transfer(struct snd_pcm_substream *substream,
  240. struct snd_pcm_indirect2 *rec,
  241. snd_pcm_indirect2_copy_t copy,
  242. snd_pcm_indirect2_zero_t zero)
  243. {
  244. struct snd_pcm_runtime *runtime = substream->runtime;
  245. snd_pcm_uframes_t appl_ptr = runtime->control->appl_ptr;
  246. /* runtime->control->appl_ptr: position where ALSA will write next time
  247. * rec->appl_ptr: position where ALSA was last time
  248. * diff: obviously ALSA wrote that much bytes into the intermediate
  249. * buffer since we checked last time
  250. */
  251. snd_pcm_sframes_t diff = appl_ptr - rec->appl_ptr;
  252. if (diff) {
  253. #ifdef SND_PCM_INDIRECT2_STAT
  254. rec->lastdifftime = jiffies;
  255. #endif
  256. if (diff < -(snd_pcm_sframes_t) (runtime->boundary / 2))
  257. diff += runtime->boundary;
  258. /* number of bytes "added" by ALSA increases the number of
  259. * bytes which are ready to "be transfered to HW"/"played"
  260. * Then, set rec->appl_ptr to not count bytes twice next time.
  261. */
  262. rec->sw_ready += (int)frames_to_bytes(runtime, diff);
  263. rec->appl_ptr = appl_ptr;
  264. }
  265. if (rec->hw_ready && (rec->sw_ready <= 0)) {
  266. unsigned int bytes;
  267. #ifdef SND_PCM_INDIRECT2_STAT
  268. if (rec->firstzerotime == 0) {
  269. rec->firstzerotime = jiffies;
  270. snd_printk(KERN_DEBUG
  271. "STAT: @firstzerotime: mul_elapsed: %d, "
  272. "min_period_count: %d\n",
  273. rec->mul_elapsed, rec->min_period_count);
  274. snd_printk(KERN_DEBUG
  275. "STAT: @firstzerotime: sw_io: %d, "
  276. "sw_data: %d, appl_ptr: %u\n",
  277. rec->sw_io, rec->sw_data,
  278. (unsigned int)appl_ptr);
  279. }
  280. if ((jiffies - rec->firstzerotime) < 3750) {
  281. rec->zero_times[(jiffies - rec->firstzerotime)]++;
  282. rec->zero_times_saved++;
  283. } else
  284. rec->zero_times_notsaved++;
  285. #endif
  286. bytes = zero(substream, rec);
  287. #ifdef SND_PCM_INDIRECT2_STAT
  288. rec->zeros2hw += bytes;
  289. if (bytes < 64)
  290. rec->zero_sizes[bytes]++;
  291. else
  292. snd_printk(KERN_DEBUG
  293. "STAT: %d zero Bytes copied to hardware at "
  294. "once - too big to save!\n",
  295. bytes);
  296. #endif
  297. snd_pcm_indirect2_increase_min_periods(substream, rec, 1, 0,
  298. bytes);
  299. return;
  300. }
  301. while (rec->hw_ready && (rec->sw_ready > 0)) {
  302. /* sw_to_end: max. number of bytes that can be read/take from
  303. * the current position (sw_data) in _one_ step
  304. */
  305. unsigned int sw_to_end = rec->sw_buffer_size - rec->sw_data;
  306. /* bytes: number of bytes we have available (for reading) */
  307. unsigned int bytes = rec->sw_ready;
  308. if (sw_to_end < bytes)
  309. bytes = sw_to_end;
  310. if (!bytes)
  311. break;
  312. #ifdef SND_PCM_INDIRECT2_STAT
  313. if (rec->firstbytetime == 0)
  314. rec->firstbytetime = jiffies;
  315. rec->lastbytetime = jiffies;
  316. #endif
  317. /* copy bytes from intermediate buffer position sw_data to the
  318. * HW and return number of bytes actually written
  319. * Furthermore, set hw_ready to 0, if the fifo isn't empty
  320. * now => more could be transfered to fifo
  321. */
  322. bytes = copy(substream, rec, bytes);
  323. rec->bytes2hw += bytes;
  324. #ifdef SND_PCM_INDIRECT2_STAT
  325. if (bytes < 64)
  326. rec->byte_sizes[bytes]++;
  327. else
  328. snd_printk(KERN_DEBUG
  329. "STAT: %d Bytes copied to hardware at once "
  330. "- too big to save!\n",
  331. bytes);
  332. #endif
  333. /* increase sw_data by the number of actually written bytes
  334. * (= number of taken bytes from intermediate buffer)
  335. */
  336. rec->sw_data += bytes;
  337. if (rec->sw_data == rec->sw_buffer_size)
  338. rec->sw_data = 0;
  339. /* now sw_data is the position where ALSA is going to write
  340. * in the intermediate buffer next time = position we are going
  341. * to read from next time
  342. */
  343. snd_pcm_indirect2_increase_min_periods(substream, rec, 1, 1,
  344. bytes);
  345. /* we read bytes from intermediate buffer, so we need to say
  346. * that the number of bytes ready for transfer are decreased
  347. * now
  348. */
  349. rec->sw_ready -= bytes;
  350. }
  351. return;
  352. }
  353. /*
  354. * helper function for playback interrupt routine
  355. */
  356. void
  357. snd_pcm_indirect2_playback_interrupt(struct snd_pcm_substream *substream,
  358. struct snd_pcm_indirect2 *rec,
  359. snd_pcm_indirect2_copy_t copy,
  360. snd_pcm_indirect2_zero_t zero)
  361. {
  362. #ifdef SND_PCM_INDIRECT2_STAT
  363. rec->irq_occured++;
  364. #endif
  365. /* hardware played some bytes, so there is room again (in fifo) */
  366. rec->hw_ready = 1;
  367. /* don't call ack() now, instead call transfer() function directly
  368. * (normally called by ack() )
  369. */
  370. snd_pcm_indirect2_playback_transfer(substream, rec, copy, zero);
  371. if (rec->min_periods >= rec->min_multiple) {
  372. #ifdef SND_PCM_INDIRECT2_STAT
  373. if ((rec->min_periods / rec->min_multiple) > 7)
  374. snd_printk(KERN_DEBUG
  375. "STAT: more than 7 (%d) mul_adds - too big "
  376. "to save!\n",
  377. (rec->min_periods / rec->min_multiple));
  378. else
  379. rec->mul_adds[(rec->min_periods /
  380. rec->min_multiple)]++;
  381. rec->mul_elapsed_real += (rec->min_periods /
  382. rec->min_multiple);
  383. rec->mul_elapsed++;
  384. #endif
  385. rec->min_periods = 0;
  386. snd_pcm_period_elapsed(substream);
  387. }
  388. }
  389. /*
  390. * _internal_ helper function for capture interrupt callback
  391. */
  392. static void
  393. snd_pcm_indirect2_capture_transfer(struct snd_pcm_substream *substream,
  394. struct snd_pcm_indirect2 *rec,
  395. snd_pcm_indirect2_copy_t copy,
  396. snd_pcm_indirect2_zero_t null)
  397. {
  398. struct snd_pcm_runtime *runtime = substream->runtime;
  399. snd_pcm_uframes_t appl_ptr = runtime->control->appl_ptr;
  400. snd_pcm_sframes_t diff = appl_ptr - rec->appl_ptr;
  401. if (diff) {
  402. #ifdef SND_PCM_INDIRECT2_STAT
  403. rec->lastdifftime = jiffies;
  404. #endif
  405. if (diff < -(snd_pcm_sframes_t) (runtime->boundary / 2))
  406. diff += runtime->boundary;
  407. rec->sw_ready -= frames_to_bytes(runtime, diff);
  408. rec->appl_ptr = appl_ptr;
  409. }
  410. /* if hardware has something, but the intermediate buffer is full
  411. * => skip contents of buffer
  412. */
  413. if (rec->hw_ready && (rec->sw_ready >= (int)rec->sw_buffer_size)) {
  414. unsigned int bytes;
  415. #ifdef SND_PCM_INDIRECT2_STAT
  416. if (rec->firstzerotime == 0) {
  417. rec->firstzerotime = jiffies;
  418. snd_printk(KERN_DEBUG "STAT: (capture) "
  419. "@firstzerotime: mul_elapsed: %d, "
  420. "min_period_count: %d\n",
  421. rec->mul_elapsed, rec->min_period_count);
  422. snd_printk(KERN_DEBUG "STAT: (capture) "
  423. "@firstzerotime: sw_io: %d, sw_data: %d, "
  424. "appl_ptr: %u\n",
  425. rec->sw_io, rec->sw_data,
  426. (unsigned int)appl_ptr);
  427. }
  428. if ((jiffies - rec->firstzerotime) < 3750) {
  429. rec->zero_times[(jiffies - rec->firstzerotime)]++;
  430. rec->zero_times_saved++;
  431. } else
  432. rec->zero_times_notsaved++;
  433. #endif
  434. bytes = null(substream, rec);
  435. #ifdef SND_PCM_INDIRECT2_STAT
  436. rec->zeros2hw += bytes;
  437. if (bytes < 64)
  438. rec->zero_sizes[bytes]++;
  439. else
  440. snd_printk(KERN_DEBUG
  441. "STAT: (capture) %d zero Bytes copied to "
  442. "hardware at once - too big to save!\n",
  443. bytes);
  444. #endif
  445. snd_pcm_indirect2_increase_min_periods(substream, rec, 0, 0,
  446. bytes);
  447. /* report an overrun */
  448. rec->sw_io = SNDRV_PCM_POS_XRUN;
  449. return;
  450. }
  451. while (rec->hw_ready && (rec->sw_ready < (int)rec->sw_buffer_size)) {
  452. /* sw_to_end: max. number of bytes that we can write to the
  453. * intermediate buffer (until it's end)
  454. */
  455. size_t sw_to_end = rec->sw_buffer_size - rec->sw_data;
  456. /* bytes: max. number of bytes, which may be copied to the
  457. * intermediate buffer without overflow (in _one_ step)
  458. */
  459. size_t bytes = rec->sw_buffer_size - rec->sw_ready;
  460. /* limit number of bytes (for transfer) by available room in
  461. * the intermediate buffer
  462. */
  463. if (sw_to_end < bytes)
  464. bytes = sw_to_end;
  465. if (!bytes)
  466. break;
  467. #ifdef SND_PCM_INDIRECT2_STAT
  468. if (rec->firstbytetime == 0)
  469. rec->firstbytetime = jiffies;
  470. rec->lastbytetime = jiffies;
  471. #endif
  472. /* copy bytes from the intermediate buffer (position sw_data)
  473. * to the HW at most and return number of bytes actually copied
  474. * from HW
  475. * Furthermore, set hw_ready to 0, if the fifo is empty now.
  476. */
  477. bytes = copy(substream, rec, bytes);
  478. rec->bytes2hw += bytes;
  479. #ifdef SND_PCM_INDIRECT2_STAT
  480. if (bytes < 64)
  481. rec->byte_sizes[bytes]++;
  482. else
  483. snd_printk(KERN_DEBUG
  484. "STAT: (capture) %d Bytes copied to "
  485. "hardware at once - too big to save!\n",
  486. bytes);
  487. #endif
  488. /* increase sw_data by the number of actually copied bytes from
  489. * HW
  490. */
  491. rec->sw_data += bytes;
  492. if (rec->sw_data == rec->sw_buffer_size)
  493. rec->sw_data = 0;
  494. snd_pcm_indirect2_increase_min_periods(substream, rec, 0, 1,
  495. bytes);
  496. /* number of bytes in the intermediate buffer, which haven't
  497. * been fetched by ALSA yet.
  498. */
  499. rec->sw_ready += bytes;
  500. }
  501. return;
  502. }
  503. /*
  504. * helper function for capture interrupt routine
  505. */
  506. void
  507. snd_pcm_indirect2_capture_interrupt(struct snd_pcm_substream *substream,
  508. struct snd_pcm_indirect2 *rec,
  509. snd_pcm_indirect2_copy_t copy,
  510. snd_pcm_indirect2_zero_t null)
  511. {
  512. #ifdef SND_PCM_INDIRECT2_STAT
  513. rec->irq_occured++;
  514. #endif
  515. /* hardware recorded some bytes, so there is something to read from the
  516. * record fifo:
  517. */
  518. rec->hw_ready = 1;
  519. /* don't call ack() now, instead call transfer() function directly
  520. * (normally called by ack() )
  521. */
  522. snd_pcm_indirect2_capture_transfer(substream, rec, copy, null);
  523. if (rec->min_periods >= rec->min_multiple) {
  524. #ifdef SND_PCM_INDIRECT2_STAT
  525. if ((rec->min_periods / rec->min_multiple) > 7)
  526. snd_printk(KERN_DEBUG
  527. "STAT: more than 7 (%d) mul_adds - "
  528. "too big to save!\n",
  529. (rec->min_periods / rec->min_multiple));
  530. else
  531. rec->mul_adds[(rec->min_periods /
  532. rec->min_multiple)]++;
  533. rec->mul_elapsed_real += (rec->min_periods /
  534. rec->min_multiple);
  535. rec->mul_elapsed++;
  536. if (!(rec->mul_elapsed % 4)) {
  537. struct snd_pcm_runtime *runtime = substream->runtime;
  538. unsigned int appl_ptr =
  539. frames_to_bytes(runtime,
  540. (unsigned int)runtime->control->
  541. appl_ptr) % rec->sw_buffer_size;
  542. int diff = rec->sw_data - appl_ptr;
  543. if (diff < 0)
  544. diff += rec->sw_buffer_size;
  545. snd_printk(KERN_DEBUG
  546. "STAT: mul_elapsed: %d, sw_data: %u, "
  547. "appl_ptr (bytes): %u, diff: %d\n",
  548. rec->mul_elapsed, rec->sw_data, appl_ptr,
  549. diff);
  550. }
  551. #endif
  552. rec->min_periods = 0;
  553. snd_pcm_period_elapsed(substream);
  554. }
  555. }