Advertisement
STANAANDREY

apd lab2 assig1

Sep 27th, 2023 (edited)
1,279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.74 KB | None | 0 0
  1. adjustVolume('input.wav', 6, 'output.wav')
  2.  
  3. function adjustVolume(inputFile, dBGain, outputFile)
  4.     if ~exist(inputFile, 'file')
  5.         error('Input file does not exist.');
  6.     end
  7.  
  8.     [audioIn, sampleRate] = audioread(inputFile);
  9.  
  10.     gainFactor = 10^(dBGain/20);
  11.  
  12.     audioOut = audioIn * gainFactor;
  13.  
  14.     audiowrite(outputFile, audioOut, sampleRate);
  15.  
  16.     t = (0:length(audioIn) - 1) / sampleRate;
  17.  
  18.     figure;
  19.    
  20.     subplot(2, 1, 1);
  21.     plot(t, audioIn);
  22.     title('Input Waveform');
  23.     xlabel('Time (s)');
  24.     ylabel('Amplitude');
  25.    
  26.     subplot(2, 1, 2);
  27.     plot(t, audioOut);
  28.     title('Output Waveform');
  29.     xlabel('Time (s)');
  30.     ylabel('Amplitude');
  31.    
  32.     disp('Volume adjustment complete.')
  33. end
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement