comparison CollidoscopeApp/include/BufferToWaveRecorderNode.h @ 5:75b744078d66

added license
author Fiore Martin <f.martin@qmul.ac.uk>
date Wed, 13 Jul 2016 16:06:46 +0200
parents dd889fff8423
children 4dad0b810f18
comparison
equal deleted inserted replaced
4:ab6db404403a 5:75b744078d66
1 /*
2
3 Copyright (C) 2016 Queen Mary University of London
4 Author: Fiore Martin
5
6 This file is part of Collidoscope.
7
8 Collidoscope is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21 This file incorporates work covered by the following copyright and permission notice:
22
23 Copyright (c) 2014, The Cinder Project
24
25 This code is intended to be used with the Cinder C++ library, http://libcinder.org
26
27 Redistribution and use in source and binary forms, with or without modification, are permitted provided that
28 the following conditions are met:
29
30 * Redistributions of source code must retain the above copyright notice, this list of conditions and
31 the following disclaimer.
32 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
33 the following disclaimer in the documentation and/or other materials provided with the distribution.
34
35 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
36 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
37 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
38 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
39 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 POSSIBILITY OF SUCH DAMAGE.
43
44 */
45
1 #pragma once 46 #pragma once
2 47
3 #include "cinder/Cinder.h" 48 #include "cinder/Cinder.h"
4 #include "cinder/audio/Node.h" 49 #include "cinder/audio/Node.h"
5 #include "cinder/audio/SampleRecorderNode.h" 50 #include "cinder/audio/SampleRecorderNode.h"
6 #include "cinder/audio/dsp/RingBuffer.h" 51 #include "cinder/audio/dsp/RingBuffer.h"
7 #include "cinder/Filesystem.h" 52 #include "cinder/Filesystem.h"
8 53
9 #include "Messages.h" 54 #include "Messages.h"
10 55
11 typedef std::shared_ptr<class BufferToWaveRecorderNode> BufferToWaveRecorderNodeRef; 56 typedef std::shared_ptr<class BufferToWaveRecorderNode> BufferToWaveRecorderNodeRef;
12 57
13 typedef ci::audio::dsp::RingBufferT<RecordWaveMsg> RecordWaveMsgRingBuffer; 58 typedef ci::audio::dsp::RingBufferT<RecordWaveMsg> RecordWaveMsgRingBuffer;
14 59
15 /** 60 /**
16 * A \a Node in the audio graph of the Cinder audio library that records input in a buffer. 61 * A \a Node in the audio graph of the Cinder audio library that records input in a buffer.
41 void setNumFrames(size_t numFrames, bool shrinkToFit = false); 86 void setNumFrames(size_t numFrames, bool shrinkToFit = false);
42 //! Sets the length of the recording buffer in seconds. \see setNumFrames 87 //! Sets the length of the recording buffer in seconds. \see setNumFrames
43 void setNumSeconds(double numSeconds, bool shrinkToFit = false); 88 void setNumSeconds(double numSeconds, bool shrinkToFit = false);
44 89
45 //! Returns the length of the recording buffer in frames. 90 //! Returns the length of the recording buffer in frames.
46 size_t getNumFrames() const { return mRecorderBuffer.getNumFrames(); } 91 size_t getNumFrames() const { return mRecorderBuffer.getNumFrames(); }
47 //! Returns the length of the recording buffer in seconds. 92 //! Returns the length of the recording buffer in seconds.
48 double getNumSeconds() const; 93 double getNumSeconds() const;
49 94
50 //! \brief Returns a copy of the recored samples, up to the current write position. 95 //! \brief Returns a copy of the recored samples, up to the current write position.
51 //! 96 //!
52 //! This method is non locking, and as such any resizing calls must be performed on the same thread or be otherwise synchronized. 97 //! This method is non locking, and as such any resizing calls must be performed on the same thread or be otherwise synchronized.
53 ci::audio::BufferRef getRecordedCopy() const; 98 ci::audio::BufferRef getRecordedCopy() const;
54 99
55 //! \brief Writes the currently recorded samples to a file at \a filePath 100 //! \brief Writes the currently recorded samples to a file at \a filePath
56 //! 101 //!
57 //! The encoding format is derived from \a filePath's extension and \a sampleType (default = SampleType::INT_16). 102 //! The encoding format is derived from \a filePath's extension and \a sampleType (default = SampleType::INT_16).
58 //! \note throws AudioFileExc if the write request cannot be completed. 103 //! \note throws AudioFileExc if the write request cannot be completed.
67 //!returns a pointer to the buffer where the audio is recorder. This is used by the PGranular to create the granular synthesis 112 //!returns a pointer to the buffer where the audio is recorder. This is used by the PGranular to create the granular synthesis
68 ci::audio::Buffer* getRecorderBuffer() { return &mRecorderBuffer; } 113 ci::audio::Buffer* getRecorderBuffer() { return &mRecorderBuffer; }
69 114
70 115
71 protected: 116 protected:
72 void initialize() override; 117 void initialize() override;
73 void process(ci::audio::Buffer *buffer) override; 118 void process(ci::audio::Buffer *buffer) override;
74 119
75 void initBuffers(size_t numFrames); 120 void initBuffers(size_t numFrames);
76 121
77 static const float kMinAudioVal; 122 static const float kMinAudioVal;
78 static const float kMaxAudioVal; 123 static const float kMaxAudioVal;
79 124
80 ci::audio::BufferDynamic mRecorderBuffer; 125 ci::audio::BufferDynamic mRecorderBuffer;
81 ci::audio::BufferDynamicRef mCopiedBuffer; 126 ci::audio::BufferDynamicRef mCopiedBuffer;
82 std::atomic<uint64_t> mLastOverrun; 127 std::atomic<uint64_t> mLastOverrun;
83 128
84 RecordWaveMsgRingBuffer mRingBuffer; 129 RecordWaveMsgRingBuffer mRingBuffer;
85 130
86 const std::size_t mNumChunks; 131 const std::size_t mNumChunks;
87 const double mNumSeconds; 132 const double mNumSeconds;