pcm.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Line 6 Linux USB driver
  3. *
  4. * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation, version 2.
  9. *
  10. */
  11. /*
  12. PCM interface to POD series devices.
  13. */
  14. #ifndef PCM_H
  15. #define PCM_H
  16. #include <sound/pcm.h>
  17. #include "driver.h"
  18. /*
  19. number of USB frames per URB
  20. The Line 6 Windows driver always transmits two frames per packet, but
  21. the Linux driver performs significantly better (i.e., lower latency)
  22. with only one frame per packet.
  23. */
  24. #define LINE6_ISO_PACKETS 1
  25. /* in a "full speed" device (such as the PODxt Pro) this means 1ms,
  26. * for "high speed" it's 1/8ms
  27. */
  28. #define LINE6_ISO_INTERVAL 1
  29. #define LINE6_IMPULSE_DEFAULT_PERIOD 100
  30. /*
  31. Get substream from Line 6 PCM data structure
  32. */
  33. #define get_substream(line6pcm, stream) \
  34. (line6pcm->pcm->streams[stream].substream)
  35. /*
  36. PCM mode bits.
  37. There are several features of the Line 6 USB driver which require PCM
  38. data to be exchanged with the device:
  39. *) PCM playback and capture via ALSA
  40. *) software monitoring (for devices without hardware monitoring)
  41. *) optional impulse response measurement
  42. However, from the device's point of view, there is just a single
  43. capture and playback stream, which must be shared between these
  44. subsystems. It is therefore necessary to maintain the state of the
  45. subsystems with respect to PCM usage.
  46. We define two bit flags, "opened" and "running", for each playback
  47. or capture stream. Both can contain the bit flag corresponding to
  48. LINE6_STREAM_* type,
  49. LINE6_STREAM_PCM = ALSA PCM playback or capture
  50. LINE6_STREAM_MONITOR = software monitoring
  51. IMPULSE = optional impulse response measurement
  52. The opened flag indicates whether the buffer is allocated while
  53. the running flag indicates whether the stream is running.
  54. For monitor or impulse operations, the driver needs to call
  55. line6_pcm_acquire() or line6_pcm_release() with the appropriate
  56. LINE6_STREAM_* flag.
  57. */
  58. /* stream types */
  59. enum {
  60. LINE6_STREAM_PCM,
  61. LINE6_STREAM_MONITOR,
  62. LINE6_STREAM_IMPULSE,
  63. LINE6_STREAM_CAPTURE_HELPER,
  64. };
  65. /* misc bit flags for PCM operation */
  66. enum {
  67. LINE6_FLAG_PAUSE_PLAYBACK,
  68. LINE6_FLAG_PREPARED,
  69. };
  70. struct line6_pcm_properties {
  71. struct snd_pcm_hardware playback_hw, capture_hw;
  72. struct snd_pcm_hw_constraint_ratdens rates;
  73. int bytes_per_channel;
  74. };
  75. struct line6_pcm_stream {
  76. /* allocated URBs */
  77. struct urb **urbs;
  78. /* Temporary buffer;
  79. * Since the packet size is not known in advance, this buffer is
  80. * large enough to store maximum size packets.
  81. */
  82. unsigned char *buffer;
  83. /* Free frame position in the buffer. */
  84. snd_pcm_uframes_t pos;
  85. /* Count processed bytes;
  86. * This is modulo period size (to determine when a period is finished).
  87. */
  88. unsigned bytes;
  89. /* Counter to create desired sample rate */
  90. unsigned count;
  91. /* period size in bytes */
  92. unsigned period;
  93. /* Processed frame position in the buffer;
  94. * The contents of the ring buffer have been consumed by the USB
  95. * subsystem (i.e., sent to the USB device) up to this position.
  96. */
  97. snd_pcm_uframes_t pos_done;
  98. /* Bit mask of active URBs */
  99. unsigned long active_urbs;
  100. /* Bit mask of URBs currently being unlinked */
  101. unsigned long unlink_urbs;
  102. /* Spin lock to protect updates of the buffer positions (not contents)
  103. */
  104. spinlock_t lock;
  105. /* Bit flags for operational stream types */
  106. unsigned long opened;
  107. /* Bit flags for running stream types */
  108. unsigned long running;
  109. int last_frame;
  110. };
  111. struct snd_line6_pcm {
  112. /* Pointer back to the Line 6 driver data structure */
  113. struct usb_line6 *line6;
  114. /* Properties. */
  115. struct line6_pcm_properties *properties;
  116. /* ALSA pcm stream */
  117. struct snd_pcm *pcm;
  118. /* protection to state changes of in/out streams */
  119. struct mutex state_mutex;
  120. /* Capture and playback streams */
  121. struct line6_pcm_stream in;
  122. struct line6_pcm_stream out;
  123. /* Previously captured frame (for software monitoring) */
  124. unsigned char *prev_fbuf;
  125. /* Size of previously captured frame (for software monitoring/sync) */
  126. int prev_fsize;
  127. /* Maximum size of USB packet */
  128. int max_packet_size_in;
  129. int max_packet_size_out;
  130. /* PCM playback volume (left and right) */
  131. int volume_playback[2];
  132. /* PCM monitor volume */
  133. int volume_monitor;
  134. /* Volume of impulse response test signal (if zero, test is disabled) */
  135. int impulse_volume;
  136. /* Period of impulse response test signal */
  137. int impulse_period;
  138. /* Counter for impulse response test signal */
  139. int impulse_count;
  140. /* Several status bits (see LINE6_FLAG_*) */
  141. unsigned long flags;
  142. };
  143. extern int line6_init_pcm(struct usb_line6 *line6,
  144. struct line6_pcm_properties *properties);
  145. extern int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd);
  146. extern int snd_line6_prepare(struct snd_pcm_substream *substream);
  147. extern int snd_line6_hw_params(struct snd_pcm_substream *substream,
  148. struct snd_pcm_hw_params *hw_params);
  149. extern int snd_line6_hw_free(struct snd_pcm_substream *substream);
  150. extern snd_pcm_uframes_t snd_line6_pointer(struct snd_pcm_substream *substream);
  151. extern void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm);
  152. extern int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type,
  153. bool start);
  154. extern void line6_pcm_release(struct snd_line6_pcm *line6pcm, int type);
  155. #endif