iPhoneã§ã¯ã¦ããã«ãä½ã£ãã£ã
ã¯ã¦ããã«ã好ãã§ããã®ã¿ã¼ã®ã«ããã£ã³ã°ã«ããã¦éãã§ããã¨ãã£ã¨ããã¾ã«æéãéãã¦ããã¾ãããããªããã§ã©ãã®ã家åºã«ãããiPhoneã¨JavaScriptã§ã¯ã¦ããã«ãä½ããã¨ã«ãã¾ããããããªãã¤ã
ã
JavaScriptã§iPhoneã®å é度ã»ã³ãµã¼ã¨Web Audio APIã使ã£ãã¯ã¦ããã«ä½ã£ãã http://t.co/rGDHh5FaWb https://t.co/erfjy9tL80
— aike (@aike1000) 2014, 10æ 20
ã
â ä½ãæ¹
ã¾ããWeb Audio APIã§ãã£ã«ã¿ã¼ãä½ãã¾ãã
Biquad Filterãä½ã£ã¦ãã³ããã¹ãã£ã«ã¿ã¼ã«è¨å®ããã ãã§ããç°¡åãQã®å¤ãå°ã大ããã®4ãããã«ãã¦ããã¨ã¯ã¦ãããã¯ã»ãåºã¾ãããã¨ã¯0.0〜1.0ã®å¼æ°ã®å¤ã«å¿ãã¦ãã£ã«ã¿ã¼ã®ä¸å¿å¨æ³¢æ°ãã»ããããé¢æ°setWahPos()ãç¨æãã¦ããã¾ããããããããã«ã®è§åº¦ãå¤ãã£ãã¨ãã«å¼ã°ãã¾ãã
ã
var ctx = new AudioContext(); var wah = ctx.createBiquadFilter(); wah.type = "bandpass"; wah.Q.value = 4; wah.connect(ctx.destination); var setWahPos = function(pos) { wah.frequency.value = 400 + 3000 * pos; } setWahPos(1.0);
ã
次ã«iPhoneã®å é度ã»ã³ãµã¼ã§è§åº¦ãæ¤ç¥ããå¦çãæ¸ãã¾ãã
deviceorientationã®ã¤ãã³ããªã¹ãã¼ãç¨æããã¨iPhoneã®è§åº¦å¤åã¤ãã³ããåãåãã¾ããè§åº¦æ
å ±ã¯alphaãbetaãgammaã®3æ¹åãããããã«ã¨ãã¦ä½¿ç¨ããåå¾ã®å¾ãæ
å ±ã¯betaã対å¿ãã¾ããæ¤ç¥ããè§åº¦ã0.0〜1.0ã®ç¯å²ã«æ£è¦åãã¦æå®ãããã³ã¼ã«ããã¯é¢æ°ãå¼ã¶å¦çã¯ãããªæãã
ã
var Pedaler = function(callback) { var self = this; window.addEventListener("deviceorientation", function(e){ if (e.alpha) { self.setAngle(e.alpha, e.beta, e.gamma); } }); this.angle = 0; this.callback = callback; } Pedaler.prototype.setAngle = function(alpha, beta, gamma) { var angle = (beta + 20) / 40; if (angle < 0.0) angle = 0.0; else if (angle > 1.0) angle = 1.0; this.angle = angle; if (this.callback) this.callback(this.angle); }
ã
ä¸è¨ã®Pedalerãªãã¸ã§ã¯ããçæãã¦ãã³ã¼ã«ããã¯é¢æ°ã§ã¯ã¦ã®setWahPos()ãæå®ãããã¨ã§è§åº¦ã¨é³è²ãé£åããã¾ãã
ã
$(function() { var pedaler = new Pedaler(function(a) { setWahPos(a); }); })
ã
ãã¨ã¯UIã¨é³æºå¦çãæ¸ãã°å®æã§ããé³æºã¯æ¬å½ã¯ã®ã¿ã¼ãiPhoneã«ã¤ãªãã§é³´ããããã¨ããã§ãããWebRTCãã¾ã iOSã®ãã©ã¦ã¶ã§ã¯ä½¿ããªãã®ã§ãµã³ããªã³ã°é³æºãã«ã¼ãã§é³´ãããã¨ã«ãã¦ãã¾ãã
ã
iPhoneWahãhttp://aikelab.net/iphonewah/
ã½ã¼ã¹ã³ã¼ããhttp://github.com/aike/iphonewah/
ã
Pedalerã¯ã¯ã¦ã«éããæ±ç¨çãªããã«ã¨ãã¦ä½¿ããããã«æ¸ãã¦ããã®ã§ãã¢ã¤ãã¢ã¨iPhoneãè¸ã¿å£ãåæ°ãããã°ããããå¿ç¨ãèããããã¨æãã¾ãã