bastibe/PySoundCard

Couldn't get it to work on Mac OS X 10.9

Closed this issue · 7 comments

Any idea?

ValueError: right operand length must match slice length     
From callback <function callback_stub at 0x104752230>:     
Traceback (most recent call last):       
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PySoundCard-0.4.2-py2.7.egg/pysoundcard.py", line 426, in callback_stub         output_buffer[:] = output_data.flatten().tostring()

It seems that you are not returning the right number of frames from your callback. You must return exactly num_frames frames as well as either continue_flag or complete_flag or abort_flag.

I've exactly been using the callback playback example from your documentation

You must return a channels x frames matrix of data. How many channels does your sound card have? (Look at default_output_device() to check that).

I actually don't know how to do that in PySoundCard but in PyAudio the device_info gives me

{'defaultHighInputLatency': 0.1,
 'defaultHighOutputLatency': 0.013038548752834467,
 'defaultLowInputLatency': 0.01,
 'defaultLowOutputLatency': 0.0028798185941043084,
 'defaultSampleRate': 44100.0,
 'hostApi': 0L,
 'index': 5,
 'maxInputChannels': 12L,
 'maxOutputChannels': 14L,
 'name': u'Babyface (23368156)',
 'structVersion': 2L}

so it is 14 channels. But do I really have to fill that matrix with zeros then or could i just provide the number of channels? (afask portaudio itself let you specify the output channel configuration at least under ASIO or CoreAudio host API)

Just run the function default_output_device. This will return something very similar to the above code.

You really have to fill all the channels. However, you can tell portaudio to only use a smaller number of channels. You do that by creating the Stream with a specific device dict, where you modified the number of output channels.

In your example, this would be something like

default_device = default_output_device()
default_device['output_channels'] = 2 # or whatever you like
s = Stream(output_device=default_device) # also add your callback etc.

works smoothly! ;-) sorry for bothering.

No problem, glad I could help ;-)