How to programmatically manage a sound card?

I am new to audio drivers, so please come with me.

I play with pyaudioon a Mac using a Saffire Pro 40 sound card. I currently have two inputs connected and I want to programmatically control the levels of the second input channel. (This works great using sound card mixing control software).

I look through the documents pyaudio, but still have not found anything that could affect this problem. What is the easiest way to essentially make the mixing control software (volume control per channel) software? (Python API would be nice, but not essential)

To simplify: it seems like you can manually read the streams from the channels I want to control, scale them with numpy, they write them as output, but I hope there is a way to just send a normalized value to the channel to control it.

So instead:

stream1 = pyaudioInstance.open( format             = FORMAT,
                                channels           = CHANNELS,
                                rate               = RATE,
                                input              = True,
                                output             = True,
                                input_device_index = 0,
                                frames_per_buffer  = CHUNK
                                )
stream2 = pyaudioInstance.open( format             = FORMAT,
                                channels           = CHANNELS,
                                rate               = RATE,
                                input              = True,
                                input_device_index = 1,
                                frames_per_buffer  = CHUNK
                                )

while processingAudio:
    # manually fetch each channel
    data1In = stream1.read(CHUNK)
    data2In = stream2.read(CHUNK)
    # convert to numpy to easy scale the arrays
    decodeddata1 = numpy.fromstring(data1In, numpy.int16)
    decodeddata2 = numpy.fromstring(data2In, numpy.int16)
    newdata = (decodeddata1 * 0.5 + decodeddata2* 0.1).astype(numpy.int16)
    # finally write the processed data
    stream1.write(result.tostring())

This is a bit misleading, but I will need to mix separate channels from the same input device index. However, what I hope is something like:

someSoundCardAPI.channels[0].setVolume(0.2)

Taking a look at the Channel Maps Example , closer to what I need. At the moment, I have found that the part of the interface_ specific to host_api_specific is a bit confusing, and I was hoping that someone already had some experience using this successfully.

I am using OSX 10.10

+4
1

OSX, , AppleScript. ., , . , .

, ...

, python-sounddevice, () Python script:

import sounddevice as sd

def callback(indata, outdata, *stuff):
    outdata[:] = indata * [1, 0.5]

with sd.Stream(channels=2, callback=callback):
    input()

script , <Return>, .

+1

Source: https://habr.com/ru/post/1605709/


All Articles