/[svn]/linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceJack.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceJack.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2410 - (hide annotations) (download) (as text)
Sat Feb 2 18:52:15 2013 UTC (11 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 8387 byte(s)
* Several fixes in JACK audio driver:
- React on sample rate changes.
- React on buffer size changes.
- jack_port_get_buffer() was cached and called
  outside RT context.

1 schoenebeck 200 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 2410 * Copyright (C) 2005 - 2013 Christian Schoenebeck *
7 schoenebeck 200 * *
8     * This program is free software; you can redistribute it and/or modify *
9     * it under the terms of the GNU General Public License as published by *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #ifndef __LS_AUDIOOUTPUTDEVICEJACK_H__
25     #define __LS_AUDIOOUTPUTDEVICEJACK_H__
26    
27 schoenebeck 1424 #include "../../common/global_private.h"
28 schoenebeck 200
29     #if HAVE_JACK
30    
31     #include <vector>
32     #include <sstream>
33     #include <jack/jack.h>
34    
35     #include "AudioOutputDevice.h"
36     #include "../../common/ConditionServer.h"
37 schoenebeck 1682
38     #if HAVE_JACK_MIDI
39 persson 1651 #include "../midi/MidiInputDeviceJack.h"
40 schoenebeck 1682 #endif
41 schoenebeck 200
42     namespace LinuxSampler {
43    
44     /** JACK audio output driver
45     *
46     * Implements audio output to the JACK Audio Connection Kit (JACK).
47     */
48     class AudioOutputDeviceJack : public AudioOutputDevice {
49     public:
50     AudioOutputDeviceJack(std::map<String,DeviceCreationParameter*> Parameters);
51 schoenebeck 374 virtual ~AudioOutputDeviceJack();
52 schoenebeck 200
53 schoenebeck 226 /**
54     * Audio channel implementation for the JACK audio driver.
55 schoenebeck 221 */
56 schoenebeck 226 class AudioChannelJack : public AudioChannel {
57 schoenebeck 200 public:
58 schoenebeck 226 /** Audio Channel Parameter 'NAME'
59     *
60     * Used to assign an arbitrary name to an audio channel.
61     */
62     class ParameterName : public AudioChannel::ParameterName {
63     public:
64     ParameterName(AudioChannelJack* pChannel);
65     virtual void OnSetValue(String s);
66     protected:
67     AudioChannelJack* pChannel;
68     };
69    
70     /** Audio Channel Parameter 'JACK_BINDINGS'
71     *
72     * Used to connect to other JACK clients.
73     */
74     class ParameterJackBindings : public DeviceRuntimeParameterStrings {
75     public:
76     ParameterJackBindings(AudioChannelJack* pChannel);
77     virtual String Description();
78     virtual bool Fix();
79     virtual std::vector<String> PossibilitiesAsString();
80     virtual void OnSetValue(std::vector<String> vS);
81     static String Name();
82     protected:
83 schoenebeck 483 AudioChannelJack* pChannel;
84     std::vector<String> Bindings;
85 schoenebeck 226 };
86 schoenebeck 200 protected:
87 schoenebeck 226 AudioChannelJack(uint ChannelNr, AudioOutputDeviceJack* pDevice) throw (AudioOutputException);
88     ~AudioChannelJack();
89 schoenebeck 2410 void UpdateJackBuffer(uint size);
90 schoenebeck 226 friend class AudioOutputDeviceJack;
91     private:
92     AudioOutputDeviceJack* pDevice;
93     jack_port_t* hJackPort;
94     uint ChannelNr;
95    
96     float* CreateJackPort(uint ChannelNr, AudioOutputDeviceJack* pDevice) throw (AudioOutputException);
97 schoenebeck 200 };
98    
99 schoenebeck 374 /** Audio Device Parameter 'NAME'
100     *
101     * Used to assign an arbitrary name to the JACK client of this
102     * audio device.
103     */
104     class ParameterName : public DeviceCreationParameterString {
105     public:
106     ParameterName();
107 schoenebeck 880 ParameterName(String s) throw (Exception);
108 schoenebeck 374 virtual String Description();
109     virtual bool Fix();
110     virtual bool Mandatory();
111     virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
112     virtual std::vector<String> PossibilitiesAsString(std::map<String,String> Parameters);
113     virtual optional<String> DefaultAsString(std::map<String,String> Parameters);
114 schoenebeck 880 virtual void OnSetValue(String s) throw (Exception);
115 schoenebeck 374 static String Name();
116     };
117    
118 schoenebeck 200 // derived abstract methods from class 'AudioOutputDevice'
119     virtual void Play();
120     virtual bool IsPlaying();
121     virtual void Stop();
122     virtual uint MaxSamplesPerCycle();
123     virtual uint SampleRate();
124 schoenebeck 226 virtual AudioChannel* CreateChannel(uint ChannelNr);
125 schoenebeck 2410 virtual float latency();
126 schoenebeck 200
127 persson 1651 static String Name();
128 schoenebeck 200
129     virtual String Driver();
130    
131     static String Description();
132     static String Version();
133    
134     int Process(uint Samples); // FIXME: should be private
135 schoenebeck 2410 void UpdateJackBuffers(uint size);
136 schoenebeck 200 protected:
137     AudioOutputDeviceJack(String* AutoConnectPortIDs = NULL, uint AutoConnectPorts = 0);
138     private:
139 schoenebeck 226 ConditionServer csIsPlaying;
140     uint uiMaxSamplesPerCycle;
141     jack_client_t* hJackClient;
142 schoenebeck 200 };
143    
144     // Callback functions for the libjack API
145 persson 1651 int linuxsampler_libjack_process_callback(jack_nframes_t nframes, void* arg);
146     void linuxsampler_libjack_shutdown_callback(void* arg);
147    
148    
149     /** JACK client
150     *
151     * Represents a jack client. This class is shared by
152     * AudioOutputDeviceJack and MidiInputDeviceJack. The jack server
153     * calls JackClient::Process, which in turn calls
154     * AudioOutputDeviceJack::Process and/or
155     * MidiInputDeviceJack::Process.
156     */
157     class JackClient {
158     public:
159     static JackClient* CreateAudio(String Name);
160     static JackClient* CreateMidi(String Name);
161     static void ReleaseAudio(String Name);
162     static void ReleaseMidi(String Name);
163     int Process(uint Samples);
164     void Stop();
165     void SetAudioOutputDevice(AudioOutputDeviceJack* device);
166 schoenebeck 1682 #if HAVE_JACK_MIDI
167 persson 1651 void SetMidiInputDevice(MidiInputDeviceJack* device);
168 schoenebeck 1682 #endif
169 persson 1651
170     jack_client_t* hJackClient;
171    
172     private:
173     static std::map<String, JackClient*> Clients;
174     struct config_t {
175     AudioOutputDeviceJack* AudioDevice;
176 schoenebeck 1682 #if HAVE_JACK_MIDI
177 persson 1651 MidiInputDeviceJack* MidiDevice;
178 schoenebeck 1682 #endif
179 persson 1651 };
180     SynchronizedConfig<config_t> Config;
181     SynchronizedConfig<config_t>::Reader ConfigReader;
182     bool audio;
183     bool midi;
184    
185     JackClient(String Name);
186     ~JackClient();
187 schoenebeck 2410
188     // Callback functions for the libjack API
189     static int libjackSampleRateCallback(jack_nframes_t nframes, void *arg);
190     static int libjackBufferSizeCallback(jack_nframes_t nframes, void *arg);
191 persson 1651 };
192 schoenebeck 200 }
193    
194     #endif // HAVE_JACK
195     #endif // __LS_AUDIOOUTPUTDEVICEJACK_H__

  ViewVC Help
Powered by ViewVC