"HTML5 Audio Oscillator 실습"의 두 판 사이의 차이

 
36번째 줄: 36번째 줄:
</script>
</script>
</source>
</source>
<jsfiddle height='400'>h37reLcj</jsfiddle>
<jsfiddle height='300'>h37reLcj</jsfiddle>


==같이 보기==
==같이 보기==

2017년 3월 30일 (목) 17:21 기준 최신판

1 개요[ | ]

HTML5 Audio Oscillator 실습
<style>
button { width: 100px; height: 50px; }
</style>

<button onclick='play_oscillator(262)'>C ( 262 Hz )</button>
<button onclick='play_oscillator(294)'>D ( 294 Hz )</button>
<button onclick='play_oscillator(330)'>E ( 330 Hz )</button>
<button onclick='play_oscillator(349)'>F ( 349 Hz )</button>
<button onclick='play_oscillator(392)'>G ( 392 Hz )</button>
<button onclick='play_oscillator(440)'>A ( 440 Hz )</button>
<button onclick='play_oscillator(494)'>B ( 494 Hz )</button>
<button onclick='play_oscillator(523)'>C ( 523 Hz )</button>

<script>
  try {
    window.AudioContext = window.AudioContext || window.webkitAudioContext;
    var context = new AudioContext();
  } catch (err) {
    alert('이 브라우저는 Web Audio API를 지원하지 않습니다.');
  }

  function play_oscillator(hz, seconds) {
    if (seconds == undefined) seconds = 1;

    var osc = context.createOscillator();
    osc.type = 'square';
    osc.frequency.value = parseInt(hz);
    osc.connect(context.destionation);
    osc.start(context.currentTime + 0);
    osc.stop(context.currentTime + seconds);
  }
</script>

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}