Mercurial > hg > smallbox
comparison util/classes/@audio/audio.m @ 160:e3035d45d014 danieleb
Added support classes
author | Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk> |
---|---|
date | Wed, 31 Aug 2011 10:53:10 +0100 |
parents | |
children | 1495bdfa13e9 |
comparison
equal
deleted
inserted
replaced
159:23763c5fbda5 | 160:e3035d45d014 |
---|---|
1 classdef audio | |
2 %% Audio object | |
3 properties | |
4 s %vector containing the audio signal | |
5 fs %sampling frequency | |
6 nBits % number of bits per sample | |
7 name % string containing the name of the audio file | |
8 format % string containing the format of the audio file | |
9 end | |
10 | |
11 methods | |
12 %% Constructor | |
13 function obj = audio(varargin) | |
14 error(nargchk(1,5,nargin)); | |
15 if ischar(varargin{1}) | |
16 [~, obj.name obj.format] = fileparts(varargin{1}); | |
17 switch obj.format | |
18 case '.wav' | |
19 [obj.s obj.fs obj.nBits] = wavread(varargin{1}); | |
20 otherwise | |
21 error('Unsupported audio format') | |
22 end | |
23 else | |
24 obj.s = varargin{1}; | |
25 if nargin>1, obj.fs = varargin{2}; else obj.fs = []; end | |
26 if nargin>2, obj.nBits = varargin{3}; else obj.nBits = []; end | |
27 if nargin>3, obj.name = varargin{4}; else obj.name = []; end | |
28 if nargin>4, obj.format = varargin{5}; else obj.format = []; end | |
29 end | |
30 end | |
31 | |
32 %% Playback functions | |
33 function player = play(obj, player) | |
34 if ~exist('player','var') || isempty(player) | |
35 player = audioplayer(obj.s,obj.fs); | |
36 end | |
37 play(player); | |
38 end | |
39 | |
40 function player = stop(obj, player) | |
41 if ~exist('player','var') || isempty(player) | |
42 player = audioplayer(obj.s,obj.fs); | |
43 end | |
44 stop(player) | |
45 end | |
46 | |
47 function player = pause(obj, player) | |
48 if ~exist('player','var') || isempty(player) | |
49 player = audioplayer(obj.s,obj.fs); | |
50 end | |
51 pause(player) | |
52 end | |
53 end | |
54 end |