-
Notifications
You must be signed in to change notification settings - Fork 0
/
aubio.R
169 lines (141 loc) · 4.92 KB
/
aubio.R
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
#------------------------------------------------------------------------------
# ---------------------------- AUBIO API -----------------------------------
#------------------------------------------------------------------------------
#
# aubioonset : onset detection
# aubiopitch : pitch detection
# aubiocut : audio to midi / cut file into multiple onsets
# aubionotes : audio to midi
# aubiomfcc : mel spectrum coefficients
# aubioquiet : extract quit and loud regions
# aubiotrack : extract beats from audio signal
note.C0 = 16.35
note.A0 = 27.50
note.C4 = 261.63
note.A4 = 440.00
note.A5 = 880
note.C8 = 4186.0
note.B8 = 7902
trace = FALSE
#------------------------------------------------------------------------------
# AUBIO PITCH
#
# -i --input input file
# -o --output output file
# -r --samplerate select samplerate
# -B --bufsize set buffer size
# -H --hopsize set hopsize
# -p --pitch select pitch detection algorithm
# -u --pitch-unit select pitch output unit
# -l --pitch-tolerance select pitch tolerance
# -s --silence select silence threshold
# -m --mix-input mix input signal with output signal
# -f --force-overwrite overwrite output file if needed
# -j --jack use Jack
# -v --verbose be verbose
# -h --help display this message
aubio.pitch.p = c('default', 'schmitt', 'fcomb', 'mcomb', 'specacf', 'yinfft')
aubiopitch <- function(file, args){
cmd = paste("aubiopitch", args, inout(file))
if(trace)
print(cmd)
pitch = cmdRun(cmd, out(file))
names(pitch)[1] = "time"
names(pitch)[2] = "frequency"
return(pitch)
}
#------------------------------------------------------------------------------
## AUBIO ONSET
#
# -i --input input file
# -o --output output file
# -r --samplerate select samplerate
# -B --bufsize set buffer size
# -H --hopsize set hopsize
# -O --onset select onset detection algorithm
# -t --onset-threshold set onset detection threshold
# -s --silence select silence threshold
# -m --mix-input mix input signal with output signal
# -f --force-overwrite overwrite output file if needed
# -j --jack use Jack
# -v --verbose be verbose
# -h --help display this message
aubio.onset.O = c('default', 'energy', 'hfc', 'complex', 'phase', 'specdiff', 'kl', 'mkl', 'specflux')
aubioonset <- function(file, args){
cmd = paste("aubioonset", args, inout(file))
if(trace)
print(cmd)
onsets <- cmdRun(cmd, out(file))
return(onsets)
}
#------------------------------------------------------------------------------
# AUBIO MFCC : Mel Spectrum Coefficients
aubiomfcc <- function(file, args){
cmd = paste("aubiomfcc", args, inout(file))
if(trace)
print(cmd)
onsets <- cmdRun(cmd, out(file))
return(onsets)
}
#------------------------------------------------------------------------------
# AUBIO CUT : WAV to midi
aubiocut <- function(file, args){
cmd = paste("aubiocut", args, inout(file))
if(trace)
print(cmd)
onsets <- cmdRun(cmd, out(file))
return(onsets)
}
#------------------------------------------------------------------------------
# AUBIO NOTES : WAV to midi
aubionotes <- function(file, args){
cmd = paste("aubionotes", args, inout(file))
if(trace)
print(cmd)
onsets <- cmdRun(cmd, out(file))
return(onsets)
}
#------------------------------------------------------------------------------
# AUBIO QUIET : Detects quiet and loud regions
aubioquiet <- function(file, args){
cmd = paste("aubioquiet", args, inout(file))
if(trace)
print(cmd)
onsets <- cmdRun(cmd, out(file))
return(onsets)
}
#------------------------------------------------------------------------------
# AUBIO TRACK : Beat detection
aubiotrack <- function(file, args){
cmd = paste("aubiotrack", args, inout(file))
if(trace)
print(cmd)
onsets <- cmdRun(cmd, out(file))
return(onsets)
}
#------------------------------------------------------------------------------
# FILTER UTILS
filterTimeRange <- function(pitch, timeRange){
outOfRange <- (pitch[,1] < timeRange[1]) | (pitch[,1] > timeRange[2])
return(pitch[!outOfRange,])
}
# Replace pitch events by NaN if they're standing out of frequency range
filterFreqRange <- function(pitch, freqRangeHz){
pitchFilter = pitch
pitchFilter[pitch$frequency < freqRangeHz[1], 2] = NaN
pitchFilter[pitch$frequency > freqRangeHz[2], 2] = NaN
return(pitchFilter)
}
#------------------------------------------------------------------------------
# RUN SYSTEM COMMANDS
cmdRun <- function(cmd, out){
system(cmd)
aubioOut <- read.table(out)
return(aubioOut)
}
inout <- function(file){
return(paste("-i", file, ">", out(file)))
}
out <- function(file){
return(paste(file, ".txt", sep=''))
}