File: psychwavwrite.m

package info (click to toggle)
psychtoolbox-3 3.0.17.9.dfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 84,408 kB
  • sloc: ansic: 171,572; cpp: 20,885; objc: 5,164; sh: 1,878; python: 1,366; php: 384; makefile: 193; java: 113
file content (40 lines) | stat: -rw-r--r-- 1,166 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function psychwavwrite(varargin)
% psychwavwrite - Replacement for wavwrite().
%
% Replaces the Matlab wavwrite() function, which was removed
% in Matlab R2015b, by the audiowrite() function, which was
% introduced in R2012b, to provide basic sanity to the mess
% that is Matlab's way of (not) dealing with "backwards
% compatibility".
%
% This is a least common denominator implementation of
% what both wavwrite() and audiowrite() support in a
% compatible fashion. See the help of either one for
% details.
%
% Usage:
%
%  wavwrite(y,filename)
%  wavwrite(y,Fs,filename)
%  wavwrite(y,Fs,N,filename)

% History:
% 02-Feb-2016 mk  Created.

if exist('audioread')
  if length(varargin) < 2
    error('Invalid call to psychwavwrite(). Must provide at least y and filename.');
  end

  if length(varargin) == 2
    audiowrite(varargin{2}, varargin{1}, 8000);
  elseif length(varargin) == 3
    audiowrite(varargin{3}, varargin{1}, varargin{2});
  elseif length(varargin) == 4
    audiowrite(varargin{4}, varargin{1}, varargin{2}, 'BitsPerSample', varargin{3});
  else
    error('Too many input arguments to psychwavwrite().');
  end
else
  wavwrite(varargin{:});
end