-
Notifications
You must be signed in to change notification settings - Fork 0
/
wav_headers.html
131 lines (127 loc) · 5.28 KB
/
wav_headers.html
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
<!--
Copyright 2018, Bart Butenaers
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/x-red" data-template-name="wav-headers">
<div class="form-row">
<label for="node-input-action"><i class="fa fa-wrench"></i> Action</label>
<select id="node-input-action">
<option value='add'>Add WAV headers</option>
<option value='del'>Remove WAV headers</option>
<option value='get'>Get WAV headers</option>
</select>
</div>
<div class="form-row actionAdd-row">
<label for="node-input-name"><i class="icon-tag"></i> channels</label>
<input type="number" id="node-input-channels" placeholder="1">
</div>
<div class="form-row actionAdd-row">
<label for="node-input-samplerate"><i class="icon-tag"></i> rate</label>
<input type="number" id="node-input-samplerate" placeholder="22050">
</div>
<div class="form-row actionAdd-row">
<label for="node-input-bitwidth"><i class="icon-tag"></i> bitwidth</label>
<input type="number" id="node-input-bitwidth" placeholder="16">
</div>
<br>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('wav-headers', {
category: 'input',
color: 'rgb(178, 102, 255)',
defaults: {
name: {value: ""},
action: {value: "add"},
channels: {value: 1, validate:function(v) {
// This value is only mandatory when headers need to be added
return v || $("#node-input-action").val() !== "add";
}},
samplerate: {value: 22050, validate:function(v) {
// This value is only mandatory when headers need to be added
return v || $("#node-input-action").val() !== "add";
}},
bitwidth: {value: 16, validate:function(v) {
// This value is only mandatory when headers need to be added
return v || $("#node-input-action").val() !== "add";
}}
},
inputs: 1,
outputs: 2,
icon: "wav.png",
inputLabels: function(index) {
if (this.action === "add") {
return "Raw audio buffer (PCM)";
}
else {
return "WAV buffer";
}
},
outputLabels: function(index) {
if (index === 0) {
if (this.action === "add" || this.action === "get") {
return "WAV buffer";
}
else {
return "Raw audio buffer (PCM)";
}
}
else {
switch (this.action) {
case "add":
return "Added WAV headers";
case "del":
return "Removed WAV headers";
case "get":
return "Available WAV headers";
}
}
},
label: function() {
if (this.name) {
return this.name;
}
switch (this.action) {
case "add":
return "Add WAV headers";
case "del":
return "Remove WAV headers";
case "get":
return "Get WAV headers";
}
},
oneditprepare: function() {
// The input fields should only be displayed when the 'ADD' action is selected
$("#node-input-action").change(function() {
var action = $("#node-input-action").val();
if (action === "add") {
$(".actionAdd-row").show();
}
else {
$(".actionAdd-row").hide();
}
});
},
});
</script>
<script type="text/x-red" data-help-name="wav-headers">
<p>A Node Red node to handle WAV headers.</p>
<p>Following actions are supported:
<ul>
<li><strong>Add WAV headers:</strong> the <code>msg.payload</code> should contain a chunk of raw audio samples (PCM), to which the WAV headers will be added (in front).</li>
<li><strong>Remove WAV headers:</strong> the <code>msg.payload</code> should contain a WAV buffer, from which the WAV headers will be removed. So only the raw audio samples (PCM) will arrive on the output.</li>
<li><strong>Get WAV headers:</strong> the <code>msg.payload</code> should contain a WAV buffer, from which the WAV headers will be read. The original input message will be send untouched on the output.</li>
</ul>
</p>
</script>