Mercurial > hg > smallbox
comparison util/classes/@audio/audio.m @ 182:f8bc99a5470c danieleb
Added test for audio buffer function
author | Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk> |
---|---|
date | Mon, 09 Jan 2012 12:58:00 +0000 |
parents | 1495bdfa13e9 |
children |
comparison
equal
deleted
inserted
replaced
181:0dc98f1c60bb | 182:f8bc99a5470c |
---|---|
1 %% AUDIO OBJECT CLASS | |
2 % Class designed to analyse and process audio signals | |
3 %% | |
1 classdef audio | 4 classdef audio |
2 %% Audio object | 5 properties (SetAccess = protected) |
3 properties | 6 s %vector containing the audio signal |
4 s %vector containing the audio signal | 7 fs %sampling frequency |
5 S %matrix containing frames of audio for subsequent processing | 8 nBits %number of bits per sample |
6 fs %sampling frequency | 9 name %string containing the name of the audio file |
7 nBits %number of bits per sample | 10 format %string containing the format of the audio file |
8 name %string containing the name of the audio file | 11 bufferOperator %struct containing the parameters of the buffer operator |
9 format %string containing the format of the audio file | 12 S %matrix containing frames of audio |
10 bufferOperator %struct containing the parameters of the buffer operator (used by unbuffer to invert it) | |
11 end | 13 end |
12 | 14 |
13 methods | 15 methods |
14 %% Constructor | 16 %% Constructor |
15 function obj = audio(varargin) | 17 function obj = audio(varargin) |
18 %%% obj = audio(varargin) | |
19 % Audio object constructor. | |
20 % INPUT: either a path to an audio file, or the following | |
21 % arguments. | |
22 % - s: vector containing the audio samples | |
23 % - fs: sampling frequency | |
24 % - nBits: number of bits per sample | |
25 % - name: name of the audio object | |
26 % - format: format of the audio object | |
27 % | |
16 % if no arguments are specified, prompt for the choice of an | 28 % if no arguments are specified, prompt for the choice of an |
17 % audio file | 29 % audio file |
18 if ~nargin | 30 if ~nargin |
19 [fileName,pathname] = uigetfile({'*.wav; *.aiff;'},'Select an audio file'); | 31 [fileName,pathname] = uigetfile({'*.wav; *.aiff;'},'Select an audio file'); |
20 varargin{1} = strcat(pathname,filesep,fileName); | 32 varargin{1} = strcat(pathname,filesep,fileName); |
21 end | 33 end |
34 % if a file is specified, read it from disk | |
22 if ischar(varargin{1}) | 35 if ischar(varargin{1}) |
23 [~, obj.name obj.format] = fileparts(varargin{1}); | 36 [~, obj.name obj.format] = fileparts(varargin{1}); |
24 switch obj.format | 37 switch obj.format |
25 case '.wav' | 38 case '.wav' |
26 [obj.s obj.fs obj.nBits] = wavread(varargin{1}); | 39 [obj.s obj.fs obj.nBits] = wavread(varargin{1}); |
27 otherwise | 40 otherwise |
28 error('Unsupported audio format') | 41 error('Unsupported audio format') |
29 end | 42 end |
43 % if properties are specified, set them to input values | |
30 else | 44 else |
31 obj.s = varargin{1}; | 45 obj.s = varargin{1}; |
32 if nargin>1, obj.fs = varargin{2}; else obj.fs = []; end | 46 if nargin>1, obj.fs = varargin{2}; else obj.fs = []; end |
33 if nargin>2, obj.nBits = varargin{3}; else obj.nBits = []; end | 47 if nargin>2, obj.nBits = varargin{3}; else obj.nBits = []; end |
34 if nargin>3, obj.name = varargin{4}; else obj.name = []; end | 48 if nargin>3, obj.name = varargin{4}; else obj.name = []; end |