jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
7.3KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #ifndef __JackAlsaDriver__
  17. #define __JackAlsaDriver__
  18. #include "JackAudioDriver.h"
  19. #include "JackThreadedDriver.h"
  20. #include "JackTime.h"
  21. #include "alsa_driver.h"
  22. namespace Jack
  23. {
  24. /*!
  25. \brief The ALSA driver.
  26. */
  27. class JackAlsaDriver : public JackAudioDriver
  28. {
  29. private:
  30. jack_driver_t* fDriver;
  31. int fReservedCaptureDevice;
  32. int fReservedPlaybackDevice;
  33. void alsa_driver_release_channel_dependent_memory(alsa_driver_t *driver);
  34. int alsa_driver_check_capabilities(alsa_driver_t *driver);
  35. int alsa_driver_check_card_type(alsa_driver_t *driver);
  36. int alsa_driver_hammerfall_hardware(alsa_driver_t *driver);
  37. int alsa_driver_hdsp_hardware(alsa_driver_t *driver);
  38. int alsa_driver_ice1712_hardware(alsa_driver_t *driver);
  39. int alsa_driver_usx2y_hardware(alsa_driver_t *driver);
  40. int alsa_driver_generic_hardware(alsa_driver_t *driver);
  41. int alsa_driver_hw_specific(alsa_driver_t *driver, int hw_monitoring,
  42. int hw_metering);
  43. int alsa_driver_setup_io_function_pointers (alsa_driver_t *driver);
  44. int alsa_driver_configure_stream(alsa_driver_t *driver, char *device_name,
  45. const char *stream_name,
  46. snd_pcm_t *handle,
  47. snd_pcm_hw_params_t *hw_params,
  48. snd_pcm_sw_params_t *sw_params,
  49. unsigned int *nperiodsp,
  50. unsigned long *nchns,
  51. unsigned long sample_width);
  52. int alsa_driver_set_parameters(alsa_driver_t *driver,
  53. jack_nframes_t frames_per_cycle,
  54. jack_nframes_t user_nperiods,
  55. jack_nframes_t rate);
  56. int alsa_driver_reset_parameters(alsa_driver_t *driver,
  57. jack_nframes_t frames_per_cycle,
  58. jack_nframes_t user_nperiods,
  59. jack_nframes_t rate);
  60. int alsa_driver_get_channel_addresses(alsa_driver_t *driver,
  61. snd_pcm_uframes_t *capture_avail,
  62. snd_pcm_uframes_t *playback_avail,
  63. snd_pcm_uframes_t *capture_offset,
  64. snd_pcm_uframes_t *playback_offset);
  65. jack_driver_t * alsa_driver_new(const char *name, char *playback_alsa_device,
  66. char *capture_alsa_device,
  67. jack_client_t *client,
  68. jack_nframes_t frames_per_cycle,
  69. jack_nframes_t user_nperiods,
  70. jack_nframes_t rate,
  71. int hw_monitoring,
  72. int hw_metering,
  73. int capturing,
  74. int playing,
  75. DitherAlgorithm dither,
  76. int soft_mode,
  77. int monitor,
  78. int user_capture_nchnls,
  79. int user_playback_nchnls,
  80. int shorts_first,
  81. jack_nframes_t capture_latency,
  82. jack_nframes_t playback_latency,
  83. alsa_midi_t *midi);
  84. void alsa_driver_delete(alsa_driver_t *driver);
  85. int alsa_driver_start(alsa_driver_t *driver);
  86. int alsa_driver_stop(alsa_driver_t *driver);
  87. int alsa_driver_read(alsa_driver_t *driver, jack_nframes_t nframes);
  88. int alsa_driver_write(alsa_driver_t *driver, jack_nframes_t nframes);
  89. jack_nframes_t alsa_driver_wait(alsa_driver_t *driver, int extra_fd, int *status, float
  90. *delayed_usecs);
  91. void alsa_driver_silence_untouched_channels(alsa_driver_t *driver,
  92. jack_nframes_t nframes);
  93. int alsa_driver_restart(alsa_driver_t *driver);
  94. int alsa_driver_xrun_recovery(alsa_driver_t *driver, float *delayed_usecs);
  95. void jack_driver_init(jack_driver_t *driver);
  96. void jack_driver_nt_init(jack_driver_nt_t * driver);
  97. public:
  98. JackAlsaDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table)
  99. : JackAudioDriver(name, alias, engine, table)
  100. ,fDriver(NULL)
  101. ,fReservedCaptureDevice(-1)
  102. ,fReservedPlaybackDevice(-1)
  103. {}
  104. virtual ~JackAlsaDriver()
  105. {}
  106. int Open(jack_nframes_t buffer_size,
  107. jack_nframes_t user_nperiods,
  108. jack_nframes_t samplerate,
  109. bool hw_monitoring,
  110. bool hw_metering,
  111. bool capturing,
  112. bool playing,
  113. DitherAlgorithm dither,
  114. bool soft_mode,
  115. bool monitor,
  116. int inchannels,
  117. int outchannels,
  118. bool shorts_first,
  119. const char* capture_driver_name,
  120. const char* playback_driver_name,
  121. jack_nframes_t capture_latency,
  122. jack_nframes_t playback_latency,
  123. const char* midi_driver_name);
  124. int Close();
  125. int Attach();
  126. int Detach();
  127. int Start();
  128. int Stop();
  129. int Read();
  130. int Write();
  131. // BufferSize can be changed
  132. bool IsFixedBufferSize()
  133. {
  134. return false;
  135. }
  136. int SetBufferSize(jack_nframes_t buffer_size);
  137. // jack api emulation for the midi driver
  138. int is_realtime() const;
  139. int create_thread(pthread_t *thread, int prio, int rt, void *(*start_func)(void*), void *arg);
  140. jack_port_id_t port_register(const char *port_name, const char *port_type, unsigned long flags, unsigned long buffer_size);
  141. int port_unregister(jack_port_id_t port_index);
  142. void* port_get_buffer(int port, jack_nframes_t nframes);
  143. int port_set_alias(int port, const char* name);
  144. jack_nframes_t get_sample_rate() const;
  145. jack_nframes_t frame_time() const;
  146. jack_nframes_t last_frame_time() const;
  147. };
  148. } // end of namespace
  149. #endif