-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
241 lines (228 loc) · 9.92 KB
/
index.php
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
require("audioswitcher.inc.php");
require("config.inc.php");
?>
<!doctype html>
<html>
<head>
<title>Audio Watermark Listening Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.1/underscore-min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.1/backbone-min.js"></script>
<script type="text/javascript" src="audioswitcher.js"></script>
<script>
var audioSwitcher = [];
var timer = {
id: null,
totalTime: 0,
interval: 1000, // milliseconds
start: function () {
var self = this;
if (this.id != null) clearInterval(this.id);
this.id = setInterval(function () {
self.totalTime = self.totalTime + self.interval/1000;
}, this.interval);
},
stop: function () {
clearInterval(this.id);
}
};
timer.start();
window.addEventListener('focus', function() {
timer.start();
console.log('starting timer at:', timer.totalTime);
}, false);
window.addEventListener('blur', function() {
timer.stop();
console.log('stopping timer at:', timer.totalTime);
}, false);
</script>
<link rel="stylesheet" href="audiotest.css">
</head>
<body>
<h1>Audio Watermark Listening Test</h1>
<?
if(isset($_POST['token'])) {
$mysqli = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$token = intval($_POST['token']);
$active_time = intval($_POST['active_time']);
$ip_address = $mysqli->escape_string($_SERVER['REMOTE_HOST']);
$environment = $mysqli->escape_string($_POST['environment']);
$device = $mysqli->escape_string($_POST['device']);
$num_correct = 0;
$correct = array();
foreach($_POST as $key => $value) {
$matches = array();
$match = preg_match('/^audio_([0-9]+)$/', $key, $matches);
if ($match === 1) {
// This item is a question response
$audio_id = intval($matches[1]);
$response = intval($value);
$audio_name = $filemap[$audio_id][0]['name'];
$correct[$audio_id] = $corr = $filemap[$audio_id][$response]['num'] == '2'; // when response value matches suffix for watermarked files
$query = "INSERT INTO responses (audio_id, audio_name, response, correct, environment, device, ip_address, token, active_time)
VALUES ('$audio_id', '$audio_name', '$response', '$corr', '$environment', '$device', '$ip_address', '$token', '$active_time')";
$result = $mysqli->query($query);
// echo("running $query.<br>");
// echo($mysqli->error."<br>");
if ($corr) $num_correct++;
}
}
?>
<h2>Results</h2>
<h3 class="score">You scored <?=$num_correct?> out of <?=count($filemap)?> correct.</h3>
<ol><?
foreach($correct as $key => $value) {
print ("<li>[".$filemap[$key][0]['name']."] ");
if ($value == true)
print ("<span class='correct'>correct</span>");
else
print ("<span class='incorrect'>incorrect</span>");
}
?>
</ol>
<p>Thanks for taking the audio watermark listening test!</p>
<?
} else {
?>
<p>
This survey will test your ability to detect a digital audio watermark embedded in music files.
<p>
Digital audio watermarks hide extra information in an audio signal, usually for
copyright enforcement purposes. The watermarks are designed to be inaudible, but necessarily add
some distortion to the original audio.
<p>
Below, you will find <?=count($filemap)?> groups of audio samples. In each group, you are presented with
two versions of the same music sample. One
contains a digital watermark, and the other does not. Switch back and forth between the two audio
samples using the control buttons. Listen closely and try to determine which sample in each group
contains a watermark. <strong>For best results, use headphones and take the test in a quiet environment.</strong>
<p>
The watermarking technology is the same in all audio samples.
Your score will be reported after you submit your answers.
<form action="index.php" method="post">
<input type="hidden" name="token" value="<?=$token?>"/>
<input type="hidden" id="active_time" name="active_time" value="0"/>
<ol class="quiz">
<?php
foreach($filemap as $index => $fileset) {
?>
<li><h2 class="question"><?=htmlspecialchars($fileset[0]['name'])?></h2>
<? if ($fileset[0]['note']) { ?>
<div class="note">
<?=$fileset[0]['note']?>
</div>
<? } ?>
<div class="listitem" id="audioswitcher<?=$index?>">
<div class="col1">
<button type="button" class="switch a">A</button>
<div class="chooser">
<input class="required" type="radio" id="chooser_<?=$index?>_0" name="audio_<?=$index?>" value="0">
<label for="chooser_<?=$index?>_0">A is Watermarked</label>
</div>
</div>
<div class="col2">
<button type="button" class="toggle">Toggle ↔</button>
<button type="button" class="rewind">Rewind ↺ 3 sec</button><br>
<button type="button" class="toggleAndRewind">Toggle and Rewind ↺ 3 sec</button><br>
<audio id="audio_<?=$index?>_0" controls="true">
<source type="audio/ogg" src="getAudio.php?token=<?=$token?>&file=<?=$index?>,0&ext=ogg">
<source type="audio/mpeg" src="getAudio.php?token=<?=$token?>&file=<?=$index?>,0&ext=mp3">
Your browser does not support the Audio element.
</audio>
<audio id="audio_<?=$index?>_1" controls="true" style="display: none">
<source type="audio/ogg" src="getAudio.php?token=<?=$token?>&file=<?=$index?>,1&ext=ogg">
<source type="audio/mpeg" src="getAudio.php?token=<?=$token?>&file=<?=$index?>,1&ext=mp3">
Your browser does not support the Audio element.
</audio>
</div>
<div class="col3">
<button type="button" class="switch b">B</button>
<div class="chooser">
<input class="required" type="radio" id="chooser_<?=$index?>_1" name="audio_<?=$index?>" value="1">
<label for="chooser_<?=$index?>_1">B is Watermarked</label>
</div>
</div>
</div>
</li>
<script>
audioSwitcher[<?=$index?>] = new AudioSwitcher(document.getElementById('audioswitcher<?=$index?>'));
</script>
<?php
}
?>
</ol>
<div class="centered">
<!--
<div class="split">
<p>My listening environment is:
<p>
<input type="radio" id="environment_1" name="environment" value="quiet"><label for="environment_1">Quiet</label><br>
<input type="radio" id="environment_2" name="environment" value="normal"><label for="environment_2">Normal</label><br>
<input type="radio" id="environment_3" name="environment" value="loud"><label for="environment_3">Loud</label><br>
</div>
<div class="split">
<p>I am listening with:
<p>
<input type="radio" id="device_1" name="device" value="headphones"><label for="device_1">Headphones</label><br>
<input type="radio" id="device_2" name="device" value="speakers"><label for="device_2">Speakers</label><br>
<input type="radio" id="device_3" name="device" value="laptop"><label for="device_3">Laptop Speakers</label><br>
</div>
<div class="split">
<p>Did the watermarks bother you?
<p>
<input type="radio" id="device_1" name="device" value="headphones"><label for="device_1">Headphones</label><br>
<input type="radio" id="device_2" name="device" value="speakers"><label for="device_2">Speakers</label><br>
<input type="radio" id="device_3" name="device" value="laptop"><label for="device_3">Laptop Speakers</label><br>
</div>
-->
</div>
<button class="submit" type="button">Submit My Answers</button>
<p class="centered formMessage"></p>
<script>
var $button = $('button.submit');
var $form = $('form');
$button.bind('click', function() {
$('#active_time').val(timer.totalTime);
if (validateForm()) {
$form.submit();
}
});
$form.find('input').bind('change', resetValidation);
function validateForm() {
var isValid = true;
$form.find('.required').each(function() {
var name = $(this).attr('name');
if (!$form.find('input[name=' + name + ']:checked').val()) {
$(this).closest('.listitem').addClass('error');
isValid = false;
}
});
if (!isValid) {
$('.formMessage').text('Please answer all the questions. The questions you forgot to answer are highlighted above.');
}
return isValid;
}
function resetValidation(event) {
$container = $(event.target).closest('.listitem');
$container.removeClass('error');
$('.formMessage').text('');
}
</script>
</form>
<?
}
?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-25089589-1']);
_gaq.push(['_setCampNameKey', 'Listening Test']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>