How can I add new audio devices after I have already created an object in the Audio System Toolbox?

4 visualizaciones (últimos 30 días)
Sometimes when I am using the Audio System Toolbox, I need to add a device midway through a session of MATLAB, but when I add the new device I can't get MATLAB to recognize it even though my computer says that it is connected. So far, the only way I have been able to get the new device recognized is to restart MATLAB, which is not ideal. See the following code for an example:
>> deviceReader = audioDeviceReader;
>> devices = getAudioDevices(deviceReader); % shows 4 devices
>> % Connect new device
>> clear
>> deviceReader = audioDeviceReader;
>> devices = getAudioDevices(deviceReader); % still shows 4 even though 5 are connected
Is there a way that I can get MATLAB to recognize new devices without having to restart?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 12 de Nov. de 2019
The device information is stored in memory in the same way a MEX file would be, so if you want to add new devices you first need to clear that information from MATLAB's memory. The following example code should allow you to add new devices without restarting MATLAB:
>> deviceReader = audioDeviceReader;
>> devices = getAudioDevices(deviceReader); % shows 4 devices
>> % Add new device
>> clear deviceReader dspAudioDeviceInfo
>> deviceReader = audioDeviceReader;
>> devices = getAudioDevices(deviceReader); % shows 5 devices
Note that you could also accomplish this using the "clear mex" command instead of specifically clearing "dspAudioDeviceInfo".
You can check if "dspAudioDeviceInfo" is currently saved in memory using the following command:
>> [~,X] = inmem

Más respuestas (0)

Categorías

Más información sobre Audio I/O and Waveform Generation en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by