Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
InputNode.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/Node.h"
27 #include "cinder/audio/Param.h"
28 #include "cinder/audio/Device.h"
29 
30 namespace cinder { namespace audio {
31 
32 typedef std::shared_ptr<class InputNode> InputNodeRef;
33 typedef std::shared_ptr<class InputDeviceNode> InputDeviceNodeRef;
34 typedef std::shared_ptr<class CallbackProcessorNode> CallbackProcessorNodeRef;
35 
39 class InputNode : public Node {
40  public:
41  virtual ~InputNode();
42 
43  protected:
44  InputNode( const Format &format );
45  private:
46  // InputNode's cannot have any sources, overridden to assert this method isn't called
47  void connectInput( const NodeRef &input ) override;
48 };
49 
54 class InputDeviceNode : public InputNode {
55  public:
56  virtual ~InputDeviceNode();
57 
59  const DeviceRef& getDevice() const { return mDevice; }
60 
62  uint64_t getLastUnderrun() const;
64  uint64_t getLastOverrun() const;
65 
66  protected:
67  InputDeviceNode( const DeviceRef &device, const Format &format );
68 
70  void markUnderrun();
72  void markOverrun();
73 
74  private:
75  DeviceRef mDevice;
76  mutable std::atomic<uint64_t> mLastOverrun, mLastUnderrun;
77 };
78 
80 typedef std::function<void( Buffer *, size_t )> CallbackProcessorFn;
81 
84  public:
85  CallbackProcessorNode( const CallbackProcessorFn &callbackFn, const Format &format = Format() );
87 
88  protected:
89  void process( Buffer *buffer ) override;
90 
91  private:
92  CallbackProcessorFn mCallbackFn;
93 };
94 
95 } } // namespace cinder::audio
uint64_t getLastOverrun() const
Returns the frame of the last buffer overrun or 0 if none since the last time this method was called...
Definition: InputNode.cpp:88
GLenum GLenum GLenum input
Definition: GLee.h:8931
const DeviceRef & getDevice() const
Returns the associated Device.
Definition: InputNode.h:59
void markUnderrun()
Should be called by platform-specific implementations that detect an under-run.
Definition: InputNode.cpp:95
void markOverrun()
Should be called by platform-specific implementations that detect an over-run.
Definition: InputNode.cpp:103
std::shared_ptr< class CallbackProcessorNode > CallbackProcessorNodeRef
Definition: InputNode.h:34
virtual ~InputNode()
Definition: InputNode.cpp:47
Interface representing a Node that communicates with a hardware input device. This is typically a mic...
Definition: InputNode.h:54
virtual ~CallbackProcessorNode()
Definition: InputNode.h:86
virtual ~InputDeviceNode()
Definition: InputNode.cpp:77
InputDeviceNode(const DeviceRef &device, const Format &format)
Definition: InputNode.cpp:60
GLuint buffer
Definition: GLee.h:2065
InputNode(const Format &format)
Definition: InputNode.cpp:36
CallbackProcessorNode(const CallbackProcessorFn &callbackFn, const Format &format=Format())
Definition: InputNode.cpp:116
InputNode that processes audio with a std::function callback.
Definition: InputNode.h:83
Definition: Node.h:72
std::shared_ptr< class Device > DeviceRef
Definition: Device.h:36
uint64_t getLastUnderrun() const
Returns the frame of the last buffer underrun or 0 if none since the last time this method was called...
Definition: InputNode.cpp:81
std::function< void(Buffer *, size_t)> CallbackProcessorFn
Callback used to allow simple audio processing without subclassing a Node. First parameter is the Buf...
Definition: InputNode.h:80
Fundamental building block for creating an audio processing graph.
Definition: Node.h:59
std::shared_ptr< class InputNode > InputNodeRef
Definition: InputNode.h:32
InputNode is the base class for Node's that produce audio. It cannot have any inputs.
Definition: InputNode.h:39
void process(Buffer *buffer) override
Override to perform audio processing on buffer.
Definition: InputNode.cpp:121
std::shared_ptr< class InputDeviceNode > InputDeviceNodeRef
Definition: InputNode.h:33
GLenum GLsizei GLenum format
Definition: GLee.h:969
std::shared_ptr< class Node > NodeRef
Definition: Node.h:39