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.

114 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. #ifdef __cplusplus
  21. extern "C"
  22. {
  23. #endif
  24. #include "driver_interface.h"
  25. #ifdef __linux__
  26. #include "JackAlsaAdapter.h"
  27. #endif
  28. #ifdef __APPLE__
  29. #include "JackCoreAudioAdapter.h"
  30. #endif
  31. #ifdef WIN32
  32. #include "JackPortAudioAdapter.h"
  33. #endif
  34. using namespace Jack;
  35. 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. 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. {
  70. if (parser.ParseParams(desc, &params) != 0)
  71. jack_error("Internal client : JackArgParser::ParseParams error.");
  72. }
  73. return jack_internal_initialize(jack_client, params);
  74. }
  75. EXPORT void jack_finish(void* arg)
  76. {
  77. Jack::JackAudioAdapter* adapter = static_cast<Jack::JackAudioAdapter*>(arg);
  78. if (adapter)
  79. {
  80. jack_log("Unloading audioadapter");
  81. adapter->Close();
  82. delete adapter;
  83. }
  84. }
  85. #ifdef __cplusplus
  86. }
  87. #endif