Segmentation fault when ofxMaxim playes sample on Raspberry pi

Hello,

I am using ofxMaxim to play a sample. The code works on Windows but on Raspberry pi 3 I get a Segmentation fault. If I use a sine oscillator to make a tone it works on both machines.

Here is the code, is very basic and it is based on the sample player example of ofxMaxim:

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup() {
	sampleRate = 44100;
	bufferSize = 1024;

	soundStream.listDevices();
#ifdef TARGET_RASPBERRY_PI 
	soundStream.setDeviceID(2);
#else
	soundStream.setDeviceID(1);
#endif

	soundStream.setup(this, 2, 0, sampleRate, bufferSize, 4);
	tsiks.load(ofToDataPath("tsiks.wav"));
}
//
void ofApp::audioOut(float * output, int bufferSize, int nChannels) {
	for (int n = 0; n < bufferSize; n++) {
		output[n*nChannels] = tsiks.play(1);
		output[n*nChannels + 1] = tsiks.play(1);
	}
}
//--------------------------------------------------------------
void ofApp::update() {
}
//
void ofApp::draw() {
}

and here is the error:

 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 gtk+-3.0 libmpg123
[notice ] ofAppEGLWindow: setupRPiNativeWindow(): screenRect: 720x480
[notice ] ofAppEGLWindow: setupRPiNativeWindow(): windowRect: 720x480
[notice ] ofAppEGLWindow: createSurface(): setting up EGL Display
[notice ] ofAppEGLWindow: createSurface(): EGL Display correctly set 0x1
[notice ] ofAppEGLWindow: createSurface(): no current renderer selected
[notice ] ofAppEGLWindow: createSurface(): default renderer detected
[notice ] ofAppEGLWindow: createSurface(): surface created correctly
[notice ] ofAppEGLWindow: createSurface(): API bound correctly
[notice ] ofAppEGLWindow: createSurface(): -----EGL-----
[notice ] ofAppEGLWindow: createSurface(): EGL_VERSION_MAJOR = 1
[notice ] ofAppEGLWindow: createSurface(): EGL_VERSION_MINOR = 4
[notice ] ofAppEGLWindow: createSurface(): EGL_CLIENT_APIS = OpenGL_ES OpenVG
[notice ] ofAppEGLWindow: createSurface(): EGL_VENDOR = Broadcom
[notice ] ofAppEGLWindow: createSurface(): EGL_VERSION = 1.4
[notice ] ofAppEGLWindow: createSurface(): EGL_EXTENSIONS = EGL_KHR_image EGL_KHR_image_base EGL_KHR_image_pixmap EGL_KHR_vg_parent_image EGL_KHR_gl_texture_2D_image EGL_KHR_gl_texture_cubemap_image EGL_KHR_lock_surface
[notice ] ofAppEGLWindow: createSurface(): GL_RENDERER = VideoCore IV HW
[notice ] ofAppEGLWindow: createSurface(): GL_VERSION  = OpenGL ES-CM 1.1
[notice ] ofAppEGLWindow: createSurface(): GL_VENDOR   = Broadcom
[notice ] ofAppEGLWindow: createSurface(): -------------
[notice ] ofAppEGLWindow: setupPeripherals(): peripheral setup complete
[notice ] ofAppEGLWindow: setupNativeUDev(): created udev object
[notice ] ofAppEGLWindow: setupMouse(): mouse_fd= 5 devicePath=/dev/input/by-path/platform-3f980000.usb-usb-0:1.3:1.0-event-mouse
[notice ] ofAppEGLWindow: setupMouse(): mouse device name = 2.4G RF SoC Desktop Receiver
[notice ] ofAppEGLWindow: setupKeyboard(): keyboard_fd= 6 devicePath=/dev/input/by-path/platform-3f980000.usb-usb-0:1.2.2:1.0-event-kbd
[notice ] ofAppEGLWindow: setupKeyboard(): keyboard device name = Logitech Logitech BT Mini-Receiver
[notice ] ofAppEGLWindow: setupPeripherals(): native event setup complete
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
[notice ] ofSoundStream::listDevices:
[0] hw:bcm2835 ALSA,0 [in:0 out:2]
[1] hw:bcm2835 ALSA,1 [in:0 out:2]
[2] hw:Sound Blaster Play! 2,0 [in:2 out:2]
[3] default [in:2 out:2]

Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started

RtApiAlsa: dump hardware params just after device open:

ACCESS:  MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT:  S16_LE
SUBFORMAT:  STD
SAMPLE_BITS: 16
FRAME_BITS: 32
CHANNELS: 2
RATE: 44100
PERIOD_TIME: (1020 2972155)
PERIOD_SIZE: [45 131072]
PERIOD_BYTES: [180 524288]
PERIODS: [2 1024]
BUFFER_TIME: (2040 5944309)
BUFFER_SIZE: [90 262144]
BUFFER_BYTES: [360 1048576]
TICK_TIME: ALL

RtApiAlsa: dump hardware params after installation:

ACCESS:  RW_INTERLEAVED
FORMAT:  S16_LE
SUBFORMAT:  STD
SAMPLE_BITS: 16
FRAME_BITS: 32
CHANNELS: 2
RATE: 44100
PERIOD_TIME: (23219 23220)
PERIOD_SIZE: 1024
PERIOD_BYTES: 4096
PERIODS: 4
BUFFER_TIME: (92879 92880)
BUFFER_SIZE: 4096
BUFFER_BYTES: 16384
TICK_TIME: 0

RtApiAlsa: dump software params after installation:

tstamp_mode: NONE
period_step: 1
avail_min: 1024
start_threshold: 1024
stop_threshold: -1
silence_threshold: 0
silence_size: 1073741824
boundary: 1073741824
Segmentation fault
/home/pi/openFrameworks/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk:176: recipe for target 'RunRelease' failed
make: *** [RunRelease] Error 139

Any ideas?

Thanks

I don’t know if it’ll help but I’ve noticed putting in a scopedLock in the audioOut part solves a lot of random thread related issues for me…

I added an ofScopedLock at the audioOut but I still get the error. Here is the code:

void ofApp::audioOut(float * output, int bufferSize, int nChannels) {
	ofScopedLock waveformLock(waveformMutex);
	for (int n = 0; n < bufferSize; n++) {
		output[n*nChannels] = tsiks.play(1);
		output[n*nChannels + 1] = tsiks.play(1);
	}
}

Is that what you meant?

yes, but if that doesn’t work then I’m out of ideas - maybe it has something to do w/ the audio drivers on the Pi and I’m not very well versed in that.

This link might be worth a look: https://stackoverflow.com/questions/18769296/segmentation-fault-139-core-dumped-c-after-changing-operating-system

Looks like handling of large files on linux which cannot be determined at startup (?) or is beyond a certain limit can give rise to this error?