1 /*
2 * Author: Harry van Haaren 2013
3 * harryhaaren@gmail.com
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "audiobuffer.hxx"
20 #include "config.hxx"
21
22 #include <stdio.h>
23
AudioBuffer()24 AudioBuffer::AudioBuffer()
25 {
26 ID = privateID++;
27 init();
28 }
29
AudioBuffer(unsigned long size)30 AudioBuffer::AudioBuffer(unsigned long size)
31 {
32 // FIXME recorded buffers don't get an ID, using garbage IDs
33 /// no ID assigned: it *takes* the one from the previous buffer!
34 init();
35 bufferL.resize(size);
36 bufferR.resize(size);
37 }
38
init()39 void AudioBuffer::init()
40 {
41 numBeats = 0;
42 audioFrames = 0;
43 }
44
45 /// this function is used for "resizing" an exisiting buffer, and should
46 /// not be called for any other reason.
setID(int id)47 void AudioBuffer::setID(int id)
48 {
49 ID = id;
50 }
51
getID()52 int AudioBuffer::getID()
53 {
54 return ID;
55 }
56
setName(const std::string & n)57 void AudioBuffer::setName(const std::string& n)
58 {
59 name = n;
60 if (n.size() > 20) {
61 #ifdef DEBUG_BUFFER
62 cout << "AudioBuffer setName too long, truncating." << endl;
63 #endif
64 name.resize(20);
65 }
66 }
67
getName() const68 const std::string& AudioBuffer::getName() const
69 {
70 return name;
71 }
72
getBeats()73 int AudioBuffer::getBeats()
74 {
75 return numBeats;
76 }
77
setBeats(int b)78 void AudioBuffer::setBeats(int b)
79 {
80 #ifdef DEBUG_BUFFER
81 cout << "AudioBuffer now has " << b << " beats\n" << endl;
82 #endif
83 numBeats = b;
84 }
85
setAudioFrames(long af)86 void AudioBuffer::setAudioFrames(long af)
87 {
88 audioFrames = af;
89 #ifdef DEBUG_BUFFER
90 cout << "AudioBuffer " << ID << " has " << audioFrames << " audioFrames\n" << endl;
91 #endif
92 }
93
getAudioFrames()94 long AudioBuffer::getAudioFrames()
95 {
96 return audioFrames;
97 }
98
getSize()99 long AudioBuffer::getSize()
100 {
101 if(bufferL.size() != bufferR.size()) {
102 LUPPP_WARN("left and right channels of audio buffer have different size: %i vs %i", bufferL.size(), bufferR.size() );
103 }
104 return std::min(bufferL.size(), bufferR.size());
105 }
106
getDataL()107 std::vector<float>& AudioBuffer::getDataL()
108 {
109 return bufferL;
110 }
getDataR()111 std::vector<float>& AudioBuffer::getDataR()
112 {
113 return bufferR;
114 }
115
nonRtSetSample(std::vector<float> & sampleL,std::vector<float> & sampleR)116 void AudioBuffer::nonRtSetSample(std::vector<float>& sampleL, std::vector<float>& sampleR)
117 {
118 bufferL.swap(sampleL);
119 bufferR.swap(sampleR);
120 }
nonRtResize(unsigned long size)121 void AudioBuffer::nonRtResize(unsigned long size)
122 {
123 bufferL.resize(size);
124 bufferR.resize(size);
125 }