-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaudio_calculator.html
209 lines (178 loc) · 7.75 KB
/
audio_calculator.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ReaClassical Audio Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.container {
max-width: 500px;
margin: auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
}
label {
display: block;
margin-bottom: 5px;
}
input, select {
width: auto;
padding: 8px;
margin-bottom: 15px;
box-sizing: border-box;
}
.result {
font-weight: bold;
}
.logo {
width: 100%; /* Set the width to 100% of the container */
height: auto; /* Maintain aspect ratio */
}
</style>
</head>
<body>
<div class="container">
<img src="reaclassical_logo.png" alt="ReaClassical Logo" class="logo">
<h2>Audio Calculator</h2>
<label for="unitType">Select Unit Type:</label>
<select id="unitType" onchange="handleUnitChange(); calculate();">
<option value="GB">GB</option>
<option value="MB">MB</option>
<option value="TB">TB</option>
<option value="Hours">Hours</option>
<option value="Minutes">Minutes</option>
<option value="Seconds">Seconds</option>
</select>
<label for="inputValue">Enter Value:</label>
<input type="number" id="inputValue" min="0" step="any" value="1" oninput="calculate();">
<label for="format">Select Format:</label>
<select id="format" onchange="handleFormatChange(); calculate();">
<option value="wav">WAV</option>
<option value="mp3">MP3</option>
</select>
<div id="bitrateContainer" style="display: none;">
<label for="bitrate">Select Bitrate (kbps):</label>
<select id="bitrate" onchange="calculate();">
<option value="32">32</option>
<option value="64">64</option>
<option value="96">96</option>
<option value="128">128</option>
<option value="160">160</option>
<option value="192">192</option>
<option value="256">256</option>
<option value="320" selected>320</option>
</select>
</div>
<label for="sampleRate">Sample Rate (Hz):</label>
<select id="sampleRate" onchange="calculate();">
<option value="44100">44.1 kHz</option>
<option value="48000" selected>48 kHz</option>
<option value="88200">88.2 kHz</option>
<option value="96000">96 kHz</option>
<option value="192000">192 kHz</option>
</select>
<label for="bitDepth">Bit Depth:</label>
<select id="bitDepth" onchange="calculate();">
<option value="16">16-bit</option>
<option value="24" selected>24-bit</option>
<option value="32">32-bit float</option>
</select>
<label for="numTracks">Number of Tracks:</label>
<input type="number" id="numTracks" value="2" min="1" oninput="calculate();">
<div class="result" id="result"></div>
</div>
<script>
function handleUnitChange() {
const unit = document.getElementById('unitType').value;
const inputLabel = document.querySelector('label[for="inputValue"]');
if (unit === 'Hours' || unit === 'Minutes' || unit === 'Seconds') {
inputLabel.innerHTML = 'Enter Duration:';
} else {
inputLabel.innerHTML = 'Enter File Size:';
}
}
function handleFormatChange() {
const format = document.getElementById('format').value;
const bitrateSelector = document.getElementById('bitDepth');
const samplerateSelector = document.getElementById('sampleRate');
const numTracksInput = document.getElementById('numTracks');
if (format === 'mp3') {
document.getElementById('bitrate').parentElement.style.display = 'block';
bitrateSelector.disabled = true;
samplerateSelector.disabled = true;
numTracksInput.value = 2;
numTracksInput.disabled = true;
} else {
document.getElementById('bitrate').parentElement.style.display = 'none';
bitrateSelector.disabled = false;
samplerateSelector.disabled = false;
numTracksInput.disabled = false;
}
}
function calculate() {
const unitType = document.getElementById('unitType').value;
const inputValue = parseFloat(document.getElementById('inputValue').value);
const format = document.getElementById('format').value;
const sampleRate = parseInt(document.getElementById('sampleRate').value);
const bitDepth = parseInt(document.getElementById('bitDepth').value);
const numTracks = parseInt(document.getElementById('numTracks').value);
const bitrate = format === 'mp3' ? parseInt(document.getElementById('bitrate').value) : null;
let dataRate;
if (format === 'mp3' && bitrate) {
dataRate = (bitrate * 1000) / 8;
} else {
dataRate = sampleRate * (bitDepth / 8) * numTracks;
}
const wavOverhead = 44;
let result;
if (unitType === 'GB' || unitType === 'MB' || unitType === 'TB') {
let bytes;
if (unitType === 'GB') {
bytes = inputValue * 1000 * 1000 * 1000;
} else if (unitType === 'MB') {
bytes = inputValue * 1000 * 1000;
} else if (unitType === 'TB') {
bytes = inputValue * 1000 * 1000 * 1000 * 1000;
}
if (format === 'wav') {
bytes -= wavOverhead;
}
const durationSeconds = bytes / dataRate;
result = `Duration: ${formatDuration(durationSeconds)}`;
} else {
let durationSeconds;
if (unitType === 'Hours') {
durationSeconds = inputValue * 3600;
} else if (unitType === 'Minutes') {
durationSeconds = inputValue * 60;
} else if (unitType === 'Seconds') {
durationSeconds = inputValue;
}
const fileSizeBytes = (durationSeconds * dataRate) + (format === 'wav' ? wavOverhead : 0);
const fileSizeMB = fileSizeBytes / (1000 * 1000);
const fileSizeGB = fileSizeBytes / (1000 * 1000 * 1000);
result = `File size: ${fileSizeMB.toFixed(2)} MB (${fileSizeGB.toFixed(2)} GB)`;
}
const dataRateKbps = dataRate * 8 / 1000;
const dataRateMbps = dataRateKbps / 1000;
result += `<br>Data Rate: ${dataRateKbps.toFixed(2)} Kbps (${dataRateMbps.toFixed(2)} Mbps)`;
document.getElementById('result').innerHTML = result;
}
function formatDuration(seconds) {
const hours = Math.floor(seconds / 3600);
seconds %= 3600;
const minutes = Math.floor(seconds / 60);
seconds = Math.floor(seconds % 60);
return `${hours}h ${minutes}m ${seconds}s`;
}
document.getElementById('inputValue').value = 1; // 1 GB
document.getElementById('numTracks').value = 2; // 2 Tracks
calculate();
</script>
</body>
</html>