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 @ 1:b5bcad8e7803

History | View | Annotate | Download (3.76 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
    mDevices.push_back( addDevice("JackIn") );
36
    mDevices.push_back( addDevice("JackOut") );
37
38
    jack_status_t status;
39
40
        jack_client_t *client = jack_client_open ("device info", JackNullOption, &status, NULL);
41
    if( client == NULL){
42
43
        std::string msg = "jack_client_open() failed. ";
44
        if(status & JackServerFailed)
45
            msg += "Unable to connect to Jack server";
46
47
        throw cinder::audio::AudioContextExc(msg);
48
    }
49
50
    mSampleRate = jack_get_sample_rate( client );
51
    mBufferSize = jack_get_buffer_size( client );
52
53
    jack_client_close( client );
54
}
55
56
DeviceManagerJack::~DeviceManagerJack()
57
{
58
59
}
60
61
const std::vector<DeviceRef>& DeviceManagerJack::getDevices()
62
{
63
   return mDevices;
64
}
65
66
DeviceRef DeviceManagerJack::getDefaultOutput()
67
{
68
    return mDevices[1];
69
}
70
71
DeviceRef DeviceManagerJack::getDefaultInput()
72
{
73
    return mDevices[0];
74
}
75
76
std::string DeviceManagerJack::getName( const DeviceRef &device )
77
{
78
    return device->getKey();
79
}
80
81
size_t DeviceManagerJack::getNumInputChannels( const DeviceRef &device )
82
{
83
    if( device->getKey() == mDevices[0]->getKey() )
84
        return 2;
85
    else
86
        return 0;
87
}
88
89
size_t DeviceManagerJack::getNumOutputChannels( const DeviceRef &device )
90
{
91
    if( device->getKey() == mDevices[1]->getKey() )
92
        return 2;
93
    else
94
        return 0;
95
}
96
97
size_t DeviceManagerJack::getSampleRate( const DeviceRef &device )
98
{
99
    return mSampleRate;
100
}
101
102
size_t DeviceManagerJack::getFramesPerBlock( const DeviceRef &device )
103
{
104
    return mBufferSize;
105
}
106
107
108
void DeviceManagerJack::setSampleRate( const DeviceRef &device, size_t sampleRate )
109
{
110
    throw "setSampleRate not supported";
111
}
112
113
void DeviceManagerJack::setFramesPerBlock( const DeviceRef &device, size_t framesPerBlock )
114
{
115
    throw "setFramesPerBlock not supported";
116
}
117
118
119
//! Returns the hardware's actual frames per block, which might not be a power of two.
120
//        size_t getFramesPerBlockHardware( const DeviceRef &device );
121
//
122
123
size_t DeviceManagerJack::getFramesPerBlockHardware( const DeviceRef &device )
124
{
125
    return mBufferSize;
126
}
127
128
129
130
131
132
133
} } } // namespace cinder::audio::linux