Processing audio files that are browsed from a computer directory

1 view (last 30 days)
I want to do watermarking to an audio that is browsed via the 'Browse' button.
Here is my code to browse audio files from my computer:
% button to browse audio file from computer directory
[filename, pathname] = uigetfile ({'*. wav'}, 'Select File');
fullpathname = strcat (pathname, filename);
[data] = audioread (fullpathname);
plot (data);
and on another button, namely the 'Embedding' button, which will embed the watermark for the audio that has been browsed.
Here's my code:
audioFile = char (strcat (pathname, filename));
[data, Fs] = audioread (audioFile);
sr = 44100; % sampling rate
w = 512; % window size
T = w / sr; % period
t = linspace (0, 1, 44100);
twindow = t (1: 512);
hamming = 0.54 - 0.46 * cos ((2 * pi * twindow) / T);
plot (hamming);
But I get an error when I want to process the audio file that has been browsed. I hope someone can help me.

Accepted Answer

Walter Roberson
Walter Roberson on 20 Mar 2021
Edited: Walter Roberson on 20 Mar 2021
[filename, pathname] = uigetfile ({'*. wav'}, 'Select File');
fullpathname = strcat (pathname, filename);
Do not use strcat() between directories and file like that. uigetfile() does not promise that it will leave a directory separator at the end of the pathname . Use fullfile() instead. Also, check to see whether the user cancelled
if ~ischar(filename)
return; %user cancel
fullpathname = fullfile(pathname, filename);
Walter Roberson
Walter Roberson on 21 Mar 2021
audioFile = fullfile(pathname, filename);
[data,sr] = audioread(audioFile);
w = 512; %window size
T = w/sr; %period
% t is an array of times at which the hamming function is evaluated
twindow = (0:w-1)/sr;
hamming = 0.54 - 0.46 * cos((2 * pi * twindow)/T);
To get any further than this, you will need to show me the error message instead of just saying that some error is occurring.
and this the code for button "Embed"
Where are you getting pathname and filename for that button? You do not have a uigetfile() call in that button. Are you assuming that just because you assigned to pathname and filename in some other function that the variables will be defined here? They will not be: each function has its own workspace and that workspace disappears when the function returns.

Sign in to comment.

More Answers (0)


Find more on Simulation, Tuning, and Visualization in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!