forked from breizhn/new_wav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wav_writeTest.m
136 lines (104 loc) · 3.53 KB
/
wav_writeTest.m
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
% Script to test and compare the function wav_write.m with the "old"
% wavwrite. This will only work in Matlab < R2015b and you have to rename the
% new function to wav_write().
% Author: Nils L. Westhausen
% (c) TGM @ Jade Hochschule (MIT license).
% Version History:
% Ver. 0.0.0 initial create (empty) 13-Apr-2015 NW
% Ver. 1.0.0 First Implementation 06-May-2015 NW
% Ver. 1.1.0 new testnames 15-May-2015 NW
% Ver. 1.2.0 added test 15-May-2015 NW
% Ver. 1.3.0 changed name to wav_write 28-May-2015 NW
% Ver. 1.3.1 corrected data comparison 06-Jun-2015 NW
%-------------------------------------------------------------------------
%
%% Testing of Error returning by calling only with one argument
data = randn(1,48000).*0.2;
try
wav_write(data);
catch err
switch err.identifier
case 'wav_write:notEnoughArgs'
otherwise
error('not returning error, when called only with one input argument')
end
end
%% Testing of writing without .wav extension
data = randn(1,48000).*0.2;
filename = 'test';
fs =48000;
try
wav_write(data,fs,filename);
catch err
error('writing without .wav extesion not possible')
end
delete([filename '.wav'])
%% Output of wavwrite(data, filename) should be the same as wav_write(data, filename)
data = randn(1,48000).*0.2;
filename1 = 'test1';
filename2 = 'test2';
wavwrite(data ,filename1)
wav_write(data, filename2)
[y_old, fs_old] = audioread([filename1 '.wav']);
[y_new, fs_new] = audioread([filename2 '.wav']);
nbits_old = audioinfo([filename1 '.wav']);
nbits_old = nbits_old.BitsPerSample;
nbits_new = audioinfo([filename2 '.wav']);
nbits_new = nbits_new.BitsPerSample;
if fs_old ~= fs_new
error('the sampling rate is not the same')
end
if ~mean(y_new == y_old)
error('the data is not equal')
end
if nbits_old ~= nbits_new
error('The bits per sample are not equal')
end
delete([filename1 '.wav'], [filename2 '.wav'])
%% Output of wavwrite(data, fs, filename) should be the same as wav_write(data, fs, filename)
data = randn(1,48000).*0.2;
fs =48000;
filename1 = 'test1';
filename2 = 'test2';
wavwrite(data, fs ,filename1)
wav_write(data, fs, filename2)
[y_old, fs_old] = audioread([filename1 '.wav']);
[y_new, fs_new] = audioread([filename2 '.wav']);
nbits_old = audioinfo([filename1 '.wav']);
nbits_old = nbits_old.BitsPerSample;
nbits_new = audioinfo([filename2 '.wav']);
nbits_new = nbits_new.BitsPerSample;
if fs_old ~= fs_new
error('the sampling rate is not the same')
end
if ~mean(y_new == y_old)
error('the data is not equal')
end
if nbits_old ~= nbits_new
error('The bits per sample are not equal')
end
delete([filename1 '.wav'], [filename2 '.wav'])
%% Output of wavwrite(data, fs, nbits, filename) should be the same as wav_write(data, fs, nbits, filename
data = randn(1,48000).*0.2;
fs =48000;
nbits = 8;
filename1 = 'test1';
filename2 = 'test2';
wavwrite(data, fs , nbits,filename1)
wav_write(data, fs, nbits, filename2)
[y_old, fs_old] = audioread([filename1 '.wav']);
[y_new, fs_new] = audioread([filename2 '.wav']);
nbits_old = audioinfo([filename1 '.wav']);
nbits_old = nbits_old.BitsPerSample;
nbits_new = audioinfo([filename2 '.wav']);
nbits_new = nbits_new.BitsPerSample;
if fs_old ~= fs_new
error('the sampling rate is not the same')
end
if ~mean(y_new == y_old)
error('the data is not equal')
end
if nbits_old ~= nbits_new
error('The bits per sample are not equal')
end
delete([filename1 '.wav'], [filename2 '.wav'])