2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * Copyright 2009-2011 Jörg Hermann Müller
6 * This file is part of AudaSpace.
8 * Audaspace 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.
13 * AudaSpace 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.
18 * You should have received a copy of the GNU General Public License
19 * along with Audaspace; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * ***** END GPL LICENSE BLOCK *****
25 /** \file audaspace/jack/AUD_JackDevice.h
30 #ifndef __AUD_JACKDEVICE_H__
31 #define __AUD_JACKDEVICE_H__
34 #include "AUD_SoftwareDevice.h"
35 #include "AUD_Buffer.h"
39 #include <AUD_JackLibrary.h>
41 typedef void (*AUD_syncFunction)(void*, int, float);
44 * This device plays back through JACK.
46 class AUD_JackDevice : public AUD_SoftwareDevice
50 * The output ports of jack.
52 jack_port_t** m_ports;
57 jack_client_t* m_client;
65 * The deinterleaving buffer.
67 AUD_Buffer m_deinterleavebuf;
69 jack_ringbuffer_t** m_ringbuffers;
72 * Whether the device is valid.
77 * Invalidates the jack device.
78 * \param data The jack device that gets invalidet by jack.
80 static void jack_shutdown(void *data);
83 * Mixes the next bytes into the buffer.
84 * \param length The length in samples to be filled.
85 * \param data A pointer to the jack device.
86 * \return 0 what shows success.
88 static int jack_mix(jack_nframes_t length, void *data);
90 static int jack_sync(jack_transport_state_t state, jack_position_t* pos, void* data);
93 * Next JACK Transport state (-1 if not expected to change).
95 jack_transport_state_t m_nextState;
98 * Current jack transport status.
100 jack_transport_state_t m_state;
103 * Syncronisation state.
108 * External syncronisation callback function.
110 AUD_syncFunction m_syncFunc;
113 * Data for the sync function.
115 void* m_syncFuncData;
120 pthread_t m_mixingThread;
125 pthread_mutex_t m_mixingLock;
128 * Condition for mixing.
130 pthread_cond_t m_mixingCondition;
133 * Mixing thread function.
134 * \param device The this pointer.
137 static void* runMixingThread(void* device);
140 * Updates the ring buffers.
142 void updateRingBuffers();
144 // hide copy constructor and operator=
145 AUD_JackDevice(const AUD_JackDevice&);
146 AUD_JackDevice& operator=(const AUD_JackDevice&);
149 virtual void playing(bool playing);
153 * Creates a JACK client for audio output.
154 * \param name The client name.
155 * \param specs The wanted audio specification, where only the channel count
157 * \param buffersize The size of the internal buffer.
158 * \exception AUD_Exception Thrown if the audio device cannot be opened.
160 AUD_JackDevice(std::string name, AUD_DeviceSpecs specs, int buffersize = AUD_DEFAULT_BUFFER_SIZE);
163 * Closes the JACK client.
165 virtual ~AUD_JackDevice();
168 * Starts jack transport playback.
170 void startPlayback();
173 * Stops jack transport playback.
178 * Seeks jack transport playback.
179 * \param time The time to seek to.
181 void seekPlayback(float time);
184 * Sets the sync callback for jack transport playback.
185 * \param sync The callback function.
186 * \param data The data for the function.
188 void setSyncCallback(AUD_syncFunction sync, void* data);
191 * Retrieves the jack transport playback time.
192 * \return The current time position.
194 float getPlaybackPosition();
197 * Returns whether jack transport plays back.
198 * \return Whether jack transport plays back.
203 #endif //__AUD_JACKDEVICE_H__