いらないモノ、ひつようなモノ

書籍、音楽、そして若干のテクノロジー

加速度センサを利用したサンプル

←csoundメモ 目次へ戻る

  • 加速度センサと画面上のトラックパッドと呼ばれる領域を使ったサンプル。
  • androidスマホを振ると音がする。
  • このCSDファイルをDropBoxなど経由で本体に転送し、Openメニュでファイルを読み込み、Startボタンで動作開始させる。
動作環境
  • Android4.0.4
  • GALAXY Tab SC-01E
コード

;
; use acceleration sensor and TrackPad
;
;
; description:
; when sqrt(ax*ax+ay*ay+az*az) > threshhold, try to make sound which
; is reverberated. Reverberation parameter is controled through
; trackpad.x and trackpad.y.
; freeverb is used.
; look up the URL http://www.csounds.com/manual/html/freeverb.html
; for the parameter details.
;
; the chain of the instrument is described below.
; inst GetAccel
; -duration is controld. as
;
; (maxdur) 1.0 *********
; *
; *
; 0.1 ******
; ----------+-----+---(click)
; 500 5000
; ->inst MixSignal
; -sends the signal to the mix
; ->inst SignalOut
; -reberbation and sends the signal to the outputs
; ->inst ClearMix
; - necessary for the mixing.
;
<CsoundSynthesizer>
<CsOptions>
  • odac -d ; -+rtaudio=null
</CsOptions> <CsScore> f1 0 65536 10 1 ;SIN i1 0 36000 i2 0 36000 i3 0 36000 i100 0 36000 e </CsScore> <CsInstruments> sr = 44100 ksmps = 10 nchnls = 2 ; 2 channnel ; ; sense the timing of signal using acceleration sensor ; instr 1, GetAccel k_cur_value init 0 k_last_value init 0 k_old_value init 0 k_click init 0 k_maxsig init 0.6 k_maxdur init 1.0 k_thresh init 4.2 k_maxval init 21 ; needs to be observed in each env k_minval init 12 ; needs to be observed in each env k_old_value = k_last_value k_last_value = k_cur_value kax chnget "accelerometerX" kay chnget "accelerometerY" kaz chnget "accelerometerZ" k_cur_value=sqrt(kax*kax+kay*kay+kaz*kaz) kdif1 = k_last_value - k_old_value kdif2 = k_cur_value - k_last_value kdur = (k_click>5000 ? k_maxdur : .1+(k_maxdur-.1)*(k_click-500)/4500) if kdif1>k_thresh && kdif2<0.01 then kval=sqrt(kax*kax+kay*kay+kaz*kaz) kamp = (kval>k_maxval) ? k_maxsig : abs(kval-k_minval)/(k_maxval-k_minval)*k_maxsig event "i",2,0,kdur,kamp k_click=0 else k_click = k_click + 1 ; k_click minimum almost equals to 500 endif endin ; ; sends the signal to the mix channel ; instr 2, MixSignal asig oscil p4*0dbfs, 440, 1 ;printf_i "%f(sec) -- %f\n",1,p3,p4 chnmix asig, "mix" endin ; ; reverbation and send the signal to the outputs ; instr 3, SigalOut asig chnget "mix" kRoomSize chnget "trackpad.x" kHFDamp chnget "trackpad.y" aLin, aRin freeverb asig, asig, kRoomSize, kHFDamp aL clip aLin,2,0dbfs aR clip aRin,2,0dbfs outs aL, aR ; when babo is used ;kx chnget "trackpad.x" ;ky chnget "trackpad.y" ;kxp = 14.39 * kx ;kyp = 11.86 * ky ;aLin, aRin babo asig, kxp, kyp, 3, 14.39, 11.86, 10 ;outs aLin, aRin endin ; ; for mixing ; instr 100, ClearMix chnclear "mix" endin <//CsInstruments> </CsoundSynthesizer>

←csoundメモ 目次へ戻る