Repository navigation
Expand file tree
/
Copy pathWaveFileAmplitudeAnalyzer.m
More file actions
217 lines (204 loc) · 10.1 KB
/
Copy pathWaveFileAmplitudeAnalyzer.m
File metadata and controls
217 lines (204 loc) · 10.1 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
%
% The MIT License (MIT)
%
% Copyright (c) 2026 Dave Starkey (midi9.com)
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in
% all copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
% THE SOFTWARE.
%
% this script is intended for use by MIDI Association members.
% this is a script for use with GNU Octave 10.2. It will likely run in Matlab.
% GNU Octave is availble for free download for MAC or windows
% this is written and run on a Windows 11 PC. It will likely work on earlier versions of the widows
% This script is hard coded with the filename to be anaylized. to use it the file names and locations need to be changed
% One of the hardest things for this app is locating the first note:
% this is hard because the first note is the softest and close to the noise floor
% since the wave files are generated in different ways there is no guarantee of pre-roll before the first note
% this application is specific to the MIDI file. If different note spacing in time is used the app must be changed
% the inFileName must point to the wave file to analyse
% the resultant .pdf and .txt files will be in the directory where the script is luanched from
% good luck
% for further question about use or modifications contact Dave Starkey
thisFileName = mfilename('fullpathext')
graphics_toolkit('gnuplot');%comment out for use with MAC might work
close all
clear all
NumVelocities = 10;% select 10 note or 13 note here
thumpSizeSeconds = 3;%seconds
DeadSpace = 0;%2seconds for Yamaha files 0 for others
preRoll =.9;%.3 for Yamaha .9 for others
pkg load signal
plotPosX = 400;
plotPosY = 400;
plotSizeX = 1250;
plotSizeY = 1600;
noteName = {"A0","A1","A2","A3","A4","A5","A6","A7"};
noteNum = [21,33,45,57,68,79,81,93,105];
noteFreq = [27.5, 55, 110,220,440,880,1760,3520,7040];
if(NumVelocities == 10)
VelocityValues = [10,25,40,53,66,79,92,104,117,127];
VelocityNames = {'pppp','ppp','pp','p','mp','mf','f','ff','fff','ffff'};
#inFileName = "WaveSource/PnoProfile_8_at_10_Yamaha_05282026_HammerMic_all.wav"; %reqires changing thumpSizeSeconds->2 preRoll -> .3
#inFileName = "WaveSource/PnoProfile_8_at_10_Yamaha_05282026_ListenerMic_all.wav";% missing first note
#inFileName = "WaveSource/PnoProfile_8_at_10_Yamaha_05282026_PlayerMic_all.wav";% missing first note
inFileName = "WaveSource/PnoProfile_8_at_10_Ivory_3_40826.wav";% required remanming for compatability
#inFileName = "WaveSource/PianoProfile 8 Notes at 10 Velocities - Ivory 3 40826.wav";
#inFileName = "WaveSource/Steinway_Spirio-B-r_8 Notes at 10 Velocities_05072026.wav";
else
VelocityValues = [5,10,16,25,32,40,53,66,79,92,104,117,127];%expanded to include 3 new veloctity values
VelocityNames = {'pppp-','pppp','ppp-','ppp','pp-','pp','p','mp','mf','f','ff','fff','ffff'};
#inFileName = "WaveSource/Piano_Profile_8_Notes_13_Velocities_Ivory_3_41226.wav";
inFileName = "WaveSource/PnoProfile_8_at_13_Ivory_3_41226 .wav";% required remanming for compatability
#inFileName = "WaveSource/Piano Profile 8 Notes at 13 Velocities - Ivory 3 41226.wav";%sould not run with this name
#inFileName = "WaveSource/Steinway_Spirio-B-r_8 Notes at 13 Velocities_05072026.wav";
end;
db_max_max = 0;
db_win_max = 0;
[pathstr, name, ext] = fileparts(inFileName);
outFileName = sprintf("Results/%s%s",name,".pdf");
TextOutFileName = sprintf("Results/%s%s",name,".txt");
TOF = fopen(TextOutFileName, "w");
info = audioinfo(inFileName);
tInfo = stat(inFileName)
fprintf(TOF,"using WaveFileAmplitudeAnalyzer_v_2.m dated 4-26-2021\n");
fprintf(TOF,"developed by Dave Starkey of MIDI 9\n");
fprintf(TOF,"Anaylizing %s\n",info.Filename);
stime = sprintf("recoded on %s",ctime(tInfo.mtime));
fprintf(TOF,"%s\n",stime);
fprintf(TOF,"SampleRate = %d\n",info.SampleRate);
fprintf(TOF,"Duration %d seconds\n",info.Duration);
fprintf(TOF,"BitsPerSample %d \n",info.BitsPerSample);
fs = info.SampleRate
thumpGroupSize = (thumpSizeSeconds * NumVelocities) + DeadSpace;
thumpSizeSamps = thumpSizeSeconds *fs;%samps
thumpGroupSamps = thumpGroupSize * fs;
[bigWave, fs] = audioread (inFileName);
bigWaveLength = length(bigWave);
sbigWave = decimate(bigWave, 4);
figure('position',[plotPosX,plotPosY,plotSizeX,plotSizeY]);
plot(sbigWave);
grid on
Title = sprintf("Waveform to analyze %s%s",name,ext);
title(Title,"interpreter", "none")
print ("-dpdf", outFileName) ;
for noteVel = 1:NumVelocities
%thumpStart(noteVel) = iOffset + (fs/2) + ((noteVel-1) * thumpSizeSamps);%offset pushes it into the note
thumpStart(noteVel) = 1+ ((noteVel-1) * thumpSizeSamps);%preRoll taken care of an thumpGroupStart later
thumpEnd(noteVel) = thumpStart(noteVel) + thumpSizeSamps;
thumpStartSec(noteVel) = thumpStart(noteVel)/fs;
thumpEndSec(noteVel) = thumpEnd(noteVel)/fs;
end
bigWaveMax = max(abs(bigWave));
vSize = 1.1 * bigWaveMax(1,1);
xSec = (1:(thumpGroupSamps+1))/fs;
preRollSamps = thumpSizeSamps * preRoll;
windowSizePeriods = 1;
for noteNumber = 1:8
freq = noteFreq(noteNumber);
windowSize = int32((fs * windowSizePeriods)/noteFreq(noteNumber));% using one for now.
hwindow = hanning(windowSize);
thumpGroupStart = ((noteNumber-1) * thumpGroupSamps ) + preRollSamps;
thumpGroupEnd = thumpGroupStart + thumpGroupSamps;
if(thumpGroupEnd > bigWaveLength)
thumpGroupEnd = bigWaveLength;
end;
SingleNoteWave = bigWave(thumpGroupStart:thumpGroupEnd);
absSingleNoteWave = abs(bigWave(thumpGroupStart:thumpGroupEnd));
figure('position',[plotPosX,plotPosY,plotSizeX,plotSizeY]);
for noteVel = 1:NumVelocities
%max_v(noteVel) = max(abs(SingleNoteWave(thumpStart(noteVel): thumpEnd(noteVel))));
tEnd = thumpEnd(noteVel);
if(tEnd > thumpGroupEnd - thumpGroupStart)
tEnd = thumpGroupEnd - thumpGroupStart;
end;
[maxY,maxX] = max(absSingleNoteWave(thumpStart(noteVel): tEnd));
thumpMaxY(noteVel) = maxY;
thumpMaxX(noteVel) = (thumpStart(noteVel) + maxX)/fs;
db_max(noteVel,noteNumber) = (10 * log(thumpMaxY(noteVel))) + 0;
end;
thumpMaxY;
thumpMaxX;
xLength = length(xSec);
wLength = length(SingleNoteWave);
if(xLength > wLength)
plot(xSec(1:wLength),SingleNoteWave,thumpMaxX,thumpMaxY,"o");
else
plot(xSec,SingleNoteWave,thumpMaxX,thumpMaxY,"o");
end;
grid on %plot(xSec,SingleNoteWave);
xSize = thumpSizeSeconds * NumVelocities;
axis([0,xSize,-vSize,vSize]);
set(gca, 'xtick', 0:thumpSizeSeconds:xSize);
Title = sprintf("Note %s vs time in %s%s",noteName{noteNumber},name,ext);
title(Title,"interpreter", "none")
print ("-dpdf", "-append", outFileName) ;
dbxxx = max(db_max(:,noteNumber));
db_max_max = max(dbxxx,db_max_max);
abs_db1 = num2str(db_max(1 ,noteNumber), "%3.1f");
abs_db2 = num2str(db_max(2 ,noteNumber)," %3.1f");
abs_db3 = num2str(db_max(3 ,noteNumber)," %3.1f");
abs_db4 = num2str(db_max(4 ,noteNumber)," %3.1f");
abs_db5 = num2str(db_max(5 ,noteNumber)," %3.1f");
abs_db6 = num2str(db_max(6 ,noteNumber)," %3.1f");
abs_db7 = num2str(db_max(7 ,noteNumber)," %3.1f");
abs_db8 = num2str(db_max(8 ,noteNumber)," %3.1f");
abs_db9 = num2str(db_max(9 ,noteNumber)," %3.1f");
abs_db10 = num2str(db_max(10,noteNumber)," %3.1f");
if(NumVelocities == 10)
abs_sdB{noteNumber} = sprintf('note %s peak amp dB: %s %s %s %s %s %s %s %s %s %s ',noteName{noteNumber},abs_db1,abs_db2,abs_db3,abs_db4,abs_db5,abs_db6,abs_db7,abs_db8,abs_db9,abs_db10);
fprintf(TOF,"note %s peak amp dB: %s %s %s %s %s %s %s %s %s %s \n",noteName{noteNumber},abs_db1,abs_db2,abs_db3,abs_db4,abs_db5,abs_db6,abs_db7,abs_db8,abs_db9,abs_db10);
else %NumVelocities == 13
abs_db11 = num2str(db_max(11,noteNumber)," %3.1f");
abs_db12 = num2str(db_max(12,noteNumber)," %3.1f");
abs_db13 = num2str(db_max(13,noteNumber)," %3.1f");
abs_sdB{noteNumber} = sprintf('note %s peak amp dB: %s %s %s %s %s %s %s %s %s %s %s %s %s',noteName{noteNumber},abs_db1,abs_db2,abs_db3,abs_db4,abs_db5,abs_db6,abs_db7,abs_db8,abs_db9,abs_db10,abs_db11,abs_db12,abs_db13);
fprintf(TOF,"note %s peak amp dB: %s %s %s %s %s %s %s %s %s %s %s %s %s\n",noteName{noteNumber},abs_db1,abs_db2,abs_db3,abs_db4,abs_db5,abs_db6,abs_db7,abs_db8,abs_db9,abs_db10,abs_db11,abs_db12,abs_db13);
end;
end
plotPosX = 1200;
figure('position',[plotPosX,plotPosY,plotSizeX,plotSizeY]);
yMax = db_max_max;
yMin = db_max_max - 60 ;
ySize = yMax - yMin;
axis([1,127,yMin,yMax]);
hold on
text(2, yMin + ySize * 0.98, abs_sdB(1));
text(2, yMin + ySize * 0.96, abs_sdB(2));
text(2, yMin + ySize * 0.94, abs_sdB(3));
text(2, yMin + ySize * 0.92, abs_sdB(4));
text(2, yMin + ySize * 0.90, abs_sdB(5));
text(2, yMin + ySize * 0.88, abs_sdB(6));
text(2, yMin + ySize * 0.86, abs_sdB(7));
text(2, yMin + ySize * 0.84, abs_sdB(8));
plot(VelocityValues(1,:),db_max(:,1))
plot(VelocityValues(1,:),db_max(:,2))
plot(VelocityValues(1,:),db_max(:,3))
plot(VelocityValues(1,:),db_max(:,4))
plot(VelocityValues(1,:),db_max(:,5),"--")
plot(VelocityValues(1,:),db_max(:,6),"--")
plot(VelocityValues(1,:),db_max(:,7),"--")
plot(VelocityValues(1,:),db_max(:,8),"--")
legend('A0','A1','A2','A3','A4','A5','A6','A7');
legend('location','southeast');
Title = sprintf("plot peak dB amplitudes in %s%s",name,ext);
title(Title,"interpreter", "none")
set(gca, 'xtick',[5,10,16,25,32,40,53,66,79,92,104,117,127])
grid on
print ("-dpdf", "-append", outFileName) ;
fclose(TOF);
close all;