Problem with ofSoundStream

hi,
i made an app that uses the onboard sound card using the direcshow drivers in windows:

ofSoundStreamSettings settings;
	settings.setApi(ofSoundDevice::Api::MS_DS);
	auto devices = soundStream.getDeviceList(ofSoundDevice::Api::MS_DS);
	settings.setInDevice(devices[4]);
	settings.setInListener(this);
	settings.sampleRate = sampleRate;
	settings.bufferSize = bufferSize;
	settings.numBuffers = 2;
	settings.numInputChannels = 2;
	settings.numOutputChannels = 0;
	soundStream.setup(settings);

the problem is that sometimes i have to run it a few times till it open, the first few times it just crashes without giving any error, and i have no idea why it may be.
i don’t have this problem with all the api, but MS_DS is one of the few that make this (and i need to use this one in this app).
any idea what may be causing the problem?

thank you

after doing some more tests, the problem seems to happen when i have input channels, if there are no inputs it always runs fine.

Could be the device being opened by other application or your main system?
Try with numBuffers with 2x of the number of enabled channels (2 * 2inputs = 4); I have seen somewhere that seems recommended.

1 Like

i’ve tried increasing the number of buffers and i still have the same problem. in all the cases the device was only been used by oF…

… Sorry, I don’t know.

But maybe you can try to apply the settings like this:
ofSoundStreamSetup(settings);
(not using soundStream.setup(settings);)

Have you tried the OF sound examples? what OF version are you using?

You can check and verify too that you are selecting an input device here: [in:2 out:0]

[notice ] ofxSoundDevicesManager::logLine: [MS DirectShow: 0] Default Device [in:2 out:2] (default in) (default out)
[notice ] ofxSoundDevicesManager::logLine: [MS DirectShow: 1] VoiceMeeter Input (VB-Audio VoiceMeeter VAIO) [in:0 out:2]
[notice ] ofxSoundDevicesManager::logLine: [MS DirectShow: 2] CABLE Input (VB-Audio Virtual Cable) [in:0 out:2]
[notice ] ofxSoundDevicesManager::logLine: [MS DirectShow: 3] Speakers (Realtek(R) Audio) [in:0 out:2]
[notice ] ofxSoundDevicesManager::logLine: [MS DirectShow: 4] Panasonic-TV (NVIDIA High Definition Audio) [in:0 out:2]
[notice ] ofxSoundDevicesManager::logLine: [MS DirectShow: 5] VoiceMeeter Aux Input (VB-Audio VoiceMeeter AUX VAIO) [in:0 out:2]
[notice ] ofxSoundDevicesManager::logLine: [MS DirectShow: 6] VoiceMeeter Aux Output (VB-Audio VoiceMeeter AUX VAIO) [in:2 out:0]
[notice ] ofxSoundDevicesManager::logLine: [MS DirectShow: 7] VoiceMeeter Output (VB-Audio VoiceMeeter VAIO) [in:2 out:0]
[notice ] ofxSoundDevicesManager::logLine: [MS DirectShow: 8] CABLE Output (VB-Audio Virtual Cable) [in:2 out:0]
[notice ] ofxSoundDevicesManager::logLine: 

[notice ] ofxSoundDevicesManager::logLine: [MS WASAPI: 0] CABLE Input (VB-Audio Virtual Cable) [in:0 out:2]
[notice ] ofxSoundDevicesManager::logLine: [MS WASAPI: 1] Speakers (Realtek(R) Audio) [in:0 out:2]
[notice ] ofxSoundDevicesManager::logLine: [MS WASAPI: 2] VoiceMeeter Input (VB-Audio VoiceMeeter VAIO) [in:0 out:2] (default out)
[notice ] ofxSoundDevicesManager::logLine: [MS WASAPI: 3] Panasonic-TV (NVIDIA High Definition Audio) [in:0 out:2]
[notice ] ofxSoundDevicesManager::logLine: [MS WASAPI: 4] VoiceMeeter Aux Input (VB-Audio VoiceMeeter AUX VAIO) [in:0 out:2]
[notice ] ofxSoundDevicesManager::logLine: [MS WASAPI: 5] VoiceMeeter Output (VB-Audio VoiceMeeter VAIO) [in:2 out:0]
[notice ] ofxSoundDevicesManager::logLine: [MS WASAPI: 6] CABLE Output (VB-Audio Virtual Cable) [in:2 out:0]
[notice ] ofxSoundDevicesManager::logLine: [MS WASAPI: 7] VoiceMeeter Aux Output (VB-Audio VoiceMeeter AUX VAIO) [in:2 out:0] (default in)
1 Like

Same problem here… I am trying to run the audioInputExample on Windows 10, of_v0.11.0_vs2017, and I am getting the error:

RtAudio: no compiled support for specified API argument!

RtAudio: no compiled support for specified API argument!

RtAudio: no compiled support for specified API argument!

RtAudio: no compiled support for specified API argument!

RtAudio: no compiled support for specified API argument!

RtApiAsio::getDeviceInfo: error (Hardware input or output is not present or available.) initializing driver (ASIO Avid Driver).

RtAudio: no compiled support for specified API argument!

RtAudio: no compiled support for specified API argument!

RtAudio: no compiled support for specified API argument!

RtAudio: no compiled support for specified API argument!

RtAudio: no compiled support for specified API argument!

devices[0] = [MS ASIO: 0] ASIO Avid Driver [in:0 out:0]
devices[1] = [MS ASIO: 1] ASIO4ALL v2 [in:2 out:2]
devices[2] = [MS ASIO: 2] Realtek ASIO [in:2 out:2]

ofSoundPlayer is working properly, but I cant use the microphone…

I’ve tried chaging the API for MS_DS, MS_ASIO, MS_WSAPI, but none worked… From another topic I guess that install JACK won’t help, right?

My PC comes with Waves MaxxAudioPro, could this be the messy thing ?

This is the code that I am running:

	//ofSoundStreamSettings settings;
	settings.setApi(ofSoundDevice::Api::MS_ASIO);
	//auto devices = soundStream.getDeviceList();
	std::vector<ofSoundDevice> devices = soundStream.getDeviceList(ofSoundDevice::Api::MS_ASIO);
	settings.setInDevice(devices[2]);
	settings.setInListener(this);
	settings.bufferSize = bufferSize;
	settings.sampleRate = 44100;
	settings.numOutputChannels = 0;
	settings.numInputChannels = 2;
	ofSoundStreamSetup(settings);
	//soundStream.setup(settings);
	soundStream.printDeviceList();

	for (int i = 0; i < devices.size(); i++) {
		std::cout << "devices[" << ofToString(i) << "] = " << ofToString(devices[i]) << std::endl;
	}

hey @fmiramar,

I think that in ASIO4ALL GUI you need to select the desired channels to route as input/output.
Also, you can try to call the listing devices again (before or after) because maybe they changed (ie. after changing a sound API DS->ASIO). I mean to check if your device #2 is correct:
settings.setInDevice(devices[2]);

I have a “work in progress” addon that I made to make easy changing between devices and handle settings…etc with a GUI.
It could be easier for you to check all other devices, just in case the device’s id/number could not correlate with the listing, or to fast check if some other not expected device could work.

Hope it helps in some way.

set this to 2 channels

@moebiussurfing and @BabaNano thanks!

For a small period of time it worked, but trowing this error after closing the window:

Exception thrown at 0x00491F7A in audioInputExample_debug.exe: 0xC0000005: Access violation reading location 0xDDDDDDE9.

Now it has stopped completely and is not even compiling…

wkernelbase.pbd not loaded
Unhandled exception at 0x764944C2 in audioInputExample_debug.exe: Microsoft C++ exception: RtAudioError at memory location 0x0E0EFCD0.

Settings that worked, but no longer compiles :

settings.setApi(ofSoundDevice::Api::MS_WASAPI);
	std::vector<ofSoundDevice> devices = soundStream.getDeviceList(ofSoundDevice::Api::MS_WASAPI);
	settings.setInDevice(devices[1]);
	settings.setInListener(this);
	settings.bufferSize = bufferSize;
	settings.sampleRate = 44100;
	settings.numOutputChannels = 0;
	settings.numInputChannels = 2;
	ofSoundStreamSetup(settings);
	soundStream.printDeviceList();

Using MS_WASAPI and settings.setInDevice(devices[0]); (does not work but compiles) the console output is:


RtAudio: no compiled support for specified API argument!

RtAudio: no compiled support for specified API argument!

RtAudio: no compiled support for specified API argument!

devices[0] = [MS WASAPI: 0] Speakers/Headphones (Realtek(R) Audio) [in:0 out:2] (default out)
devices[1] = [MS WASAPI: 1] Microphone (Realtek(R) Audio) [in:2 out:0] (default in)

Changing things on my Windows 10 would be a solution ?

in ofApp.h add this function:
void exit();

and implemnt it at the end of your ccp with this line inside
void offApp::exit() {
ofSoundStreamClose();
}

Hello everyone and thanks for keep on the flame!
I’m having some troubles with this also, should be the ofSoundStream engine, settings or so, letme paste the outcome:

[notice ] ofGstVideoGrabber: Probing devices with udev…
[notice ] ofGstVideoGrabber: Found device 04f2:b43b, getting capabilities…
[notice ] ofGstVideoGrabber: detected v4l2 device: Chicony USB 2.0 Camera: Chicony
[notice ] ofGstVideoGrabber: driver: uvcvideo, version: 328759
[notice ] ofGstVideoGrabber: Capabilities: 0x84A00001
[notice ] ofGstVideoGrabber: Found device 04f2:b43b, getting capabilities…
[notice ] ofGstVideoGrabber: detected v4l2 device: Chicony USB 2.0 Camera: Chicony
[notice ] ofGstVideoGrabber: driver: uvcvideo, version: 328759
[notice ] ofGstVideoGrabber: Capabilities: 0x84A00001
[notice ] ofGstVideoGrabber: initGrabber(): selected device: Chicony USB 2.0 Camera: Chicony
[notice ] ofGstVideoGrabber: initGrabber(): selected format: 640x480 video/x-raw YUY2 framerate: 30/1
[notice ] ofGstUtils: setPipelineWithSink(): gstreamer pipeline: v4l2src name=video_source device=/dev/video0 ! video/x-raw,format=YUY2,width=640,height=480,framerate=30/1 ! videoconvert ! appsink name=ofappsink enable-last-sample=0 caps=“video/x-raw, format=RGB, width=640, height=480”
Cannot connect to server socket err = No existe el archivo o el directorio
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

RtApiAlsa::getDeviceInfo: snd_pcm_open error for device (hw:1,0), Dispositivo o recurso ocupado.

RtApiAlsa: dump hardware params just after device open:

ACCESS: MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT: S16_LE S32_LE IEC958_SUBFRAME_LE
SUBFORMAT: STD
SAMPLE_BITS: [16 32]
FRAME_BITS: [32 256]
CHANNELS: [2 8]
RATE: [32000 192000]
PERIOD_TIME: (20 256000]
PERIOD_SIZE: [4 8192]
PERIOD_BYTES: [128 262144]
PERIODS: [2 32]
BUFFER_TIME: (41 512000]
BUFFER_SIZE: [8 16384]
BUFFER_BYTES: [128 65536]
TICK_TIME: ALL

RtApiAlsa: dump hardware params after installation:

ACCESS: RW_INTERLEAVED
FORMAT: S32_LE
SUBFORMAT: STD
SAMPLE_BITS: 32
FRAME_BITS: 64
CHANNELS: 2
RATE: 44100
PERIOD_TIME: (11609 11610)
PERIOD_SIZE: 512
PERIOD_BYTES: 4096
PERIODS: 4
BUFFER_TIME: (46439 46440)
BUFFER_SIZE: 2048
BUFFER_BYTES: 16384
TICK_TIME: 0

RtApiAlsa: dump software params after installation:

tstamp_mode: NONE
tstamp_type: MONOTONIC
period_step: 1
avail_min: 512
start_threshold: 512
stop_threshold: -1
silence_threshold: 0
silence_size: 4611686018427387904
boundary: 4611686018427387904

After the code there is a circle that should go along with the frecuency, apparently the little circle shows and also the videograbber but I wouldn’t hear the sinusoid… its the part 1 of a project.
Some of the code has a videograbber that im using for a work project on media arts school, the finish project would have a videograbber (with no facetracker due to that 1 of the requisites is no using of addons in the project) with a mic, so it would works simple: you talk/yell and the program would register the amplitude setting the size of an object in the screen, that would fill the screen covering your image from the webcam. still I don’t think that the code block from the videograbber is doing anything, I bet it comes from linux and version of the Of that Im using (v0.11.0).
I got plenty of the code from a web tutorial in youtube that was upÄşoaded back in 2016, considering the speed of light its old (lol), you can check it on the following link:

I’ve had a similar problem on OSX. I don’t know if this solution applies for you:

The new Macbooks seem to stream only ONE microphone input to openframeworks. So, two steps are necessary:

In setup():

  1. set proper inDevice with settings.setInDevice(devices[0]);
  2. set only one inputChannel with settings.numInputChannels = 1;

In your audioIn() function:
when accessing your input buffer (ofSoundBuffer & input) instead of using this:

        left[i]        = input[i*2];
        right[i]     = input[i*2+1];

use only:

        left[i]		= input[i];

Solved it for me. This seems obvious in hindsight. For some reason, at least in the OSX branch of OF, it is possible to call ofSoundBuffer frames that are greater than the number of frames in the ofSoundBuffer. This probably accesses memory that’s allocated to something else (?), resulting in wildly inappropriate/unexpected values. Doing so throws no error in this case.
I am not sure why… Is that a design choice or a bug?