Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DeviceManagerCoreAudio.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2014, 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  the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12  the following disclaimer in the documentation and/or other materials provided with the distribution.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
15  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
16  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
17  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
18  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21  POSSIBILITY OF SUCH DAMAGE.
22 */
23 
24 #pragma once
25 
26 #include "cinder/audio/Device.h"
27 
28 #include <AudioUnit/AudioUnit.h>
29 #include <CoreAudio/CoreAudio.h>
30 #include <map>
31 
32 namespace cinder { namespace audio { namespace cocoa {
33 
35  public:
37 
38  const std::vector<DeviceRef>& getDevices() override;
39  DeviceRef getDefaultOutput() override;
40  DeviceRef getDefaultInput() override;
41 
42  std::string getName( const DeviceRef &device ) override;
43  size_t getNumInputChannels( const DeviceRef &device ) override;
44  size_t getNumOutputChannels( const DeviceRef &device ) override;
45  size_t getSampleRate( const DeviceRef &device ) override;
46  size_t getFramesPerBlock( const DeviceRef &device ) override;
47 
48  void setSampleRate( const DeviceRef &device, size_t sampleRate ) override;
49  void setFramesPerBlock( const DeviceRef &device, size_t framesPerBlock ) override;
50 
51  bool isFormatUpdatedAsync() const override { return true; }
52 
54  void setCurrentOutputDevice( const DeviceRef &device, ::AudioComponentInstance componentInstance );
55  void setCurrentInputDevice( const DeviceRef &device, ::AudioComponentInstance componentInstance );
56 
57  private:
58  void setCurrentDeviceImpl( const DeviceRef &device, const DeviceRef &current, ::AudioComponentInstance componentInstance, bool isOutput );
59  // device is copied in so that it is retained in an async callback.
60  void registerPropertyListeners( DeviceRef device, ::AudioDeviceID deviceId, bool isOutput );
61  void unregisterPropertyListeners( const DeviceRef &device, ::AudioDeviceID deviceId, bool isOutput );
62 
63  std::vector<size_t> getAcceptableSampleRates( ::AudioDeviceID deviceId );
64  std::pair<size_t, size_t> getAcceptableFramesPerBlockRange( ::AudioDeviceID deviceId );
65 
66  static std::string keyForDeviceId( ::AudioDeviceID deviceId );
67 
68  std::map<DeviceRef, ::AudioDeviceID> mDeviceIds;
69  DeviceRef mCurrentOutputDevice, mCurrentInputDevice;
70  ::AudioObjectPropertyListenerBlock mOutputDeviceListenerBlock, mInputDeviceListenerBlock;
71 
72  bool mUserHasModifiedFormat; // flag that indicates the user has modified device format, rather than a system update.
73 
74  friend class Context;
75 };
76 
77 } } } // namespace cinder::audio::cocoa
DeviceRef getDefaultInput() override
Definition: DeviceManagerCoreAudio.cpp:148
GLsizei const GLchar ** string
Definition: GLee.h:2427
size_t getNumInputChannels(const DeviceRef &device) override
Definition: DeviceManagerCoreAudio.cpp:162
std::string getName(const DeviceRef &device) override
Definition: DeviceManagerCoreAudio.cpp:156
Manages the creation, connections, and lifecycle of audio::Node's.
Definition: Context.h:44
size_t getNumOutputChannels(const DeviceRef &device) override
Definition: DeviceManagerCoreAudio.cpp:168
void setFramesPerBlock(const DeviceRef &device, size_t framesPerBlock) override
Definition: DeviceManagerCoreAudio.cpp:207
DeviceRef getDefaultOutput() override
Definition: DeviceManagerCoreAudio.cpp:140
bool isFormatUpdatedAsync() const override
override if subclass needs to update params async, and will issue formatWillChange callbacks ...
Definition: DeviceManagerCoreAudio.h:51
Definition: DeviceManagerCoreAudio.h:34
void setCurrentInputDevice(const DeviceRef &device,::AudioComponentInstance componentInstance)
Definition: DeviceManagerCoreAudio.cpp:228
Platform-specific Singleton for managing hardware devices. Applications normally should not need to u...
Definition: Device.h:110
const std::vector< DeviceRef > & getDevices() override
Definition: DeviceManagerCoreAudio.cpp:348
size_t getSampleRate(const DeviceRef &device) override
Definition: DeviceManagerCoreAudio.cpp:174
std::shared_ptr< class Device > DeviceRef
Definition: Device.h:36
void setCurrentOutputDevice(const DeviceRef &device,::AudioComponentInstance componentInstance)
Sets the device related to key and managed by componenetInstance as the current active audio device...
Definition: DeviceManagerCoreAudio.cpp:222
void setSampleRate(const DeviceRef &device, size_t sampleRate) override
Definition: DeviceManagerCoreAudio.cpp:183
size_t getFramesPerBlock(const DeviceRef &device) override
Definition: DeviceManagerCoreAudio.cpp:198
DeviceManagerCoreAudio()
Definition: DeviceManagerCoreAudio.cpp:135