Mercurial > hg > smallbox
annotate 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 |
rev | line source |
---|---|
daniele@160 | 1 classdef audio |
daniele@160 | 2 %% Audio object |
daniele@160 | 3 properties |
daniele@160 | 4 s %vector containing the audio signal |
daniele@160 | 5 fs %sampling frequency |
daniele@160 | 6 nBits % number of bits per sample |
daniele@160 | 7 name % string containing the name of the audio file |
daniele@160 | 8 format % string containing the format of the audio file |
daniele@160 | 9 end |
daniele@160 | 10 |
daniele@160 | 11 methods |
daniele@160 | 12 %% Constructor |
daniele@160 | 13 function obj = audio(varargin) |
daniele@160 | 14 error(nargchk(1,5,nargin)); |
daniele@160 | 15 if ischar(varargin{1}) |
daniele@160 | 16 [~, obj.name obj.format] = fileparts(varargin{1}); |
daniele@160 | 17 switch obj.format |
daniele@160 | 18 case '.wav' |
daniele@160 | 19 [obj.s obj.fs obj.nBits] = wavread(varargin{1}); |
daniele@160 | 20 otherwise |
daniele@160 | 21 error('Unsupported audio format') |
daniele@160 | 22 end |
daniele@160 | 23 else |
daniele@160 | 24 obj.s = varargin{1}; |
daniele@160 | 25 if nargin>1, obj.fs = varargin{2}; else obj.fs = []; end |
daniele@160 | 26 if nargin>2, obj.nBits = varargin{3}; else obj.nBits = []; end |
daniele@160 | 27 if nargin>3, obj.name = varargin{4}; else obj.name = []; end |
daniele@160 | 28 if nargin>4, obj.format = varargin{5}; else obj.format = []; end |
daniele@160 | 29 end |
daniele@160 | 30 end |
daniele@160 | 31 |
daniele@160 | 32 %% Playback functions |
daniele@160 | 33 function player = play(obj, player) |
daniele@160 | 34 if ~exist('player','var') || isempty(player) |
daniele@160 | 35 player = audioplayer(obj.s,obj.fs); |
daniele@160 | 36 end |
daniele@160 | 37 play(player); |
daniele@160 | 38 end |
daniele@160 | 39 |
daniele@160 | 40 function player = stop(obj, player) |
daniele@160 | 41 if ~exist('player','var') || isempty(player) |
daniele@160 | 42 player = audioplayer(obj.s,obj.fs); |
daniele@160 | 43 end |
daniele@160 | 44 stop(player) |
daniele@160 | 45 end |
daniele@160 | 46 |
daniele@160 | 47 function player = pause(obj, player) |
daniele@160 | 48 if ~exist('player','var') || isempty(player) |
daniele@160 | 49 player = audioplayer(obj.s,obj.fs); |
daniele@160 | 50 end |
daniele@160 | 51 pause(player) |
daniele@160 | 52 end |
daniele@160 | 53 end |
daniele@160 | 54 end |