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

잔글 (로봇: 자동으로 텍스트 교체 (-http://jmnote.com/js/ +http://zetawiki.com/ex/js/))
2번째 줄: 2번째 줄:


==예시==
==예시==
*예제: http://jmnote.com/js/oscillator.php
*예제: http://zetawiki.com/ex/js/oscillator.php
<source lang='php'>
<source lang='php'>
<?php
<?php

2015년 7월 15일 (수) 01:03 판

HTML5 Audio Oscillator 실습

1 예시

<?php
$buttons = array(
	array('label'=>'C', 'hz'=>'262'),
	array('label'=>'D', 'hz'=>'294'),
	array('label'=>'E', 'hz'=>'330'),
	array('label'=>'F', 'hz'=>'349'),
	array('label'=>'G', 'hz'=>'392'),
	array('label'=>'A', 'hz'=>'440'),
	array('label'=>'B', 'hz'=>'494'),
	array('label'=>'C', 'hz'=>'523'),
);
foreach($buttons as $button) {
	echo "<button onclick='play_oscillator(${button['hz']})'>${button['label']}</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 }}