How to feed popupmenu with list of audio device

조회 수: 2 (최근 30일)
Zdrapko
Zdrapko 2014년 10월 16일
편집: Zdrapko 2014년 10월 17일
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에서 MATLAB Mobile에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by