Jack2: JackAudioAdapterFactory.cpp Source File

Jack2 1.9.12

JackAudioAdapterFactory.cpp
1 /*
2 Copyright (C) 2008-2012 Grame
3
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
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "JackAudioAdapter.h"
21 #include "JackPlatformPlug.h"
22 #include "JackArgParser.h"
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <assert.h>
27
28 #ifdef __APPLE__
29 #include "JackCoreAudioAdapter.h"
30 #define JackPlatformAdapter JackCoreAudioAdapter
31 #endif
32
33 #ifdef __linux__
34 #include "JackAlsaAdapter.h"
35 #define JackPlatformAdapter JackAlsaAdapter
36 #endif
37
38 #if defined(__sun__) || defined(sun)
39 #include "JackOSSAdapter.h"
40 #define JackPlatformAdapter JackOSSAdapter
41 #endif
42
43 #ifdef WIN32
44 #include "JackPortAudioAdapter.h"
45 #define JackPlatformAdapter JackPortAudioAdapter
46 #endif
47
48 #ifdef __cplusplus
49 extern "C"
50 {
51 #endif
52
53 using namespace Jack;
54
55 SERVER_EXPORT int jack_internal_initialize(jack_client_t* jack_client, const JSList* params)
56 {
57 jack_log("Loading audioadapter");
58
59 Jack::JackAudioAdapter* adapter;
60 jack_nframes_t buffer_size = jack_get_buffer_size(jack_client);
61 jack_nframes_t sample_rate = jack_get_sample_rate(jack_client);
62
63 try {
64
65 adapter = new Jack::JackAudioAdapter(jack_client, new Jack::JackPlatformAdapter(buffer_size, sample_rate, params), params);
66 assert(adapter);
67
68 if (adapter->Open() == 0) {
69 return 0;
70 } else {
71 delete adapter;
72 return 1;
73 }
74
75 } catch (...) {
76 jack_info("audioadapter allocation error");
77 return 1;
78 }
79 }
80
81 SERVER_EXPORT int jack_initialize(jack_client_t* jack_client, const char* load_init)
82 {
83 JSList* params = NULL;
84 bool parse_params = true;
85 int res = 1;
86 jack_driver_desc_t* desc = jack_get_descriptor();
87
88 Jack::JackArgParser parser(load_init);
89 if (parser.GetArgc() > 0) {
90 parse_params = parser.ParseParams(desc, &params);
91 }
92
93 if (parse_params) {
94 res = jack_internal_initialize(jack_client, params);
95 parser.FreeParams(params);
96 }
97 return res;
98 }
99
100 SERVER_EXPORT void jack_finish(void* arg)
101 {
102 Jack::JackAudioAdapter* adapter = static_cast<Jack::JackAudioAdapter*>(arg);
103
104 if (adapter) {
105 jack_log("Unloading audioadapter");
106 adapter->Close();
107 delete adapter;
108 }
109 }
110
111 #ifdef __cplusplus
112 }
113 #endif
Jack::JackArgParser
Definition: JackArgParser.h:37
jack_info
SERVER_EXPORT void jack_info(const char *fmt,...)
Definition: JackError.cpp:100
Jack::JackAudioAdapter
Audio adapter : Jack client side.
Definition: JackAudioAdapter.h:33
jack_get_buffer_size
LIB_EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t *)
Definition: JackAPI.cpp:1275
jack_get_sample_rate
LIB_EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t *)
Definition: JackAPI.cpp:1261
_JSList
Definition: linux/alsa/jslist.h:35
jack_log
SERVER_EXPORT void jack_log(const char *fmt,...)
Definition: JackError.cpp:108
jack_driver_desc_t
Definition: driver_interface.h:132