필터 지우기
필터 지우기

Save stereo audio file

조회 수: 9 (최근 30일)
An
An 2024년 2월 6일
댓글: Star Strider 2024년 2월 6일
When using
player = audioplayer(y, fs);
This sounds stereo, as intended:
play(player) % sound stereo OK
But after saving a file to disk, stereo seems to be lost and both channels mixed:
audiowrite(filename, y, fs);
Is there anyway to overcome time?
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 2월 6일
audiowrite(filename, y, fs); should be okay provided that y has 2 columns.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2024년 2월 6일
Testing those functions, they both appear to be working correctly —
Fs1 = 44100;
L1 = 2;
t1 = linspace(0, L1*Fs1, L1*Fs1+1).'/Fs1; % Column Vector
s = [sin(2*pi*t1*1E+3) sin(2*pi*t1*2E+3)]; % Sound
audiowrite('Test.wav', s, Fs1)
[y, Fs2] = audioread('Test.wav');
t2 = linspace(0, size(y,1)-1, size(y,1)).'/Fs2;
figure
tiledlayout(2,1)
nexttile
plot(t1, s(:,1), '-', 'LineWidth',2)
hold on
plot(t2, y(:,1), '--', 'LineWidth',2)
hold off
grid
xlim([1 1.1]*1E-2)
title('Left Channel')
nexttile
plot(t1, s(:,2), '-', 'LineWidth',2)
hold on
plot(t2, y(:,2), '--', 'LineWidth',2)
hold off
grid
xlim([1 1.1]*1E-2)
title('Right Channel')
It might be appropriate to check to be certain that your audiocard drivers are up-to-date and that your audiocard is working correctly. You can use this code to check it.
.
  댓글 수: 2
An
An 2024년 2월 6일
편집: An 2024년 2월 6일
You are right; I must have been doing something wrong. Worked fine.
Simplified your code a bit and Tested stereo sound with:
% testwav
Fs = 44100; % sample frequency (points per second)
duration = 5; %seconds
t = linspace(0, duration, duration*Fs)'; % Column Vector
f1 = 440; % frequency 1
f2 = 442; % frequency 2
s1 = sin(2*pi*t*f1);
s2 = sin(2*pi*t*f2);
nil = zeros(size(s1));
% build test: left ear, right ear, both ears
% generating a 2Hz binaural beat in the last 5s of audio
ba = [
s1 nil;
nil s2;
s1 s2;
];
audiowrite('Test.wav', ba, Fs)
Star Strider
Star Strider 2024년 2월 6일
Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by