Sound synthesis, problem when I add sounds, there is a snapping sound

2 views (last 30 days)
Hi,
I'm making a code which convert image to sound. I process the image to get different objexts and the I associate each object to a frequency according to its position in the image. Then, for each line of pixel's column, I create a sound and i add every sound of a column to make a chord that I call "accord" and then I concatenate every "accord" to make a music. My problem is that between to "accord" there is a sound which makes the music not smooth. I don't know how to do, not to have this sound, could you help me ?
Here is my program :
for i = 1 : 500 %number of column
accord = 0;
for e = 1 : nRowResized
if imageObjet(e,i) > 0
AmpSon = log(1000000+stats(imageObjet(e,i)).Area);
Duree = double(int16(noteObjet(imageObjet(e,i))))/(noteObjet(imageObjet(e,i)));
son = note(noteObjet(imageObjet(e,i)),Duree,AmpSon,6000); %freq, durée, amplitude, fe
else
son = note(0,1,5,6000); %freq, durée, amplitude, fe
end
if length(accord)>length(son)
son(numel(accord)) = 0;
end
if length(accord)<length(son)
accord(numel(son)) = 0;
end
accord = accord + son; % add every sound of a culumn to make a chord
end
musique = [musique accord]; %concatenate chords to make the music
end
  1 Comment
Mathieu NOE
Mathieu NOE on 11 May 2022
hello
maybe you should make sue that the "connection" between the last and next section (accord) is smoothed . there may be discontinuites. So apply a window that makes sure the data converge towards zero or make a kind of local smoothing of end / start sections

Sign in to comment.

Answers (1)

Milan Bansal
Milan Bansal on 29 Dec 2023
Hi Louis Vitaloni,
It is my understanding that you are trying to concatenate chords ("accords") to create some music but there is some unwanted noise between the two chords ("accord").
The unwanted sound between the chords could be due to abrupt changes in the waveform at the point where one chord ends and the next begins. This can create a popping or clicking noise.
A short crossfade between the end of one chord and the beginning of the next chord can be implemeted to smoothen the transition. Please apply fade out at the end of the already concatenated chord ("musique") and fade in at the beginning of the incoming chord before concatenating them. Please refer to the pseudo in code snippet below: -
fe = 5000 % sampling frequency. Please change this value as per requirement
fadeDuration = 0.05 % Please change this value as per requirement
fadeOut = linspace(1, 0, fe * fadeDuration);
fadeIn = linspace(0, 1, fe * fadeDuration);
% Multiply fadeOut and fadeIn to the end of "musique" and fadeIn to the "accord"
musique(end-length(fadeOut)+1:end) = musique(end-length(fadeOut)+1:end) .* fadeOut;
accord(1:length(fadeIn)) = accord(1:length(fadeIn)) .* fadeIn;
musique = [musique accord]; % Concatenate the chords
Hope it helps!

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!