MATLAB Answers

How to change audio output device

조회 수: 62(최근 30일)
Jiajun Yang
Jiajun Yang 13 Sep 2018
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

로그인 to comment.

답변 수 (1)

Auralius Manurung
Auralius Manurung 5 Oct 2018
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

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by