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.

94 lines
2.5KB

  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 __cplusplus
  22. extern "C"
  23. {
  24. #endif
  25. using namespace Jack;
  26. SERVER_EXPORT int jack_internal_initialize(jack_client_t* jack_client, const JSList* params)
  27. {
  28. jack_log("Loading audioadapter");
  29. Jack::JackAudioAdapter* adapter;
  30. jack_nframes_t buffer_size = jack_get_buffer_size(jack_client);
  31. jack_nframes_t sample_rate = jack_get_sample_rate(jack_client);
  32. try {
  33. adapter = new Jack::JackAudioAdapter(jack_client, new Jack::JackPlatformAdapter(buffer_size, sample_rate, params));
  34. assert(adapter);
  35. if (adapter->Open() == 0) {
  36. return 0;
  37. } else {
  38. delete adapter;
  39. return 1;
  40. }
  41. } catch (...) {
  42. jack_info("audioadapter allocation error");
  43. return 1;
  44. }
  45. }
  46. SERVER_EXPORT int jack_initialize(jack_client_t* jack_client, const char* load_init)
  47. {
  48. JSList* params = NULL;
  49. bool parse_params = true;
  50. int res = 1;
  51. jack_driver_desc_t* desc = jack_get_descriptor();
  52. Jack::JackArgParser parser(load_init);
  53. if (parser.GetArgc() > 0) {
  54. parse_params = parser.ParseParams(desc, &params);
  55. }
  56. if (parse_params) {
  57. res = jack_internal_initialize(jack_client, params);
  58. parser.FreeParams(params);
  59. }
  60. return res;
  61. }
  62. SERVER_EXPORT void jack_finish(void* arg)
  63. {
  64. Jack::JackAudioAdapter* adapter = static_cast<Jack::JackAudioAdapter*>(arg);
  65. if (adapter) {
  66. jack_log("Unloading audioadapter");
  67. adapter->Close();
  68. delete adapter;
  69. }
  70. }
  71. #ifdef __cplusplus
  72. }
  73. #endif