How to change audio output device
조회 수: 64 (최근 30일)
이전 댓글 표시
I want to be able to specify which audio output the sound to be played. Using audioDeviceWriter I am able to get the device info, but I don't know how I can change the output to a specific device. I try .Device(index) but that doesn't work. Please help.
fs = 44100;
T = 1/fs;
t = [0:T:2];
f1 = 250;
omega1 = 2*pi*f1;
phi = 2*pi *0.75;
x1 = cos(omega1*t +phi);
deviceWriter = audioDeviceWriter(fs);
devices = getAudioDevices(deviceWriter);
% I wish to change the audio device here between built-in and my sound card.
deviceWriter.Device(3)
sound(0.9*x1, fs)
댓글 수: 0
답변 (1개)
Auralius Manurung
2018년 10월 5일
deviceWriter is more complex to use as it plays only one frame. It means you have to use it in a loop. You also don't need the code in the last line. Rather then using deviceWriter, why not using audioPlayer?
fs = 44100;
T = 1/fs;
t = [0:T:1];
f1 = 250;
omega1 = 2*pi*f1;
phi = 2*pi *0.75;
x1 = cos(omega1*t +phi)';
info = audiodevinfo
player = audioplayer(0.9*x1, fs, 16, 3);
play(player);
You can explore the info.output variable to see the list of detected hardware.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!