How to feed popupmenu with list of audio device

1 visualización (últimos 30 días)
Zdrapko
Zdrapko el 16 de Oct. de 2014
Editada: Zdrapko el 17 de Oct. de 2014
Hi all. I want to choose an audio device for dsp.AudioPlayer in GUI from popup menu. When i am using audiodevice command or dspAudioDeviceInfo it gives me names of devices like below
ans =
Podstawowy sterownik przechwytywania dźwięku (Windows DirectSound)
ans =
SoundMAX HD Audio (Windows DirectSound)
ans =
SB Live! 24-bit External (Windows DirectSound)
ans =
The problem is that dsp.AudioPlayer needs DeviceName without the part in the brackets. It needs name like
'SB Live! 24-bit External'
How can I make it?

Respuestas (1)

Geoff Hayes
Geoff Hayes el 17 de Oct. de 2014
Zdrapko - you could use strfind to determine where the first open bracket appears in the string, and then remove all that occurs from that index on. Something like
audioDeviceStr = 'SB Live! 24-bit External (Windows DirectSound)';
idx = strfind(audioDeviceStr,'(');
audioDeviceStr = strtrim(audioDeviceStr(1:idx-1));
Running the above will set the string to desired result
audioDeviceStr =
SB Live! 24-bit External
Note that it assumes that your audio device strings have only the one open bracket. If it is just the '(Windows DirectSound)' that you want to remove, then you could do something like
audioDeviceStr = 'SB Live! 24-bit External (Windows DirectSound)';
audioDeviceStr = strtrim(strrep(audioDeviceStr,'(Windows DirectSound)',''));
In the above, we replace the '(Windows DirectSound)' with an empty string.
  1 comentario
Zdrapko
Zdrapko el 17 de Oct. de 2014
Editada: Zdrapko el 17 de Oct. de 2014
Thanks for reply. I made sth like that. It's not depend only for '(Windows DirectSound)' string. I want to use it also with ASIO and in other PCs. I dont know if there will be some strings with brackets or not. Now I am checking if is a char '(' in the string and reamove all part wich is after this char. It looks like:
info = audiodevinfo;
j = length(info.output);
for i = 1:j
list{i} = info.output(i).Name;
end
set(handles.popup, 'String', list);
function popup_Callback(hObject, eventdata, handles)
devname = list{get(handles.popup, 'Value')};
i=1;
while (i <= length(devname))
if devname(i) == '('
k = i-2;
i = 1000;
else
k = i;
end
i = i+1;
end
devname = devname(1: k);
in.DeviceName = devname;
out.DeviceName = devname;
Thanks for all

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by