I would like to write a function which takes an audio file address as input, and then make some changes to that audio file and play it.
I am new to Octave and by looking the documentation I came up with the code below
function main
% clear screen
clear;
clc;
audio_src_address = 'introduction.wav';
NegateAudioPhase(audio_src_address);
endfunction;
function NegateAudioPhase (audio_src_address)
% load audio source
[y, fs] = audioread(audio_src_address);
% use chanel 1
y = y(:,1);
% audio frequency domain
f = fft(y);
m = abs(f);
p = angle(f);
% negate audio source phase
p = -p;
% calculate new fourier transform
f = m .* exp(j*p);
% create the new audio source
y2 = ifft(f);
% play audio sound
player = audioplayer(y2, fs);
play(player);
endfunction
I have put this code in main.m
file.
I use Octave CLI to run the code by typing main
and pressing enter.
code will be run until the end but no audio is played. there is a warning at the command line after the execution:
warning: Octave:audio-interrupt
warning: called from
main>NegateAudioPhase at line 33 column 1
main at line 6 column 5
I have put all the code in an other file without defining any functions and it worked as expected.
endfunction
which is at the end of the file. – Farbod Shahinfar