edit .mat values to match
1 回表示 (過去 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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1546017/image.png)
And I need it to look like this .mat file (A sample that works with my given code found online).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1546022/image.png)
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 and Video Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!