4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * Copyright 2009-2011 Jörg Hermann Müller
8 * This file is part of AudaSpace.
10 * Audaspace is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * AudaSpace is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Audaspace; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 * ***** END GPL LICENSE BLOCK *****
27 /** \file audaspace/jack/AUD_JackDevice.h
32 #ifndef AUD_JACKDEVICE
33 #define AUD_JACKDEVICE
36 #include "AUD_SoftwareDevice.h"
37 #include "AUD_Buffer.h"
42 #include <ringbuffer.h>
44 typedef void (*AUD_syncFunction)(void*, int, float);
47 * This device plays back through Jack.
49 class AUD_JackDevice : public AUD_SoftwareDevice
53 * The output ports of jack.
55 jack_port_t** m_ports;
60 jack_client_t* m_client;
68 * The deinterleaving buffer.
70 AUD_Buffer m_deinterleavebuf;
72 jack_ringbuffer_t** m_ringbuffers;
75 * Whether the device is valid.
80 * Invalidates the jack device.
81 * \param data The jack device that gets invalidet by jack.
83 static void jack_shutdown(void *data);
86 * Mixes the next bytes into the buffer.
87 * \param length The length in samples to be filled.
88 * \param data A pointer to the jack device.
89 * \return 0 what shows success.
91 static int jack_mix(jack_nframes_t length, void *data);
93 static int jack_sync(jack_transport_state_t state, jack_position_t* pos, void* data);
96 * Next Jack Transport state (-1 if not expected to change).
98 jack_transport_state_t m_nextState;
101 * Current jack transport status.
103 jack_transport_state_t m_state;
106 * Syncronisation state.
111 * External syncronisation callback function.
113 AUD_syncFunction m_syncFunc;
116 * Data for the sync function.
118 void* m_syncFuncData;
123 pthread_t m_mixingThread;
128 pthread_mutex_t m_mixingLock;
131 * Condition for mixing.
133 pthread_cond_t m_mixingCondition;
136 * Mixing thread function.
137 * \param device The this pointer.
140 static void* runMixingThread(void* device);
143 * Updates the ring buffers.
145 void updateRingBuffers();
147 // hide copy constructor and operator=
148 AUD_JackDevice(const AUD_JackDevice&);
149 AUD_JackDevice& operator=(const AUD_JackDevice&);
152 virtual void playing(bool playing);
156 * Creates a Jack client for audio output.
157 * \param name The client name.
158 * \param specs The wanted audio specification, where only the channel count
160 * \param buffersize The size of the internal buffer.
161 * \exception AUD_Exception Thrown if the audio device cannot be opened.
163 AUD_JackDevice(std::string name, AUD_DeviceSpecs specs, int buffersize = AUD_DEFAULT_BUFFER_SIZE);
166 * Closes the Jack client.
168 virtual ~AUD_JackDevice();
171 * Starts jack transport playback.
173 void startPlayback();
176 * Stops jack transport playback.
181 * Seeks jack transport playback.
182 * \param time The time to seek to.
184 void seekPlayback(float time);
187 * Sets the sync callback for jack transport playback.
188 * \param sync The callback function.
189 * \param data The data for the function.
191 void setSyncCallback(AUD_syncFunction sync, void* data);
194 * Retrieves the jack transport playback time.
195 * \return The current time position.
197 float getPlaybackPosition();
200 * Returns whether jack transport plays back.
201 * \return Whether jack transport plays back.
206 #endif //AUD_JACKDEVICE