Skip to content

Commit 80d2c97

Browse files
committed
avoid crash on empty audio signal cable
1 parent 63437e0 commit 80d2c97

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/objects/audio_analysis/AudioAnalyzer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ void AudioAnalyzer::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
9393

9494
//--------------------------------------------------------------
9595
void AudioAnalyzer::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
96+
unusedArgs(patchObjects);
9697

9798
if(this->inletsConnected[0]){
9899
if(!isConnected){
@@ -163,6 +164,8 @@ void AudioAnalyzer::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchO
163164

164165
//--------------------------------------------------------------
165166
void AudioAnalyzer::drawObjectContent(ofTrueTypeFont *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
167+
unusedArgs(font,glRenderer);
168+
166169
ofSetColor(255);
167170
}
168171

@@ -227,11 +230,15 @@ void AudioAnalyzer::drawObjectNodeConfig(){
227230

228231
//--------------------------------------------------------------
229232
void AudioAnalyzer::removeObjectContent(bool removeFileFromData){
230-
233+
unusedArgs(removeFileFromData);
231234
}
232235

233236
//--------------------------------------------------------------
234237
void AudioAnalyzer::audioOutObject(ofSoundBuffer &inputBuffer){
238+
unusedArgs(inputBuffer);
239+
240+
if(static_cast<ofSoundBuffer *>(_inletParams[0])->getBuffer().empty()) return;
241+
235242
if(this->inletsConnected[0] && isConnected && ofGetElapsedTimeMillis()-startTime > waitTime){
236243

237244
lastBuffer = *static_cast<ofSoundBuffer *>(_inletParams[0]);
@@ -251,6 +258,7 @@ void AudioAnalyzer::audioOutObject(ofSoundBuffer &inputBuffer){
251258
// autocorrelation + normalization
252259
doAutoCorrelation(monoBuffer.getBuffer().data());
253260

261+
254262
// get volume
255263
detectRMS();
256264

@@ -361,6 +369,7 @@ void AudioAnalyzer::loadAudioSettings(){
361369

362370
//--------------------------------------------------------------
363371
void AudioAnalyzer::doAutoCorrelation(float* signal){
372+
364373
float sum;
365374
std::vector<float> autoCorrelationResults(bufferSize);
366375

src/objects/gui/moSignalViewer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ void moSignalViewer::audioOutObject(ofSoundBuffer &outBuffer){
197197
static_cast<vector<float> *>(_outletParams[2])->at(i) = sample;
198198
}
199199
}else{
200-
*static_cast<ofSoundBuffer *>(_outletParams[0]) *= 0.0f;
201-
*static_cast<ofSoundBuffer *>(_outletParams[1]) *= 0.0f;
200+
static_cast<ofSoundBuffer *>(_outletParams[0])->set(0.0f);
201+
static_cast<ofSoundBuffer *>(_outletParams[1])->set(0.0f);
202202
}
203203

204204
}

src/objects/sound/AudioGate.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ void AudioGate::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
105105

106106
//--------------------------------------------------------------
107107
void AudioGate::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
108+
unusedArgs(patchObjects);
108109

109110
if(this->inletsConnected[0]){
110111
if(static_cast<int>(floor(*(float *)&_inletParams[0])) != openInlet){
@@ -140,6 +141,8 @@ void AudioGate::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjec
140141

141142
//--------------------------------------------------------------
142143
void AudioGate::drawObjectContent(ofTrueTypeFont *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
144+
unusedArgs(font,glRenderer);
145+
143146
ofSetColor(255);
144147

145148
}
@@ -224,15 +227,21 @@ void AudioGate::drawObjectNodeConfig(){
224227

225228
//--------------------------------------------------------------
226229
void AudioGate::removeObjectContent(bool removeFileFromData){
227-
230+
unusedArgs(removeFileFromData);
228231
}
229232

230233
//--------------------------------------------------------------
231234
void AudioGate::audioOutObject(ofSoundBuffer &outputBuffer){
235+
unusedArgs(outputBuffer);
236+
232237
if(openInlet >= 1 && openInlet < this->numInlets){
233-
*static_cast<ofSoundBuffer *>(_outletParams[0]) = *static_cast<ofSoundBuffer *>(_inletParams[openInlet]);
238+
if(this->inletsConnected[openInlet]){
239+
*static_cast<ofSoundBuffer *>(_outletParams[0]) = *static_cast<ofSoundBuffer *>(_inletParams[openInlet]);
240+
}else{
241+
static_cast<ofSoundBuffer *>(_outletParams[0])->set(0.0f);
242+
}
234243
}else if(openInlet == 0){
235-
*static_cast<ofSoundBuffer *>(_outletParams[0]) *= 0.0f;
244+
static_cast<ofSoundBuffer *>(_outletParams[0])->set(0.0f);
236245
}
237246
}
238247

@@ -262,7 +271,7 @@ void AudioGate::resetInletsSettings(){
262271
_inletParams[0] = new float(); // open
263272
*(float *)&_inletParams[0] = 0.0f;
264273

265-
for(size_t i=1;i<this->numInlets;i++){
274+
for(int i=1;i<this->numInlets;i++){
266275
_inletParams[i] = new ofSoundBuffer();
267276
static_cast<ofSoundBuffer *>(_inletParams[i])->set(0.0f);
268277
}
@@ -274,7 +283,7 @@ void AudioGate::resetInletsSettings(){
274283

275284
this->addInlet(VP_LINK_NUMERIC,"open");
276285

277-
for(size_t i=1;i<this->numInlets;i++){
286+
for(int i=1;i<this->numInlets;i++){
278287
this->addInlet(VP_LINK_AUDIO,"s"+ofToString(i));
279288
}
280289

0 commit comments

Comments
 (0)