0% found this document useful (0 votes)
21 views2 pages

LL

Uploaded by

lyes Ou
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

LL

Uploaded by

lyes Ou
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

[y,Fs]=audioread('C:\Users\hp\Desktop\ramy\sunday.

wav');
sound(y,Fs);
plot(y);

% Load audio signals


[signal1, Fs1] = audioread('C:\Users\hp\Desktop\ramy\sunday.wav');
[signal2, Fs2] = audioread('C:\Users\hp\Desktop\ramy\lyes.wav');

% Ensure both signals have the same sampling frequency


Fs = min(Fs1, Fs2);

% Resample signals if needed


signal1 = resample(signal1, Fs, Fs1);
signal2 = resample(signal2, Fs, Fs2);

% Make signals of equal length


minLength = min(length(signal1), length(signal2));
signal1 = signal1(1:minLength);
signal2 = signal2(1:minLength);

% Adjust signal amplitudes


amplitudeFactor1 = 0.9;
amplitudeFactor2 = 0.6;
signal1 = amplitudeFactor1 * signal1;
signal2 = amplitudeFactor2 * signal2;

% Mix the signals


mixedSignal = signal1 + signal2;

% Play the mixed signal


sound(mixedSignal, Fs);

% Save the mixed signal to a new audio file


audiowrite('C:\Users\hp\Desktop\ramy\mixed_audio.wav', mixedSignal, Fs);

try
% Load the audio signal
[signal, Fs] = audioread('C:\Users\hp\Desktop\ramy\sunday.wav');

% Define the start and end indices of the segment you want to keep
start_index = 1; % Start from the beginning
end_index = floor(length(signal)/2); % End at half of the signal length

% Cut the signal


cut_signal = signal(start_index:end_index);

% Play the cut signal


sound(cut_signal, Fs);

% Optionally, save the cut signal to a new audio file


audiowrite('C:\Users\hp\Desktop\ramy\cut_audio.wav', cut_signal, Fs);

disp('Audio successfully cut and saved.');


catch
disp('Error: Unable to read or process the audio file.');
end

% Define the frequencies for notes (in Hz)


C = 261.63; % C note
D = 293.66; % D note
E = 329.63; % E note
F = 349.23; % F note
G = 392.00; % G note
A = 440.00; % A note
B = 493.88; % B note

% Define the duration of each note (in seconds)


duration = 0.5; % half second for each note

% Create the melody by concatenating notes


melody = [E, D, C, D, E, E, E, D, D, D, E, E, E, E, D, D, E, D, C, D, E, E, E];

% Generate the audio signal for the melody


fs = 44100; % Sampling frequency (samples per second)
t = 0:1/fs:duration; % Time vector for one note
audio_signal = zeros(1, length(t) * length(melody)); % Preallocate audio signal
array

% Generate audio signal for the melody


idx = 1; % Index to keep track of the position in audio_signal
for i = 1:length(melody)
note_frequency = melody(i);
note_sound = sin(2*pi*note_frequency*t);
audio_signal(idx:idx+length(note_sound)-1) = note_sound;
idx = idx + length(note_sound);
end

% Play the melody


sound(audio_signal, fs);

You might also like