Changeset View
Changeset View
Standalone View
Standalone View
extern/audaspace/plugins/jack/JackDevice.h
- This file was moved from intern/audaspace/jack/AUD_JackDevice.h.
| /* | /******************************************************************************* | ||||
| * ***** BEGIN GPL LICENSE BLOCK ***** | * Copyright 2009-2016 Jörg Müller | ||||
| * | * | ||||
| * Copyright 2009-2011 Jörg Hermann Müller | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| * you may not use this file except in compliance with the License. | |||||
| * You may obtain a copy of the License at | |||||
| * | * | ||||
| * This file is part of AudaSpace. | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
| * | * | ||||
| * Audaspace is free software; you can redistribute it and/or modify | * Unless required by applicable law or agreed to in writing, software | ||||
| * it under the terms of the GNU General Public License as published by | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
| * the Free Software Foundation; either version 2 of the License, or | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * (at your option) any later version. | * See the License for the specific language governing permissions and | ||||
| * | * limitations under the License. | ||||
| * AudaSpace is distributed in the hope that it will be useful, | ******************************************************************************/ | ||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with Audaspace; if not, write to the Free Software Foundation, | |||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
| * | |||||
| * ***** END GPL LICENSE BLOCK ***** | |||||
| */ | |||||
| /** \file audaspace/jack/AUD_JackDevice.h | #pragma once | ||||
| * \ingroup audjack | |||||
| */ | |||||
| #ifdef JACK_PLUGIN | |||||
| #define AUD_BUILD_PLUGIN | |||||
| #endif | |||||
| #ifndef __AUD_JACKDEVICE_H__ | /** | ||||
| #define __AUD_JACKDEVICE_H__ | * @file JackDevice.h | ||||
| * @ingroup plugin | |||||
| * The JackDevice class. | |||||
| */ | |||||
| #include "AUD_SoftwareDevice.h" | #include "JackSynchronizer.h" | ||||
| #include "AUD_Buffer.h" | #include "devices/SoftwareDevice.h" | ||||
| #include "util/Buffer.h" | |||||
| #include <string> | #include <string> | ||||
| #include <condition_variable> | |||||
| #include <thread> | |||||
| #include <jack/jack.h> | |||||
| #include <jack/ringbuffer.h> | |||||
| #include <AUD_JackLibrary.h> | AUD_NAMESPACE_BEGIN | ||||
| typedef void (*AUD_syncFunction)(void*, int, float); | |||||
| /** | /** | ||||
| * This device plays back through JACK. | * This device plays back through JACK. | ||||
| */ | */ | ||||
| class AUD_JackDevice : public AUD_SoftwareDevice | class AUD_PLUGIN_API JackDevice : public SoftwareDevice | ||||
| { | { | ||||
| private: | private: | ||||
| /** | /** | ||||
| Context not available. | |||||
| /** | /** | ||||
| * The output buffer. | * The output buffer. | ||||
| */ | */ | ||||
| AUD_Buffer m_buffer; | Buffer m_buffer; | ||||
| /** | /** | ||||
| * The deinterleaving buffer. | * The deinterleaving buffer. | ||||
| */ | */ | ||||
| AUD_Buffer m_deinterleavebuf; | Buffer m_deinterleavebuf; | ||||
| jack_ringbuffer_t** m_ringbuffers; | jack_ringbuffer_t** m_ringbuffers; | ||||
| Context not available. | |||||
| */ | */ | ||||
| bool m_valid; | bool m_valid; | ||||
| /// Synchronizer. | |||||
| JackSynchronizer m_synchronizer; | |||||
| /** | /** | ||||
| * Invalidates the jack device. | * Invalidates the jack device. | ||||
| * \param data The jack device that gets invalidet by jack. | * \param data The jack device that gets invalidet by jack. | ||||
| */ | */ | ||||
| static void jack_shutdown(void *data); | AUD_LOCAL static void jack_shutdown(void* data); | ||||
| /** | /** | ||||
| * Mixes the next bytes into the buffer. | * Mixes the next bytes into the buffer. | ||||
| Context not available. | |||||
| * \param data A pointer to the jack device. | * \param data A pointer to the jack device. | ||||
| * \return 0 what shows success. | * \return 0 what shows success. | ||||
| */ | */ | ||||
| static int jack_mix(jack_nframes_t length, void *data); | AUD_LOCAL static int jack_mix(jack_nframes_t length, void* data); | ||||
| static int jack_sync(jack_transport_state_t state, jack_position_t* pos, void* data); | AUD_LOCAL static int jack_sync(jack_transport_state_t state, jack_position_t* pos, void* data); | ||||
| /** | /** | ||||
| * Next JACK Transport state (-1 if not expected to change). | * Next JACK Transport state (-1 if not expected to change). | ||||
| Context not available. | |||||
| /** | /** | ||||
| * External syncronisation callback function. | * External syncronisation callback function. | ||||
| */ | */ | ||||
| AUD_syncFunction m_syncFunc; | ISynchronizer::syncFunction m_syncFunc; | ||||
| /** | /** | ||||
| * Data for the sync function. | * Data for the sync function. | ||||
| Context not available. | |||||
| /** | /** | ||||
| * The mixing thread. | * The mixing thread. | ||||
| */ | */ | ||||
| pthread_t m_mixingThread; | std::thread m_mixingThread; | ||||
| /** | /** | ||||
| * Mutex for mixing. | * Mutex for mixing. | ||||
| */ | */ | ||||
| pthread_mutex_t m_mixingLock; | std::mutex m_mixingLock; | ||||
| /** | /** | ||||
| * Condition for mixing. | * Condition for mixing. | ||||
| */ | */ | ||||
| pthread_cond_t m_mixingCondition; | std::condition_variable m_mixingCondition; | ||||
| /** | |||||
| * Mixing thread function. | |||||
| * \param device The this pointer. | |||||
| * \return NULL. | |||||
| */ | |||||
| static void* runMixingThread(void* device); | |||||
| /** | /** | ||||
| * Updates the ring buffers. | * Updates the ring buffers. | ||||
| */ | */ | ||||
| void updateRingBuffers(); | AUD_LOCAL void updateRingBuffers(); | ||||
| // hide copy constructor and operator= | // delete copy constructor and operator= | ||||
| AUD_JackDevice(const AUD_JackDevice&); | JackDevice(const JackDevice&) = delete; | ||||
| AUD_JackDevice& operator=(const AUD_JackDevice&); | JackDevice& operator=(const JackDevice&) = delete; | ||||
| protected: | protected: | ||||
| virtual void playing(bool playing); | virtual void playing(bool playing); | ||||
| Context not available. | |||||
| * \param specs The wanted audio specification, where only the channel count | * \param specs The wanted audio specification, where only the channel count | ||||
| * is important. | * is important. | ||||
| * \param buffersize The size of the internal buffer. | * \param buffersize The size of the internal buffer. | ||||
| * \exception AUD_Exception Thrown if the audio device cannot be opened. | * \exception Exception Thrown if the audio device cannot be opened. | ||||
| */ | */ | ||||
| AUD_JackDevice(std::string name, AUD_DeviceSpecs specs, int buffersize = AUD_DEFAULT_BUFFER_SIZE); | JackDevice(std::string name, DeviceSpecs specs, int buffersize = AUD_DEFAULT_BUFFER_SIZE); | ||||
| /** | /** | ||||
| * Closes the JACK client. | * Closes the JACK client. | ||||
| */ | */ | ||||
| virtual ~AUD_JackDevice(); | virtual ~JackDevice(); | ||||
| virtual ISynchronizer* getSynchronizer(); | |||||
| /** | /** | ||||
| * Starts jack transport playback. | * Starts jack transport playback. | ||||
| Context not available. | |||||
| * \param sync The callback function. | * \param sync The callback function. | ||||
| * \param data The data for the function. | * \param data The data for the function. | ||||
| */ | */ | ||||
| void setSyncCallback(AUD_syncFunction sync, void* data); | void setSyncCallback(ISynchronizer::syncFunction sync, void* data); | ||||
| /** | /** | ||||
| * Retrieves the jack transport playback time. | * Retrieves the jack transport playback time. | ||||
| Context not available. | |||||
| * \return Whether jack transport plays back. | * \return Whether jack transport plays back. | ||||
| */ | */ | ||||
| bool doesPlayback(); | bool doesPlayback(); | ||||
| /** | |||||
| * Registers this plugin. | |||||
| */ | |||||
| static void registerPlugin(); | |||||
| }; | }; | ||||
| #endif //__AUD_JACKDEVICE_H__ | AUD_NAMESPACE_END | ||||
| Context not available. | |||||