daniele@160
|
1 classdef audio
|
daniele@166
|
2 %% Audio object
|
daniele@166
|
3 properties
|
daniele@166
|
4 s %vector containing the audio signal
|
daniele@166
|
5 S %matrix containing frames of audio for subsequent processing
|
daniele@166
|
6 fs %sampling frequency
|
daniele@166
|
7 nBits %number of bits per sample
|
daniele@166
|
8 name %string containing the name of the audio file
|
daniele@166
|
9 format %string containing the format of the audio file
|
daniele@166
|
10 bufferOperator %struct containing the parameters of the buffer operator (used by unbuffer to invert it)
|
daniele@166
|
11 end
|
daniele@166
|
12
|
daniele@166
|
13 methods
|
daniele@166
|
14 %% Constructor
|
daniele@166
|
15 function obj = audio(varargin)
|
daniele@166
|
16 % if no arguments are specified, prompt for the choice of an
|
daniele@166
|
17 % audio file
|
daniele@166
|
18 if ~nargin
|
daniele@166
|
19 [fileName,pathname] = uigetfile({'*.wav; *.aiff;'},'Select an audio file');
|
daniele@166
|
20 varargin{1} = strcat(pathname,filesep,fileName);
|
daniele@166
|
21 end
|
daniele@166
|
22 if ischar(varargin{1})
|
daniele@166
|
23 [~, obj.name obj.format] = fileparts(varargin{1});
|
daniele@166
|
24 switch obj.format
|
daniele@166
|
25 case '.wav'
|
daniele@166
|
26 [obj.s obj.fs obj.nBits] = wavread(varargin{1});
|
daniele@166
|
27 otherwise
|
daniele@166
|
28 error('Unsupported audio format')
|
daniele@166
|
29 end
|
daniele@166
|
30 else
|
daniele@166
|
31 obj.s = varargin{1};
|
daniele@166
|
32 if nargin>1, obj.fs = varargin{2}; else obj.fs = []; end
|
daniele@166
|
33 if nargin>2, obj.nBits = varargin{3}; else obj.nBits = []; end
|
daniele@166
|
34 if nargin>3, obj.name = varargin{4}; else obj.name = []; end
|
daniele@166
|
35 if nargin>4, obj.format = varargin{5}; else obj.format = []; end
|
daniele@166
|
36 end
|
daniele@166
|
37 obj.S = [];
|
daniele@166
|
38 obj.bufferOperator = [];
|
daniele@166
|
39 end
|
daniele@166
|
40
|
daniele@166
|
41 %% Playback functions
|
daniele@166
|
42 function player = play(obj, player)
|
daniele@166
|
43 if ~exist('player','var') || isempty(player)
|
daniele@166
|
44 player = audioplayer(obj.s,obj.fs);
|
daniele@166
|
45 end
|
daniele@166
|
46 play(player);
|
daniele@166
|
47 end
|
daniele@166
|
48
|
daniele@166
|
49 function player = stop(obj, player)
|
daniele@166
|
50 if ~exist('player','var') || isempty(player)
|
daniele@166
|
51 player = audioplayer(obj.s,obj.fs);
|
daniele@166
|
52 end
|
daniele@166
|
53 stop(player)
|
daniele@166
|
54 end
|
daniele@166
|
55
|
daniele@166
|
56 function player = pause(obj, player)
|
daniele@166
|
57 if ~exist('player','var') || isempty(player)
|
daniele@166
|
58 player = audioplayer(obj.s,obj.fs);
|
daniele@166
|
59 end
|
daniele@166
|
60 pause(player)
|
daniele@166
|
61 end
|
daniele@166
|
62 end
|
daniele@160
|
63 end
|