-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidation.js
69 lines (60 loc) · 1.73 KB
/
validation.js
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
const meyda = require('meyda');
const validateFeatures = (features) => {
const invalidFeatures = (() => {
try {
// Get a list of the features that have been asked for that aren't supported
return features.reduce((accumulator,feature) => {
if (Object.keys(meyda.featureExtractors).indexOf(feature) < 0) {
return accumulator.concat([feature]);
}
return accumulator;
}, []);
} catch (e) {
throw {
name: 'Invalid Features',
message: 'Feature must be in an array'
}
}
})();
if (invalidFeatures.length > 0) {
throw {
name: 'Invalid Features',
message: `Invalid feature(s) ${invalidFeatures.toString()}`
};
}
return true;
}
const validateWindowingFunction = (windowingFunction) => {
// TODO get this list of valid windowing functions from Meyda
const validWindowingFunctions = [
'hanning',
'hamming',
'blackman',
'sine'
];
if (validWindowingFunctions.indexOf(windowingFunction) > -1){
throw {
name: 'Invalid Windowing Function',
message: 'Valid windowing functions list available here:\nhttps://github.com/hughrawlinson/meyda/wiki/audio-features#windowing-functions'
};
}
return true;
}
const validateBufferSize = (bufferSize) => {
// TODO validate buffer size
if (!powerOfTwo(bufferSize)){
throw {
name: 'Invalid Buffer Size',
message: 'The buffer size must be a power of two'
}
}
}
const validate = (features, windowingFunction, bufferSize) => {
return validateFeatures(features) && validateWindowingFunction(windowingFunction) && validateBufferSize(bufferSize);
}
module.exports = {
validate,
validateFeatures,
validateWindowingFunction,
validateBufferSize
}