pcm-indirect2.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. #ifndef __SOUND_PCM_INDIRECT2_H
  28. #define __SOUND_PCM_INDIRECT2_H
  29. /* struct snd_pcm_substream, struct snd_pcm_runtime, snd_pcm_uframes_t */
  30. #include <sound/pcm.h>
  31. /* Debug options for code which may be removed completely in a final version */
  32. #ifdef CONFIG_SND_DEBUG
  33. #define SND_PCM_INDIRECT2_STAT /* turn on some "statistics" about the
  34. * process of copying bytes from the
  35. * intermediate buffer to the hardware
  36. * fifo and the other way round
  37. */
  38. #endif
  39. struct snd_pcm_indirect2 {
  40. unsigned int hw_buffer_size; /* Byte size of hardware buffer */
  41. int hw_ready; /* playback: 1 = hw fifo has room left,
  42. * 0 = hw fifo is full
  43. */
  44. unsigned int min_multiple;
  45. int min_periods; /* counts number of min. periods until
  46. * min_multiple is reached
  47. */
  48. int min_period_count; /* counts bytes to count number of
  49. * min. periods
  50. */
  51. unsigned int sw_buffer_size; /* Byte size of software buffer */
  52. /* sw_data: position in intermediate buffer, where we will read (or
  53. * write) from/to next time (to transfer data to/from HW)
  54. */
  55. unsigned int sw_data; /* Offset to next dst (or src) in sw
  56. * ring buffer
  57. */
  58. /* easiest case (playback):
  59. * sw_data is nearly the same as ~ runtime->control->appl_ptr, with the
  60. * exception that sw_data is "behind" by the number if bytes ALSA wrote
  61. * to the intermediate buffer last time.
  62. * A call to ack() callback synchronizes both indirectly.
  63. */
  64. /* We have no real sw_io pointer here. Usually sw_io is pointing to the
  65. * current playback/capture position _inside_ the hardware. Devices
  66. * with plain FIFOs often have no possibility to publish this position.
  67. * So we say: if sw_data is updated, that means bytes were copied to
  68. * the hardware, we increase sw_io by that amount, because there have
  69. * to be as much bytes which were played. So sw_io will stay behind
  70. * sw_data all the time and has to converge to sw_data at the end of
  71. * playback.
  72. */
  73. unsigned int sw_io; /* Current software pointer in bytes */
  74. /* sw_ready: number of bytes ALSA copied to the intermediate buffer, so
  75. * it represents the number of bytes which wait for transfer to the HW
  76. */
  77. int sw_ready; /* Bytes ready to be transferred to/from hw */
  78. /* appl_ptr: last known position of ALSA (where ALSA is going to write
  79. * next time into the intermediate buffer
  80. */
  81. snd_pcm_uframes_t appl_ptr; /* Last seen appl_ptr */
  82. unsigned int bytes2hw;
  83. int check_alignment;
  84. #ifdef SND_PCM_INDIRECT2_STAT
  85. unsigned int zeros2hw;
  86. unsigned int mul_elapsed;
  87. unsigned int mul_elapsed_real;
  88. unsigned long firstbytetime;
  89. unsigned long lastbytetime;
  90. unsigned long firstzerotime;
  91. unsigned int byte_sizes[64];
  92. unsigned int zero_sizes[64];
  93. unsigned int min_adds[8];
  94. unsigned int mul_adds[8];
  95. unsigned int zero_times[3750]; /* = 15s */
  96. unsigned int zero_times_saved;
  97. unsigned int zero_times_notsaved;
  98. unsigned int irq_occured;
  99. unsigned int pointer_calls;
  100. unsigned int lastdifftime;
  101. #endif
  102. };
  103. typedef size_t (*snd_pcm_indirect2_copy_t) (struct snd_pcm_substream *substream,
  104. struct snd_pcm_indirect2 *rec,
  105. size_t bytes);
  106. typedef size_t (*snd_pcm_indirect2_zero_t) (struct snd_pcm_substream *substream,
  107. struct snd_pcm_indirect2 *rec);
  108. #ifdef SND_PCM_INDIRECT2_STAT
  109. void snd_pcm_indirect2_stat(struct snd_pcm_substream *substream,
  110. struct snd_pcm_indirect2 *rec);
  111. #endif
  112. snd_pcm_uframes_t
  113. snd_pcm_indirect2_pointer(struct snd_pcm_substream *substream,
  114. struct snd_pcm_indirect2 *rec);
  115. void
  116. snd_pcm_indirect2_playback_interrupt(struct snd_pcm_substream *substream,
  117. struct snd_pcm_indirect2 *rec,
  118. snd_pcm_indirect2_copy_t copy,
  119. snd_pcm_indirect2_zero_t zero);
  120. void
  121. snd_pcm_indirect2_capture_interrupt(struct snd_pcm_substream *substream,
  122. struct snd_pcm_indirect2 *rec,
  123. snd_pcm_indirect2_copy_t copy,
  124. snd_pcm_indirect2_zero_t null);
  125. #endif /* __SOUND_PCM_INDIRECT2_H */