Skip to content

Commit 6e3b71b

Browse files
committed
Remove wavread and wavwrite (#81)
* Replace wavread with audioread * Replace wavwrite with savewav()
1 parent 64efec8 commit 6e3b71b

File tree

6 files changed

+101
-8
lines changed

6 files changed

+101
-8
lines changed

INSTALL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ subpathes.
1010

1111
If you are using Octave you will need the following additional packages from
1212
octave-forge (http://octave.sourceforge.net/):
13-
* audio (e.g. for wavwrite)
13+
* audio
1414
* signal (e.g. for firls)

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Changes in the Sound Field Synthesis-Toolbox. Recent changes on top.
66
- change license to MIT
77
- update delayline() config settings
88
- add Lagrange and Thiran filters to delayline()
9+
- replace wavread and warwrite by audioread and savewav
910

1011
2.1.0 (10. March 2016)
1112

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ directory.
5959
You need Octave version 3.6 or newer to run the Toolbox. In addition,
6060
you will need the following additional packages from
6161
[octave-forge](http://octave.sourceforge.net/):
62-
* audio (e.g. for wavwrite)
62+
* audio
6363
* signal (e.g. for firls)
6464

6565
**Impulse responses**
@@ -591,7 +591,7 @@ function.
591591
conf = SFS_config;
592592
hrtf = SOFAload('QU_KEMAR_anechoic_3m.sofa');
593593
ir = get_ir(hrtf,[0 0 0],[0 0],[rad(30) 0 3],'spherical',conf);
594-
cello = wavread('anechoic_cello.wav');
594+
cello = audioread('anechoic_cello.wav');
595595
sig = auralize_ir(ir,cello,1,conf);
596596
sound(sig,conf.fs);
597597
```
@@ -608,7 +608,7 @@ conf.dimension = '2.5D';
608608
hrtf = SOFAload('QU_KEMAR_anechoic_3m.sofa');
609609
% ir = ir_wfs(X,phi,xs,src,hrtf,conf);
610610
ir = ir_wfs([0 0 0],pi/2,[0 3 0],'ps',hrtf,conf);
611-
cello = wavread('anechoic_cello.wav');
611+
cello = audioread('anechoic_cello.wav');
612612
sig = auralize_ir(ir,cello,1,conf);
613613
```
614614

@@ -651,7 +651,7 @@ conf.secondary_sources.geometry = 'custom';
651651
conf.secondary_sources.x0 = brir;
652652
conf.N = 44100;
653653
ir = ir_wfs([0 0 0],0,[3 0 0],'ps',brir,conf);
654-
cello = wavread('anechoic_cello.wav');
654+
cello = audioread('anechoic_cello.wav');
655655
sig = auralize_ir(ir,cello,1,conf);
656656
```
657657

@@ -725,7 +725,7 @@ All functions regarding the SSR are stored in <code>SFS_ssr</code>.
725725
```Matlab
726726
conf = SFS_config;
727727
brs = ssr_brs_wfs(X,phi,xs,src,hrtf,conf);
728-
wavwrite(brs,fs,16,'brs_set_for_SSR.wav');
728+
savewav(brs,'brs_set_for_SSR.wav',fs);
729729
```
730730

731731

SFS_binaural_synthesis/auralize_ir.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
if isnumeric(content)
7272
contentfs = conf.fs;
7373
elseif ~exist(content,'file')
74-
[content,contentfs] = wavread(contentfile);
74+
[content,contentfs] = audioread(contentfile);
7575
else
7676
error('%s: %s file was not found.',upper(mfilename),content);
7777
end

SFS_binaural_synthesis/compensate_headphone.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
if(usehcomp)
6464
lenir = size(ir,1);
6565
% Read headphone compensation filter
66-
hcomp = wavread(conf.ir.hcompfile);
66+
hcomp = audioread(conf.ir.hcompfile);
6767
% Check if the IR has the right length for the filter
6868
if lenir<length(hcomp)
6969
warning(['The length of the used IR is shorter than the headphone ', ...

SFS_general/savewav.m

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
function savewav(y,filename,fs)
2+
%SAVEWAV saves floating point audio data in a *.wav with 32bit precision
3+
%
4+
% Usage: savewav(y,filename,fs)
5+
%
6+
% Input parameters:
7+
% y - audio data in floating point [NFrames x NChannels]
8+
% filename - name of *.wav file (file extension will NOT be added
9+
% automatically)
10+
% fs - sample rate / Hz
11+
%
12+
% Since wavwrite has been removed in MATLAB 2015b and audiowrite does not
13+
% support audio data with a channel number higher than 256, this is an
14+
% alternative to save massive multichannel. This function does only support
15+
% floating point data and saves it 32bit floating point precision.
16+
%
17+
% See also: audiowrite, audioread, fwrite
18+
19+
% Copyright (c) 2015 Fiete Winter
20+
%
21+
% Permission is hereby granted, free of charge, to any person obtaining a copy
22+
% of this software and associated documentation files (the "Software"), to deal
23+
% in the Software without restriction, including without limitation the rights
24+
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25+
% copies of the Software, and to permit persons to whom the Software is
26+
% furnished to do so, subject to the following conditions:
27+
%
28+
% The above copyright notice and this permission notice shall be included in
29+
% all copies or substantial portions of the Software.
30+
%
31+
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32+
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33+
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34+
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35+
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36+
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
37+
% THE SOFTWARE.
38+
39+
%% Input Check
40+
narginchk(3,3);
41+
if ~isfloat(y)
42+
error('%s: only floating point supported', upper(mfilename));
43+
end
44+
if ~ndims(y) > 2
45+
error('%s: only audio data with [NFrames x NChannels] supported', ...
46+
upper(mfilename));
47+
end
48+
49+
%%
50+
[NFrames, NChannels] = size(y); % Number of Frames and Channels
51+
NSamples = NFrames*NChannels; % total Samples
52+
Nbits = 32; % 32 floating point
53+
Nbyte = 4; % bytes per Samples
54+
55+
fileID = fopen(filename,'w', 'ieee-le'); % open wav-file (little Endian)
56+
57+
fwrite(fileID, 'RIFF', 'char*1'); % RIFF header
58+
% number of bytes following (chunk size)
59+
Noverallbytes = 4 + 4; % for 'WAVE' and 'fmt '
60+
Noverallbytes = Noverallbytes + 4; % for the number of bytes in 'fmt '
61+
Noverallbytes = Noverallbytes + 16; % bytes in 'fmt '
62+
Noverallbytes = Noverallbytes + 12; % for 'fact'
63+
Noverallbytes = Noverallbytes + 8 + Nbyte*NSamples; % 'data' chunk
64+
fwrite(fileID, Noverallbytes, 'uint32');
65+
66+
fwrite(fileID, 'WAVE', 'char*1'); % WAVE header
67+
68+
%% fmt chunk
69+
fwrite(fileID, 'fmt ', 'char*1'); % mind the whitespace!
70+
fwrite(fileID, 16, 'uint32'); % number of bytes following (chunk size)
71+
fwrite(fileID, 3, 'uint16'); % data type (3 for float)
72+
fwrite(fileID, NChannels, 'uint16'); % number of channels
73+
fwrite(fileID, fs, 'uint32'); % samplerate
74+
fwrite(fileID, fs * NChannels * Nbyte, 'uint32'); % bytes per second
75+
fwrite(fileID, NChannels * Nbyte, 'uint16'); % frame size
76+
fwrite(fileID, Nbits, 'uint16'); % bits per sample
77+
78+
%% fact chunk (floating point only)
79+
fwrite(fileID, 'fact', 'char*1');
80+
fwrite(fileID, 4, 'uint32'); % number of bytes following (chunk size)
81+
fwrite(fileID, NFrames, 'uint32'); % number of frames
82+
83+
%% data chunk
84+
fwrite(fileID, 'data', 'char*1');
85+
fwrite(fileID, Nbyte*NSamples, 'uint32'); % number of bytes following (chunk size)
86+
y = y.'; % prepare data for interlacing
87+
fwrite(fileID, y(:), 'float32'); % interlaced data
88+
89+
%%
90+
fclose(fileID);
91+
92+
end

0 commit comments

Comments
 (0)