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.

111 lines
2.9KB

  1. /*
  2. Copyright (C) 2008 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #include "JackAudioAdapter.h"
  16. #include "JackTools.h"
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <assert.h>
  20. #include "driver_interface.h"
  21. #ifdef __linux__
  22. #include "JackAlsaAdapter.h"
  23. #endif
  24. #ifdef __APPLE__
  25. #include "JackCoreAudioAdapter.h"
  26. #endif
  27. #ifdef WIN32
  28. #include "JackPortAudioAdapter.h"
  29. #endif
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #endif
  34. using namespace Jack;
  35. SERVER_EXPORT int jack_internal_initialize(jack_client_t* jack_client, const JSList* params)
  36. {
  37. jack_log("Loading audioadapter");
  38. Jack::JackAudioAdapter* adapter;
  39. jack_nframes_t buffer_size = jack_get_buffer_size(jack_client);
  40. jack_nframes_t sample_rate = jack_get_sample_rate(jack_client);
  41. try {
  42. #ifdef __linux__
  43. adapter = new Jack::JackAudioAdapter(jack_client, new Jack::JackAlsaAdapter(buffer_size, sample_rate, params));
  44. #endif
  45. #ifdef WIN32
  46. adapter = new Jack::JackAudioAdapter(jack_client, new Jack::JackPortAudioAdapter(buffer_size, sample_rate, params));
  47. #endif
  48. #ifdef __APPLE__
  49. adapter = new Jack::JackAudioAdapter(jack_client, new Jack::JackCoreAudioAdapter(buffer_size, sample_rate, params));
  50. #endif
  51. assert(adapter);
  52. if (adapter->Open() == 0)
  53. return 0;
  54. else
  55. {
  56. delete adapter;
  57. return 1;
  58. }
  59. } catch (...) {
  60. return 1;
  61. }
  62. }
  63. SERVER_EXPORT int jack_initialize(jack_client_t* jack_client, const char* load_init)
  64. {
  65. JSList* params = NULL;
  66. jack_driver_desc_t *desc = jack_get_descriptor();
  67. JackArgParser parser(load_init);
  68. if (parser.GetArgc() > 0)
  69. parser.ParseParams(desc, &params);
  70. int res = jack_internal_initialize(jack_client, params);
  71. parser.FreeParams(params);
  72. return res;
  73. }
  74. SERVER_EXPORT void jack_finish(void* arg)
  75. {
  76. Jack::JackAudioAdapter* adapter = static_cast<Jack::JackAudioAdapter*>(arg);
  77. if (adapter) {
  78. jack_log("Unloading audioadapter");
  79. adapter->Close();
  80. delete adapter;
  81. }
  82. }
  83. #ifdef __cplusplus
  84. }
  85. #endif