Skip to content

Commit

Permalink
update haptic test
Browse files Browse the repository at this point in the history
  • Loading branch information
cabanier committed May 9, 2023
1 parent 0d83650 commit e2da542
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Binary file added banjo_haptic.mp3
Binary file not shown.
18 changes: 11 additions & 7 deletions input-selection-4.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@
buffer[i] = value;
}

let yodelBuffer;
const URL = 'beat.mp3';
const context = new AudioContext();
let banjoBuffer;
const URL = 'banjo_haptic.mp3';
const context = new AudioContext({'sampleRate': 3000});

window.fetch(URL)
.then(response => response.arrayBuffer())
.then(arrayBuffer => context.decodeAudioData(arrayBuffer))
.then(audioBuffer => {
yodelBuffer = audioBuffer;
banjoBuffer = audioBuffer;
});
// WebGL scene globals.
let gl = null;
Expand Down Expand Up @@ -224,15 +224,19 @@
return;
}

let audio_buffer = new AudioBuffer({'sampleRate': 3000, 'length': buffer.byteLength});
audio_buffer.copyToChannel(buffer, 0);
ev.inputSource.gamepad.hapticActuators[0].playPCM((ev.inputSource.handedness == "left") ? audio_buffer : banjoBuffer);

let hitResult = scene.hitTest(targetRayPose.transform);
if (hitResult) {
// Check to see if the hit result was one of our boxes.
for (let box of boxes) {
if (hitResult.node == box.node) {
let i = (ev.inputSource.handedness == "left") ? 0 : 1;
let audio_buffer = new AudioBuffer({'sampleRate': 3000, 'length': buffer.byteLength});
audio_buffer.copyToChannel(buffer, 0);
ev.inputSource.gamepad.hapticActuators[0].playPCM(audio_buffer);
// let audio_buffer = new AudioBuffer({'sampleRate': 3000, 'length': buffer.byteLength});
// audio_buffer.copyToChannel(buffer, 0);
// ev.inputSource.gamepad.hapticActuators[0].playPCM(audio_buffer/*banjoBuffer*/);
currently_selected_boxes[i] = box;
box.scale = [1.25, 1.25, 1.25];
box.selected = false;
Expand Down

0 comments on commit e2da542

Please sign in to comment.