00001 /* 00002 Copyright (c) 2010, Cinder 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that 00006 the following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright notice, this list of conditions and 00009 the following disclaimer. 00010 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 00011 the following disclaimer in the documentation and/or other materials provided with the distribution. 00012 00013 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 00014 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00015 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00016 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00017 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00018 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00019 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00020 POSSIBILITY OF SUCH DAMAGE. 00021 */ 00022 00023 #pragma once 00024 00025 #include "cinder/Cinder.h" 00026 #include "cinder/audio/PcmBuffer.h" 00027 00028 namespace cinder { namespace audio { 00029 00031 // This is an abstract base class for implementing platform specific InputDevices 00032 class InputDevice { 00033 public: 00034 typedef uint32_t DeviceIdentifier; 00035 00036 virtual ~InputDevice() {} 00038 virtual const std::string& getName() = 0; 00039 virtual DeviceIdentifier getDeviceId() { return mDeviceId; } 00040 protected: 00041 InputDevice() {} 00042 DeviceIdentifier mDeviceId; 00043 }; 00045 00046 typedef shared_ptr<InputDevice> InputDeviceRef; 00047 00049 // This is an abstract base class for implementing Input 00050 class InputImpl { 00051 public: 00052 virtual ~InputImpl() {} 00053 00054 virtual void start() = 0; 00055 virtual void stop() = 0; 00056 virtual PcmBuffer32fRef getPcmBuffer() = 0; 00057 virtual bool isCapturing() const = 0; 00058 00059 virtual uint32_t getSampleRate() const = 0; 00060 virtual uint16_t getChannelCount() const = 0; 00061 protected: 00062 InputImpl( InputDeviceRef aDevice ) {} 00063 }; 00065 00066 class Input { 00067 public: 00068 00069 Input(); 00070 Input( InputDeviceRef aDevice ); 00071 ~Input() {} 00072 00074 void start() { mImpl->start(); } 00076 void stop() { mImpl->stop(); } 00078 PcmBuffer32fRef getPcmBuffer() { return mImpl->getPcmBuffer(); } 00080 bool isCapturing() const { return mImpl->isCapturing(); } 00082 uint32_t getSampleRate() { return mImpl->getSampleRate(); }; 00084 uint16_t getChannelCount() { return mImpl->getChannelCount(); }; 00085 00087 static const std::vector<InputDeviceRef>& getDevices( bool forceRefresh = false ); 00089 static InputDeviceRef getDefaultDevice(); 00091 static InputDeviceRef findDeviceByName( const std::string &name ); 00093 static InputDeviceRef findDeviceByNameContains( const std::string &nameFragment ); 00094 private: 00095 shared_ptr<InputImpl> mImpl; 00096 public: 00098 00099 typedef shared_ptr<InputImpl> Input::*unspecified_bool_type; 00100 operator unspecified_bool_type() const { return ( mImpl.get() == 0 ) ? 0 : &Input::mImpl; } 00101 void reset() { mImpl.reset(); } 00103 }; 00104 00105 class InputExc : public Exception {}; 00106 class InvalidDeviceInputExc : public InputExc {}; 00107 00108 }} //namespace