Effacer les filtres
Effacer les filtres

Save stereo audio file

10 vues (au cours des 30 derniers jours)
An
An le 6 Fév 2024
Commenté : Star Strider le 6 Fév 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 commentaire
Walter Roberson
Walter Roberson le 6 Fév 2024
audiowrite(filename, y, fs); should be okay provided that y has 2 columns.

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 6 Fév 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 commentaires
An
An le 6 Fév 2024
Modifié(e) : An le 6 Fév 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 le 6 Fév 2024
Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Audio I/O and Waveform Generation dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by