Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inputFilePath = 'input.wav';
- outputFilePath = 'output_flanger.wav';
- maxBufferSize = 1000;
- minBufferSize = 200;
- modulationDepth = 0.5;
- flanger(inputFilePath, outputFilePath, maxBufferSize, minBufferSize, modulationDepth);
- function flanger(inputWavefile, outputWavefile, maxBufferSize, minBufferSize, modDepth)
- % Read the input wavefile
- [inputSignal, Fs] = audioread(inputWavefile);
- % Initialize circular buffer and other parameters
- circularBuffer = zeros(maxBufferSize, 2);
- bufferIndex = uint32(1);
- modFrequency = 0.25; % You can adjust this value
- % Prepare the output signal
- outputSignal = zeros(size(inputSignal));
- % Create time vector for plotting
- t = (0:length(inputSignal) - 1) / Fs;
- % Initialize plots
- figure;
- % Plot the input wave
- subplot(2, 1, 1);
- plot(t, inputSignal);
- title('Input Wave');
- xlabel('Time (s)');
- ylabel('Amplitude');
- % Apply flanger effect
- for n = 1:length(inputSignal)
- % Calculate delay time using modulation
- delayTime = minBufferSize + modDepth * sin(2 * pi * modFrequency * n / Fs);
- delaySamples = round(delayTime * Fs);
- % Circular buffer read
- readIndex = mod(bufferIndex - delaySamples - 1, maxBufferSize) + 1;
- delayedSample = mean(circularBuffer(readIndex, :));
- % Apply the flanger effect to the input sample
- outputSignal(n) = inputSignal(n) + delayedSample;
- % Circular buffer write
- circularBuffer(bufferIndex, :) = inputSignal(n, :);
- bufferIndex = mod(bufferIndex, maxBufferSize) + 1;
- end
- % Normalize the output signal to prevent clipping
- outputSignal = outputSignal / max(abs(outputSignal));
- % Plot the output wave
- subplot(2, 1, 2);
- plot(t, outputSignal);
- title('Output Wave (Flanger Effect)');
- xlabel('Time (s)');
- ylabel('Amplitude');
- % Save the output wave to a new file
- audiowrite(outputWavefile, outputSignal, Fs);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement