Save stereo audio file

24 Ansichten (letzte 30 Tage)
An
An am 6 Feb. 2024
Kommentiert: Star Strider am 6 Feb. 2024
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 Kommentar
Walter Roberson
Walter Roberson am 6 Feb. 2024
audiowrite(filename, y, fs); should be okay provided that y has 2 columns.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 6 Feb. 2024
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 Kommentare
An
An am 6 Feb. 2024
Bearbeitet: An am 6 Feb. 2024
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 am 6 Feb. 2024
Thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by