edit .mat values to match
3 次查看(过去 30 天)
显示 更早的评论
I currently have this code below:
clc
clear
clear all
[data,fs]=audioread('pracsound.mp3');
save new_file data fs
new_file = new_file';
% Load sample sound
load new_file.mat;
% Play sample sound
sound(data, fs);
% Wait 5 seconds
pause(5)
% Call the function to add echo
y_echo = echo_gen(data, fs, 0.5, 0.75);
% Play echo sound
sound(y_echo, fs);
function output=echo_gen(input, fs, delay, amp)
% Preallocate new vector
output=zeros((numel(input)+delay*fs),1);
% Add zeros to input to get both vectors same length
input = [input; zeros(delay*fs,1)];
% No change during the delay time
output(1:delay*fs) = input(1:delay*fs);
% Add Echo to the remaining part
output(delay*fs+1:end)= input(1:end-delay*fs)*amp + input(delay*fs+1:end);
% Normalize between -1 and 1
output = rescale(output,-1,1);
end
It is supposed to load an .mat audio file play the original, add an echo using a function then play it again.
My problem is the .mat file I want to use appears like this once loaded in:
And I need it to look like this .mat file (A sample that works with my given code found online).
How do I get the data value for new_file to be 246000x1 double like the TestSoundEcho.mat file instead of 246000x2?
0 个评论
回答(2 个)
Fangjun Jiang
2023-11-21
According to "doc audioread",
Audio data in the file, returned as an m-by-n matrix, where m is the number of audio samples read and n is the number of audio channels in the file.
So it was dependent on the contents of the .mp3 file.
You could to this after audioread() to select only one channel
[data,fs]=audioread('pracsound.mp3');
data=data(:,1);
1 个评论
Walter Roberson
2023-11-21
Some people prefer
data = mean(data,2);
to merge all of the channels into a single channel.
For example especially in the 1960's, it was very common in pop and rock music to have one channel (ear) be the vocals, and the other channel (ear) be the music; if you were to just extract one channel from such a recording you would get only the music or only the vocals.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!