Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- adjustVolume('input.wav', 6, 'output.wav')
- function adjustVolume(inputFile, dBGain, outputFile)
- if ~exist(inputFile, 'file')
- error('Input file does not exist.');
- end
- [audioIn, sampleRate] = audioread(inputFile);
- gainFactor = 10^(dBGain/20);
- audioOut = audioIn * gainFactor;
- audiowrite(outputFile, audioOut, sampleRate);
- t = (0:length(audioIn) - 1) / sampleRate;
- figure;
- subplot(2, 1, 1);
- plot(t, audioIn);
- title('Input Waveform');
- xlabel('Time (s)');
- ylabel('Amplitude');
- subplot(2, 1, 2);
- plot(t, audioOut);
- title('Output Waveform');
- xlabel('Time (s)');
- ylabel('Amplitude');
- disp('Volume adjustment complete.')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement