ofSoundStream not working as expected

Hi there. I’m still trying to find a solution to this problem, but I wanted to post in case anyone has an insight.

I’m using Linux (Manjaro) and QTCreator with OF 0.9.2.

I’m working with audio, specifically ofxMaxim. At the end of setup, when I call any of the following:

soundStream.setup(settings);
// Where soundStream is an ofSoundStream object and settings is an
// ofSoundStreamSettings object)

ofSoundStreamSetup(2,2, this, sampleRate, initialBufferSize, 4);/* Call this last ! */@@

ofSoundStreamSetup(2,2,this);

QT spits out:

Starting /home/tollie/Development/openFrameworks/apps/Audio/voiceAnalyserII/bin/voiceAnalyserII_debug…
The program has unexpectedly finished.> /home/tollie/Development/openFrameworks/apps/Audio/voiceAnalyserII/bin/voiceAnalyserII_debug crashed

Otherwise it compiles fine, provided I comment out any audio thread activity.

I’m currently thinking maybe I have an issue with the RTAudio library?

Not sure…

Anyway, cheers all,

Leon

Hmm so ran it with make and getting a segmentation fault? I tried reinstalling rt-audio through yaourt and re-compiling dependencies and OF. Still no likey.

Here is what make run gives me:

[tollie@manjaro audioAnalyserPLZWORK]$ make run
HOST_OS=Linux
checking pkg-config libraries: cairo zlib gstreamer-app-1.0 gstreamer-1.0 gstreamer-video-1.0 gstreamer-base-1.0 libudev freetype2 fontconfig sndfile openal openssl libpulse-simple alsa gl glu glew gtk±3.0 libmpg123
/bin/sh: line 1: 5509 Segmentation fault (core dumped) ./audioAnalyserPLZWORK
/home/tollie/Development/openFrameworks/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk:168: recipe for target ‘run’ failed
make: *** [run] Error 139

So using ofSoundStreamSettings gave me the above error. Now when I use:

ofSoundStreamSetup(2,2, this, sampleRate, initialBufferSize, 4);

It works! Kinda…
Seemingly no audio functionality. Then again I’m fairly new to Manjaro so it’s possible I haven’t set up the mic/speaker correctly. Although the speakers have been working fine with alsamixer…

[tollie@manjaro audioAnalyserPLZWORK]$ make run
HOST_OS=Linux
checking pkg-config libraries: cairo zlib gstreamer-app-1.0 gstreamer-1.0 gstreamer-video-1.0 gstreamer-base-1.0 libudev freetype2 fontconfig sndfile openal openssl libpulse-simple alsa gl glu glew gtk±3.0 libmpg123
[ error ] RtApi::openStream: input and output StreamParameters structures are both NULL

Googling the RtApi error message now…

Nope was being an idiot - where I posted this:

ofSoundStreamSetup(2,2, this, sampleRate, initialBufferSize, 4);

I was actually using this:

ofSoundStreamSetup(0,0, this, sampleRate, initialBufferSize, 4);

changing it to the former of the two causes the same fault as usual with make. Hmm

As a note audioInputExample is working as expected. Still trying to figure out whats going on here. Perhaps its the code actually… Although I presumed it should be fine as I got from a lecturer’s website…

in latest releases of gnome the sound output usually defaults to the hdmi out so you can’t hear anything unless you have an hdmi output connected. usually device 3 is the internal speakers or headphones

Hi thanks for dropping by, its not a problem of audio output - more I seem to be getting a segmentation error when I call this line:

ofSoundStreamSetup(2,2, this, sampleRate, initialBufferSize, 4);

If the above is commented out then there isn’t an issue, it compiles and runs provided I don’t do anything in the audio callback methods…

that might be because the part that runs on the audio callback is actually faulty and doing a bad memory access

Sorry, I don’t think that is the case. iThe below code (note I’m not doing anything in audioIn() or audioOut()) returns the below output when using make run.

[tollie@manjaro audioAnalyserPLZWORK]$ make run
HOST_OS=Linux
checking pkg-config libraries: cairo zlib gstreamer-app-1.0 gstreamer-1.0 gstreamer-video-1.0 gstreamer-base-1.0 libudev freetype2 fontconfig sndfile openal openssl libpulse-simple alsa gl glu glew gtk±3.0 libmpg123
/bin/sh: line 1: 12477 Segmentation fault (core dumped) ./audioAnalyserPLZWORK
/home/tollie/Development/openFrameworks/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk:168: recipe for target ‘run’ failed
make: *** [run] Error 139

Code:

/********************************************************************

  • Based on the MFCC to Wekinator example by Rebecca Fiebrink, 2016
  • Originally adapted from Maximilian example code
  • Now developed by Leon Fedden, 2016
    ****/

#include “ofApp.h”
#include “maximilian.h”/* include the lib */
#include “time.h”

//-------------------------------------------------------------
// Destructor
ofApp::~ofApp() {

}

//--------------------------------------------------------------
void ofApp::setup(){
sender.setup(HOST, PORT);

//Load font
myfont.loadFont("Arial.ttf", 10);
/* some standard setup stuff*/
ofEnableAlphaBlending();
ofSetupScreen();
ofBackground(0, 0, 0);
ofSetFrameRate(60);
/* This is stuff you always need when you use Maximilian. Don't change it.*/
sampleRate 			= 44100; /* Sampling Rate */
initialBufferSize	= 512;	/* Buffer Size. you have to fill this buffer with sound*/
lAudioOut			= new float[initialBufferSize];/* outputs */
rAudioOut			= new float[initialBufferSize];
lAudioIn			= new float[initialBufferSize];/* inputs */
rAudioIn			= new float[initialBufferSize];
/* This is a nice safe piece of code */
memset(lAudioOut, 0, initialBufferSize * sizeof(float));
memset(rAudioOut, 0, initialBufferSize * sizeof(float));
memset(lAudioIn, 0, initialBufferSize * sizeof(float));
memset(rAudioIn, 0, initialBufferSize * sizeof(float));
/* Now you can put anything you would normally put in maximilian's 'setup' method in here. */
mfft.setup(fftSize, 512, 256); //just a forward FFT
oct.setup(sampleRate, fftSize/2, nAverages);
mfccs = (double*) malloc(sizeof(double) * 13);
//512 bins, 42 filters, 13 coeffs, min/max freq 20/20000
mfcc.setup(512, 42, 13, 20, 20000, sampleRate);
ofxMaxiSettings::setup(sampleRate, 2, initialBufferSize);
// ofSoundStreamSettings settings;
//
// auto devices = soundStream.getMatchingDevices("default");
//
//
// if(!devices.empty()){
//
//     settings.setInDevice(devices[0]);
// }
//
//
// settings.setInListener(this);
// settings.sampleRate = sampleRate;
// settings.numOutputChannels = 2;
// settings.numInputChannels = 2;
// settings.bufferSize = initialBufferSize;
//soundStream.setup(settings);
ofSoundStreamSetup(2,2, this, sampleRate, initialBufferSize, 4);/* Call this last ! */
//ofSoundStreamSetup(2,2,this);
ofSetVerticalSync(true);

}

//--------------------------------------------------------------
void ofApp::update(){

}

//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(255, 255, 255,255);

ofSetColor(0, 255, 0, 255);
myfont.drawString(“Sending 13 inputs to port 6448\nUsing message /wek/inputs”, 8, 10);

//Draw MFCC values:
ofSetColor(0, 255, 0,255);
float xinc = 190.0 / 13;

for (int i=0; i < 13; i++) {

   float height = mfccs[i] * 200.0;
   ofRect(10 + (i*xinc),200 - height,10, height);

}

//Send OSC:
ofxOscMessage m;
m.setAddress("/wek/inputs");

for (int i = 0; i < 13; i++) {

   m.addFloatArg(mfccs[i]);

}
sender.sendMessage(m);
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
if( key == ‘s’ ){
soundStream.start();
}

if( key == 'e' ){
    soundStream.stop();
}

}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){

}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){

}

//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){

}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){

}

////--------------------------------------------------------------
void ofApp::audioOut (float * output, int bufferSize, int nChannels){

// // static double tm;
// for (int i = 0; i < bufferSize; i++){
// wave = lAudioIn[i];
//
// //Calculate the mfccs
// if (mfft.process(wave)) { //is the window buffer full?
// mfft.magsToDB();
// oct.calculate(mfft.magnitudesDB);
// mfcc.mfcc(mfft.magnitudes, mfccs);
// }
//
// memset(lAudioOut, 0, initialBufferSize * sizeof(float));
// memset(rAudioOut, 0, initialBufferSize * sizeof(float));
// }
}

////--------------------------------------------------------------
void ofApp::audioIn (float * input, int bufferSize, int nChannels){
//
// for (int i = 0; i < bufferSize; i++){
//
// /* grab the data out of the arrays*/
// lAudioIn[i] = input[i*2];
// rAudioIn[i] = input[i*2+1];
// }
}

interesting update: it would seem that the two outputs cause a segmentation error when running the program. The inputs don’t cause a problem, it is the outputs!

So the below compiles and runs fine (I can do the aforementioned ofxMaxim MFCC processing no problem in the audioIn thread):

ofSoundStreamSettings settings;
auto devices = soundStream.getMatchingDevices(“default”);
if(!devices.empty()){
settings.setInDevice(devices[0]);
}
settings.setInListener(this);
settings.sampleRate = 44100;
settings.numOutputChannels = 0;
settings.numInputChannels = 2;
settings.bufferSize = bufferSize;
soundStream.setup(settings);

However, the below will cause a crash. Note the only difference is the number of output channels compared to the previous 0 outputs. Weird?

ofSoundStreamSettings settings;
auto devices = soundStream.getMatchingDevices(“default”);
if(!devices.empty()){
settings.setInDevice(devices[0]);
}
settings.setInListener(this);
settings.sampleRate = 44100;
settings.numOutputChannels = 2;
settings.numInputChannels = 2;
settings.bufferSize = bufferSize;
soundStream.setup(settings);

@arturo I tried to use device three and that didn’t work unfortunately.

is that code alone, without anything else at all in the application, crashing?

btw you are using quote instead of the code tag to mark the code, you have to enclose code inbtween

```

or just indent it at least four spaces

I also had a segfault with MSYS2 on the master branch. I just pushed a PR #4820 that solves the segfault on MSYS2.
You may want to give it a try (just 2 lines to edit in ofRtAudioSoundStream.cpp)

Hi Arturo, sorry for the delay I’ve been travelling across the UK. No problem will format properly next time.

So yes the code above crashes provided ofSoundStreamSetup() is passed greater than zero output channels. otherwise it runs fine.

@oxillo thanks for the link I’ll read it now and try it out and let you know if it helps.

@oxillo’s PR was merged already in master so if you just pull from there it should be fixed now