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
3.0KB

  1. /*
  2. Copyright (C) 2008-2012 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 "JackPlatformPlug.h"
  17. #include "JackArgParser.h"
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <assert.h>
  21. #ifdef __APPLE__
  22. #include "JackCoreAudioAdapter.h"
  23. #define JackPlatformAdapter JackCoreAudioAdapter
  24. #endif
  25. #ifdef __linux__
  26. #include "JackAlsaAdapter.h"
  27. #define JackPlatformAdapter JackAlsaAdapter
  28. #endif
  29. #if defined(__sun__) || defined(sun) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
  30. #include "JackOSSAdapter.h"
  31. #define JackPlatformAdapter JackOSSAdapter
  32. #endif
  33. #ifdef WIN32
  34. #include "JackPortAudioAdapter.h"
  35. #define JackPlatformAdapter JackPortAudioAdapter
  36. #endif
  37. #ifdef __cplusplus
  38. extern "C"
  39. {
  40. #endif
  41. using namespace Jack;
  42. SERVER_EXPORT int jack_internal_initialize(jack_client_t* jack_client, const JSList* params)
  43. {
  44. jack_log("Loading audioadapter");
  45. Jack::JackAudioAdapter* adapter;
  46. jack_nframes_t buffer_size = jack_get_buffer_size(jack_client);
  47. jack_nframes_t sample_rate = jack_get_sample_rate(jack_client);
  48. try {
  49. adapter = new Jack::JackAudioAdapter(jack_client, new Jack::JackPlatformAdapter(buffer_size, sample_rate, params), params);
  50. assert(adapter);
  51. if (adapter->Open() == 0) {
  52. return 0;
  53. } else {
  54. delete adapter;
  55. return 1;
  56. }
  57. } catch (...) {
  58. jack_info("audioadapter allocation error");
  59. return 1;
  60. }
  61. }
  62. SERVER_EXPORT int jack_initialize(jack_client_t* jack_client, const char* load_init)
  63. {
  64. JSList* params = NULL;
  65. bool parse_params = true;
  66. int res = 1;
  67. jack_driver_desc_t* desc = jack_get_descriptor();
  68. Jack::JackArgParser parser(load_init);
  69. if (parser.GetArgc() > 0) {
  70. parse_params = parser.ParseParams(desc, &params);
  71. }
  72. if (parse_params) {
  73. res = jack_internal_initialize(jack_client, params);
  74. parser.FreeParams(params);
  75. }
  76. return res;
  77. }
  78. SERVER_EXPORT void jack_finish(void* arg)
  79. {
  80. Jack::JackAudioAdapter* adapter = static_cast<Jack::JackAudioAdapter*>(arg);
  81. if (adapter) {
  82. jack_log("Unloading audioadapter");
  83. adapter->Close();
  84. delete adapter;
  85. }
  86. }
  87. #ifdef __cplusplus
  88. }
  89. #endif