Blender V2.61 - r43446

AUD_JackDevice.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * Copyright 2009-2011 Jörg Hermann Müller
00005  *
00006  * This file is part of AudaSpace.
00007  *
00008  * Audaspace is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * AudaSpace is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Audaspace; if not, write to the Free Software Foundation,
00020  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00021  *
00022  * ***** END GPL LICENSE BLOCK *****
00023  */
00024 
00030 #ifndef AUD_JACKDEVICE
00031 #define AUD_JACKDEVICE
00032 
00033 
00034 #include "AUD_SoftwareDevice.h"
00035 #include "AUD_Buffer.h"
00036 
00037 #include <string>
00038 
00039 #if defined(__APPLE__) // always first include for jack weaklinking !
00040 #include <weakjack.h>
00041 #endif
00042 
00043 #include <jack.h>
00044 #include <ringbuffer.h>
00045 
00046 typedef void (*AUD_syncFunction)(void*, int, float);
00047 
00051 class AUD_JackDevice : public AUD_SoftwareDevice
00052 {
00053 private:
00057     jack_port_t** m_ports;
00058 
00062     jack_client_t* m_client;
00063 
00067     AUD_Buffer m_buffer;
00068 
00072     AUD_Buffer m_deinterleavebuf;
00073 
00074     jack_ringbuffer_t** m_ringbuffers;
00075 
00079     bool m_valid;
00080 
00085     static void jack_shutdown(void *data);
00086 
00093     static int jack_mix(jack_nframes_t length, void *data);
00094 
00095     static int jack_sync(jack_transport_state_t state, jack_position_t* pos, void* data);
00096 
00100     jack_transport_state_t m_nextState;
00101 
00105     jack_transport_state_t m_state;
00106 
00110     int m_sync;
00111 
00115     AUD_syncFunction m_syncFunc;
00116 
00120     void* m_syncFuncData;
00121 
00125     pthread_t m_mixingThread;
00126 
00130     pthread_mutex_t m_mixingLock;
00131 
00135     pthread_cond_t m_mixingCondition;
00136 
00142     static void* runMixingThread(void* device);
00143 
00147     void updateRingBuffers();
00148 
00149     // hide copy constructor and operator=
00150     AUD_JackDevice(const AUD_JackDevice&);
00151     AUD_JackDevice& operator=(const AUD_JackDevice&);
00152 
00153 protected:
00154     virtual void playing(bool playing);
00155 
00156 public:
00165     AUD_JackDevice(std::string name, AUD_DeviceSpecs specs, int buffersize = AUD_DEFAULT_BUFFER_SIZE);
00166 
00170     virtual ~AUD_JackDevice();
00171 
00175     void startPlayback();
00176 
00180     void stopPlayback();
00181 
00186     void seekPlayback(float time);
00187 
00193     void setSyncCallback(AUD_syncFunction sync, void* data);
00194 
00199     float getPlaybackPosition();
00200 
00205     bool doesPlayback();
00206 };
00207 
00208 #endif //AUD_JACKDEVICE