Experts, please help me to fix the below errors: Warning: Data clipped when writing file. > In audiowrite>clipInputData (line 474) In audiowrite (line 245) In ass1 (line 48)

6 Ansichten (letzte 30 Tage)
% Define drum sounds
fs = 44100; % Sampling rate
durations = [0.1, 0.05, 0.1, 0.25, 0.2, 0.3]; % Duration of each sound (in seconds)
openHihat = sin(2*pi*800*(0:(1/fs):durations(1)));
closedHihat = sin(2*pi*1200*(0:(1/fs):durations(2)));
snareDrum = sin(2*pi*400*(0:(1/fs):durations(3))) + 0.5*sin(2*pi*1200*(0:(1/fs):durations(3)));
bassDrum = sin(2*pi*60*(0:(1/fs):durations(4)));
tomToms = sin(2*pi*300*(0:(1/fs):durations(5))) + sin(2*pi*500*(0:(1/fs):durations(5))) + sin(2*pi*700*(0:(1/fs):durations(5)));
cymbals = sin(2*pi*1000*(0:(1/fs):durations(6))) + sin(2*pi*1500*(0:(1/fs):durations(6))) + sin(2*pi*2000*(0:(1/fs):durations(6)));
% Define drum table
drumTable = [
0 1 1 1 0 0 0 1 1;
0 0 0 1 0 1 1 0 1;
0 1 0 1 1 0 0 1 1;
1 1 1 1 1 0 0 0 1;
0 0 0 1 0 1 1 0 1;
0 0 0 1 0 1 1 0 1;
];
% Play drum sounds according to drum table
output = zeros(1, size(drumTable, 2)*fs);
for i = 1:size(drumTable, 2)
for j = 1:size(drumTable, 1)
if drumTable(j,i) == 1
switch j
case 1 % Open hihat
sound = openHihat;
case 2 % Closed hihat
sound = closedHihat;
case 3 % Snare drum
sound = snareDrum;
case 4 % Bass drum
sound = bassDrum;
case 5 % Tom toms
sound = tomToms;
case 6 % Cymbals
sound = cymbals;
end
startIndex = (i-1)*fs+1;
endIndex = startIndex+length(sound)-1;
output(startIndex:endIndex) = output(startIndex:endIndex) + sound;
end
end
end
% Save output to wave file
audiowrite('drum_output.wav', output, fs);

Antworten (1)

Walter Roberson
Walter Roberson am 6 Apr. 2023
Your 4th column of drumtable has 6 non-zero entries, one for each instrument. So in your 4th stretch you are adding together snippits of 6 different sounds. Each sound is a sine wave, range -1 to +1. Therefore the 4th section of the output will contain entries that potentially range from 6*(-1) to 6*(+1) . (It is even worse than that because some of your sections are themselves the sum of multiple sine waves.)
However, audiowrite() can only handle values between -1 and +1. It is going to truncate anything outside that range.
Question for you: if you have the tom-toms going on a beat, and then you introduce the snare drum, then how loud should the result be? Should you be setting the range of each sound to be 1/6th of maximum value, so that only in the case that all 6 are playing together do you get maximum volume, but the volume of each individual instrument will stay consistent no matter what else is playing? Or when you add snare to tom-toms should the snare and tom-toms each be reduced to half volume so that their sum becomes -1 to +1? More generally, at each point should the loudness of each instrument be reduced according to the number of other instruments playing simultaneously, the mean() of the signals of each of the instruments playing? So any particular instrument keeps changing in volume as you go, depending what else is happening?

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by