To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / JackDevice / DeviceManagerJack.cpp
History | View | Annotate | Download (4.77 KB)
| 1 | 1:b5bcad8e7803 | f | /*
|
|---|---|---|---|
| 2 | |||
| 3 | 5:75b744078d66 | f | Copyright (C) 2016 Queen Mary University of London
|
| 4 | Author: Fiore Martin
|
||
| 5 | 1:b5bcad8e7803 | f | |
| 6 | 5:75b744078d66 | f | This file is part of Collidoscope.
|
| 7 | |||
| 8 | Collidoscope 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 3 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, see <http://www.gnu.org/licenses/>.
|
||
| 20 | |||
| 21 | This file incorporates work covered by the following copyright and permission notice:
|
||
| 22 | |||
| 23 | Copyright (c) 2014, The Cinder Project
|
||
| 24 | |||
| 25 | This code is intended to be used with the Cinder C++ library, http://libcinder.org
|
||
| 26 | |||
| 27 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that
|
||
| 28 | the following conditions are met:
|
||
| 29 | 1:b5bcad8e7803 | f | |
| 30 | * Redistributions of source code must retain the above copyright notice, this list of conditions and
|
||
| 31 | the following disclaimer.
|
||
| 32 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||
| 33 | 5:75b744078d66 | f | the following disclaimer in the documentation and/or other materials provided with the distribution.
|
| 34 | 1:b5bcad8e7803 | f | |
| 35 | 5:75b744078d66 | f | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
| 36 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||
| 37 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||
| 38 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||
| 39 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||
| 40 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||
| 41 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||
| 42 | POSSIBILITY OF SUCH DAMAGE.
|
||
| 43 | |||
| 44 | 1:b5bcad8e7803 | f | */
|
| 45 | |||
| 46 | #include "cinder/audio/linux/DeviceManagerJack.h" |
||
| 47 | #include "cinder/audio/Exception.h" |
||
| 48 | #include <jack/jack.h> |
||
| 49 | |||
| 50 | |||
| 51 | namespace cinder { namespace audio { namespace linux { |
||
| 52 | |||
| 53 | DeviceManagerJack::DeviceManagerJack() |
||
| 54 | {
|
||
| 55 | |||
| 56 | 4:ab6db404403a | f | // hardcoded devices. They are always JackIn and JackOut
|
| 57 | 1:b5bcad8e7803 | f | mDevices.push_back( addDevice("JackIn") );
|
| 58 | mDevices.push_back( addDevice("JackOut") );
|
||
| 59 | |||
| 60 | jack_status_t status; |
||
| 61 | |||
| 62 | 4:ab6db404403a | f | // open a jack client, get info and close
|
| 63 | 5:75b744078d66 | f | jack_client_t *client = jack_client_open ("device info", JackNullOption, &status, NULL); |
| 64 | 1:b5bcad8e7803 | f | if( client == NULL){ |
| 65 | |||
| 66 | std::string msg = "jack_client_open() failed. "; |
||
| 67 | if(status & JackServerFailed)
|
||
| 68 | msg += "Unable to connect to Jack server";
|
||
| 69 | |||
| 70 | throw cinder::audio::AudioContextExc(msg);
|
||
| 71 | } |
||
| 72 | |||
| 73 | mSampleRate = jack_get_sample_rate( client ); |
||
| 74 | mBufferSize = jack_get_buffer_size( client ); |
||
| 75 | |||
| 76 | jack_client_close( client ); |
||
| 77 | } |
||
| 78 | |||
| 79 | DeviceManagerJack::~DeviceManagerJack() |
||
| 80 | {
|
||
| 81 | 5:75b744078d66 | f | |
| 82 | 1:b5bcad8e7803 | f | } |
| 83 | |||
| 84 | const std::vector<DeviceRef>& DeviceManagerJack::getDevices()
|
||
| 85 | {
|
||
| 86 | return mDevices;
|
||
| 87 | } |
||
| 88 | |||
| 89 | DeviceRef DeviceManagerJack::getDefaultOutput() |
||
| 90 | {
|
||
| 91 | return mDevices[1]; |
||
| 92 | } |
||
| 93 | |||
| 94 | DeviceRef DeviceManagerJack::getDefaultInput() |
||
| 95 | {
|
||
| 96 | return mDevices[0]; |
||
| 97 | } |
||
| 98 | |||
| 99 | 4:ab6db404403a | f | //hardcoded name same as key
|
| 100 | 1:b5bcad8e7803 | f | std::string DeviceManagerJack::getName( const DeviceRef &device ) |
| 101 | {
|
||
| 102 | return device->getKey();
|
||
| 103 | } |
||
| 104 | |||
| 105 | size_t DeviceManagerJack::getNumInputChannels( const DeviceRef &device )
|
||
| 106 | {
|
||
| 107 | if( device->getKey() == mDevices[0]->getKey() ) |
||
| 108 | return 2; |
||
| 109 | else
|
||
| 110 | return 0; |
||
| 111 | } |
||
| 112 | |||
| 113 | size_t DeviceManagerJack::getNumOutputChannels( const DeviceRef &device )
|
||
| 114 | {
|
||
| 115 | if( device->getKey() == mDevices[1]->getKey() ) |
||
| 116 | return 2; |
||
| 117 | else
|
||
| 118 | return 0; |
||
| 119 | } |
||
| 120 | |||
| 121 | size_t DeviceManagerJack::getSampleRate( const DeviceRef &device )
|
||
| 122 | {
|
||
| 123 | return mSampleRate;
|
||
| 124 | } |
||
| 125 | |||
| 126 | size_t DeviceManagerJack::getFramesPerBlock( const DeviceRef &device )
|
||
| 127 | {
|
||
| 128 | return mBufferSize;
|
||
| 129 | } |
||
| 130 | |||
| 131 | |||
| 132 | void DeviceManagerJack::setSampleRate( const DeviceRef &device, size_t sampleRate ) |
||
| 133 | {
|
||
| 134 | throw "setSampleRate not supported"; |
||
| 135 | } |
||
| 136 | |||
| 137 | void DeviceManagerJack::setFramesPerBlock( const DeviceRef &device, size_t framesPerBlock ) |
||
| 138 | {
|
||
| 139 | throw "setFramesPerBlock not supported"; |
||
| 140 | } |
||
| 141 | |||
| 142 | |||
| 143 | //! Returns the hardware's actual frames per block, which might not be a power of two.
|
||
| 144 | // size_t getFramesPerBlockHardware( const DeviceRef &device );
|
||
| 145 | //
|
||
| 146 | |||
| 147 | size_t DeviceManagerJack::getFramesPerBlockHardware( const DeviceRef &device )
|
||
| 148 | {
|
||
| 149 | return mBufferSize;
|
||
| 150 | } |
||
| 151 | |||
| 152 | |||
| 153 | |||
| 154 | |||
| 155 | |||
| 156 | |||
| 157 | } } } // namespace cinder::audio::linux |