Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OutputNode.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/Device.h"
28 
29 namespace cinder { namespace audio {
30 
31 typedef std::shared_ptr<class OutputNode> OutputNodeRef;
32 typedef std::shared_ptr<class OutputDeviceNode> OutputDeviceNodeRef;
33 
35 class OutputNode : public Node {
36  public:
37  virtual ~OutputNode() {}
38 
40  virtual size_t getOutputSampleRate() = 0;
42  virtual size_t getOutputFramesPerBlock() = 0;
43 
46  void enableClipDetection( bool enable = true, float threshold = 2 );
50  uint64_t getLastClip();
51 
52  protected:
53  OutputNode( const Format &format = Format() );
54 
56  bool checkNotClipping();
57 
58  std::atomic<uint64_t> mLastClip;
61 
62  private:
63  // OutputNode does not have outputs, overridden to assert this method isn't called
64  void connect( const NodeRef &output ) override;
65 };
66 
71 class OutputDeviceNode : public OutputNode {
72  public:
73  virtual ~OutputDeviceNode() {}
74 
76  const DeviceRef& getDevice() const { return mDevice; }
77 
79  size_t getOutputSampleRate() override { return getDevice()->getSampleRate(); }
81  size_t getOutputFramesPerBlock() override { return getDevice()->getFramesPerBlock(); }
82 
83  protected:
84  OutputDeviceNode( const DeviceRef &device, const Format &format = Format() );
85 
86  virtual void deviceParamsWillChange();
87  virtual void deviceParamsDidChange();
88 
91  signals::scoped_connection mWillChangeConn, mDidChangeConn;
92 };
93 
94 } } // namespace cinder::audio
bool checkNotClipping()
Implementations should call this to detect if the internal audio buffer is clipping. Always returns false if clip detection is disabled.
Definition: OutputNode.cpp:65
uint64_t getLastClip()
Returns the frame of the last buffer clip or 0 if none since the last time this method was called...
Definition: OutputNode.cpp:50
Base class for Node's that consume an audio signal, for example speakers. It cannot have any outputs...
Definition: OutputNode.h:35
virtual size_t getOutputFramesPerBlock()=0
Returns the output frames per block, which governs the current context.
OutputNode(const Format &format=Format())
Definition: OutputNode.cpp:38
bool mWasEnabledBeforeParamsChange
Definition: OutputNode.h:90
bool isClipDetectionEnabled() const
Returns whether clip detection is enabled or not.
Definition: OutputNode.h:48
virtual void deviceParamsDidChange()
Definition: OutputNode.cpp:112
std::shared_ptr< class OutputDeviceNode > OutputDeviceNodeRef
Definition: OutputNode.h:32
virtual ~OutputNode()
Definition: OutputNode.h:37
virtual size_t getOutputSampleRate()=0
Returns the output samplerate, which governs the current context.
float mClipThreshold
Definition: OutputNode.h:60
void enableClipDetection(bool enable=true, float threshold=2)
Definition: OutputNode.cpp:57
signals::scoped_connection mWillChangeConn
Definition: OutputNode.h:91
Interface representing a Node that communicates with a hardware output device. This is typically spea...
Definition: OutputNode.h:71
bool mClipDetectionEnabled
Definition: OutputNode.h:59
std::shared_ptr< class Device > DeviceRef
Definition: Device.h:36
Fundamental building block for creating an audio processing graph.
Definition: Node.h:59
const DeviceRef & getDevice() const
Returns a shared_ptr to the Device that this OutputDeviceNode operates.
Definition: OutputNode.h:76
DeviceRef mDevice
Definition: OutputNode.h:89
std::atomic< uint64_t > mLastClip
Definition: OutputNode.h:58
virtual ~OutputDeviceNode()
Definition: OutputNode.h:73
signals::scoped_connection mDidChangeConn
Definition: OutputNode.h:91
void enable()
Enables this Node for processing. Same as setEnabled( true ).
Definition: Node.cpp:165
OutputDeviceNode(const DeviceRef &device, const Format &format=Format())
Definition: OutputNode.cpp:82
GLenum GLsizei GLenum format
Definition: GLee.h:969
size_t getOutputSampleRate() override
Implemented to return the samplerate of the owned Device.
Definition: OutputNode.h:79
std::shared_ptr< class Node > NodeRef
Definition: Node.h:39
virtual void deviceParamsWillChange()
Definition: OutputNode.cpp:104
std::shared_ptr< class OutputNode > OutputNodeRef
Definition: OutputNode.h:31
void threshold(SurfaceT< T > *surface, T value, const Area &area)
Thresholds surface setting any values below value to zero and any values above to unity inside the Ar...
Definition: Threshold.cpp:100
size_t getOutputFramesPerBlock() override
Implemented to return the frames per block of the owned Device.
Definition: OutputNode.h:81