To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / JackDevice / DeviceManagerJack.cpp @ 4:ab6db404403a

History | View | Annotate | Download (3.9 KB)

1 1:b5bcad8e7803 f
/*
2
 Copyright (c) 2015, The Cinder Project
3

4
 This code is intended to be used with the Cinder C++ library, http://libcinder.org
5

6
 Redistribution and use in source and binary forms, with or without modification, are permitted provided that
7
 the following conditions are met:
8

9
    * Redistributions of source code must retain the above copyright notice, this list of conditions and
10

11
    the following disclaimer.
12
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
13
        the following disclaimer in the documentation and/or other materials provided with the distribution.
14

15
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16
 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17
 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18
 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19
 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
 POSSIBILITY OF SUCH DAMAGE.
23
*/
24
25
#include "cinder/audio/linux/DeviceManagerJack.h"
26
#include "cinder/audio/Exception.h"
27
#include <jack/jack.h>
28
29
30
namespace cinder { namespace audio { namespace linux {
31
32
DeviceManagerJack::DeviceManagerJack()
33
{
34
35 4:ab6db404403a f
    // hardcoded devices. They are always JackIn and JackOut
36 1:b5bcad8e7803 f
    mDevices.push_back( addDevice("JackIn") );
37
    mDevices.push_back( addDevice("JackOut") );
38
39
    jack_status_t status;
40
41 4:ab6db404403a f
    // open a jack client, get info and close
42 1:b5bcad8e7803 f
        jack_client_t *client = jack_client_open ("device info", JackNullOption, &status, NULL);
43
    if( client == NULL){
44
45
        std::string msg = "jack_client_open() failed. ";
46
        if(status & JackServerFailed)
47
            msg += "Unable to connect to Jack server";
48
49
        throw cinder::audio::AudioContextExc(msg);
50
    }
51
52
    mSampleRate = jack_get_sample_rate( client );
53
    mBufferSize = jack_get_buffer_size( client );
54
55
    jack_client_close( client );
56
}
57
58
DeviceManagerJack::~DeviceManagerJack()
59
{
60
61
}
62
63
const std::vector<DeviceRef>& DeviceManagerJack::getDevices()
64
{
65
   return mDevices;
66
}
67
68
DeviceRef DeviceManagerJack::getDefaultOutput()
69
{
70
    return mDevices[1];
71
}
72
73
DeviceRef DeviceManagerJack::getDefaultInput()
74
{
75
    return mDevices[0];
76
}
77
78 4:ab6db404403a f
//hardcoded name same as key
79 1:b5bcad8e7803 f
std::string DeviceManagerJack::getName( const DeviceRef &device )
80
{
81
    return device->getKey();
82
}
83
84
size_t DeviceManagerJack::getNumInputChannels( const DeviceRef &device )
85
{
86
    if( device->getKey() == mDevices[0]->getKey() )
87
        return 2;
88
    else
89
        return 0;
90
}
91
92
size_t DeviceManagerJack::getNumOutputChannels( const DeviceRef &device )
93
{
94
    if( device->getKey() == mDevices[1]->getKey() )
95
        return 2;
96
    else
97
        return 0;
98
}
99
100
size_t DeviceManagerJack::getSampleRate( const DeviceRef &device )
101
{
102
    return mSampleRate;
103
}
104
105
size_t DeviceManagerJack::getFramesPerBlock( const DeviceRef &device )
106
{
107
    return mBufferSize;
108
}
109
110
111
void DeviceManagerJack::setSampleRate( const DeviceRef &device, size_t sampleRate )
112
{
113
    throw "setSampleRate not supported";
114
}
115
116
void DeviceManagerJack::setFramesPerBlock( const DeviceRef &device, size_t framesPerBlock )
117
{
118
    throw "setFramesPerBlock not supported";
119
}
120
121
122
//! Returns the hardware's actual frames per block, which might not be a power of two.
123
//        size_t getFramesPerBlockHardware( const DeviceRef &device );
124
//
125
126
size_t DeviceManagerJack::getFramesPerBlockHardware( const DeviceRef &device )
127
{
128
    return mBufferSize;
129
}
130
131
132
133
134
135
136
} } } // namespace cinder::audio::linux