Advertisement
STANAANDREY

apd lab2 assig2

Sep 27th, 2023
1,232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.96 KB | None | 0 0
  1. function modifyVocalVolume(inputFilePath, dBValue, outputFilePath)
  2.     [inputSignal, sampleRate] = audioread(inputFilePath);
  3.     leftChannel = inputSignal(:, 1);
  4.     rightChannel = inputSignal(:, 2);
  5.     scalingFactor = 10^(dBValue/20);
  6.     modifiedLeftChannel = leftChannel * scalingFactor;
  7.     modifiedRightChannel = rightChannel * scalingFactor;
  8.     outputSignal = [modifiedLeftChannel, modifiedRightChannel];
  9.     audiowrite(outputFilePath, outputSignal, sampleRate);
  10.     t = (0:length(inputSignal)-1) / sampleRate;
  11.  
  12.     figure;
  13.  
  14.     subplot(2, 1, 1);
  15.     plot(t, leftChannel, 'b', t, rightChannel, 'r');
  16.     title('Input Vocals');
  17.     xlabel('Time (s)');
  18.     ylabel('Amplitude');
  19.     legend('Left Channel', 'Right Channel');
  20.    
  21.     subplot(2, 1, 2);
  22.     plot(t, modifiedLeftChannel, 'b', t, modifiedRightChannel, 'r');
  23.     title('Output Vocals');
  24.     xlabel('Time (s)');
  25.     ylabel('Amplitude');
  26.     legend('Left Channel', 'Right Channel');
  27. end
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement