How to feed popupmenu with list of audio device

2 次查看(过去 30 天)
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?

回答(1 个)

Geoff Hayes
Geoff Hayes 2014-10-17
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 个评论
Zdrapko
Zdrapko 2014-10-17
编辑:Zdrapko 2014-10-17
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by