Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
chiptune by web audio api
Search
hiro-tan
October 13, 2016
Technology
170
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
chiptune by web audio api
hiro-tan
October 13, 2016
More Decks by hiro-tan
See All by hiro-tan
party-night-with-webaudio-api
hirotan
0
250
Getting Started Web Audio API
hirotan
0
190
音色と波形の話
hirotan
0
190
Web Audio API でお手軽10バンドイコライザー
hirotan
1
710
Other Decks in Technology
See All in Technology
【CEDEC2026】『ウマ娘 プリティーダービー』 英語版のキャラクターの方言や口調をローカライズするための創造的アプローチ
cygames
PRO
1
240
【CEDEC2026】グラフィックスエンジニアのためのニューラルシェーディング入門
cygames
PRO
0
140
FDEの心得
noriakioji
3
4.2k
攻撃と防御で学ぶAI時代のプロダクトセキュリティ演習
recruitengineers
PRO
9
2.6k
Head First モブプログラミング / Head First Mobprogramming
takaking22
10
12k
ホームラボ紹介
y_sera15
0
150
LanceDB入門
mocobeta
7
380
DatadogのBits Chatが開発組織にもたらしたもの / What Bits Chat Has Brought Us
sms_tech
1
230
認知負荷をGemini で溶かす — GKE 基盤「Orbit」における AI エージェントの実践
sansantech
PRO
1
290
ラジオの科学
frievea
0
300
Genie Codeハンズオン基礎編
taka_aki
1
110
生成 AI の基礎 〜 サンプル実装で学ぶ基本原理
enakai00
7
4.4k
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Darren the Foodie - Storyboard
khoart
PRO
3
3.6k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
260
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
Un-Boring Meetings
codingconduct
0
380
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
240
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
410
Into the Great Unknown - MozCon
thekraken
41
2.7k
GitHub's CSS Performance
jonrohan
1033
470k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
440
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
Transcript
Web Audio API を使って FC 音源を再現してみる 廣田洋平 @DRECOM
自己紹介 廣田洋平 a.k.a ひろたん ドリコム16 新卒入社 「 ちょこっとファー ム」 サー
バー サイド 好きなジャンルはチップチュー ンとハピコア Web Audio の人と呼ばれるのを目指して修行中
Join us! #2 11/8(tue) @Drecom
Join us! Web Audio API 初心者向けハンズオン 11/6(sun) @ 渋谷ヒカリエ
アジェンダ Web Audio API を使った音作り 波形を選択して音色を変える エンベロー プジェネレー ター を実装する
スイー プを実装する
波形を選択して音色を変える サイン波、 矩形波、 のこぎり波、 三角波の4 種 var audioContext = new
AudioContext(); var oscillator = audioContext.createOscillator(); oscillator.type = "sine" //square, sawtooth, triangle oscillator.connect(audioContext.desination); oscillator.start(0); 簡単に音色を変えられる 4 種以外の波形は選べないほか、4 種の波形も デフォルトから変化させることはできない
ScriptProcessorNode の利用 JavaScript で音声デー タを編集できるノー ド var processor = audioContext.createScriptProcessor(1024);
oscillator.connect(processor); // for iOS processor.onaudioprocess = function(event) { var buffer1 = event.outputBuffer.getChannelData(0); var buffer2 = event.outputBuffer.getChannelData(1); for(var i = 0; i < 1024; i++) { buffer[0] = buffer[1] = (Math.random() - 0.5) * 2; } }); processor.connect(audioContext.destination); onaudioprocess はdestination に接続すると発生
ScriptProceossorNode は廃止予定 代わりにAudioWorker が提案されたが… 実装されているブラウザはない 9 月の初めに仕様から削除 AudioWorklet に置き換えられる予定 しばらくはScriptProcessorNode
を使いましょう
エンベロー プジェネレー ター を実装 エンベロー プジェネレー ター とは? 音量の時間変化を作り出す機能 Attack
, Decay , Sutain , Release の4 つを設定 Attack : 音が鳴り始めかてら最大音量になるまで Decay : 最大音量からSustain までの減衰 Sustain : 音がなっているときの音量レベル Release : 音が鳴り止むまでの減衰 Duration : 音がなっている時間
エンベロー プジェネレー ター を実装 oscillator にgain ノー ドを接続 gain ノー
ドのパラメー ター を時間変化させる setValueAtTime(value, startTime) : startTime にパラメー ター をvalue に設定 linearRampToValueAtTime(value, endTime) : endTime にパラメー ター がvalue になるよう パラメー ター を線形変化 setTargetAtTime(target, startTime, timeConstant) : startTime からtimeConstant 分時間をかけて パラメー ター をtarget に変化
エンベロー プジェネレー ター を実装
エンベロー プジェネレー ター を実装 var t0 = audioContext.currentTime(); var t1
= t0 + attack; var t3 = t0 + duration - release; var envelope = audioContext.createGain(); oscillator.connect(envelope); envelope.connect(audioContext.destination); oscillator.start(t0); envelope.gain.setValueAtTime(0, t0); envelope.gain.linearRampToValueAtTime(1.0, t1); envelope.gain.setTargetAtTime(sustain, t1, decay); envelope.gain.setTargetAtTime(0, t3, release); oscillator.stop(t0 + duration);
スイー プを実装 スイー プとは? 周波数を一定速度で変化させること SweepSwitch : off , positive
, negative の3 種 SweepTime : 周波数を変化させる時間 バスドラムの音を再現するには 急激に周波数を上下させる
スイー プを実装 周波数はoscillator ノー ドのパラメー ター で設定 var current =
oscillator.frequency.value; switch (sweepSwitch) { case positive: oscillator.frequency.setValueAtTime(current * 1.8, sweepTime); break; case negative: oscillator.frequency.setValueAtTime(current * 0.2, sweepTime); break; default: }
参考資料 チップチュー ンを作ってみよう! ドラム音色エディット編 -- くりおぺ http://www.tsurishi.info/chiptune-neiro-edit-drum/ WEB SOUNDER http://curtaincall.weblike.jp/portfolio-web-sounder/