使用JavaScript和HTML5创建音量控制
我很难理解讲师给我的作业。他给我们提供了一个程序,该程序应该是从计算机麦克风录音,并告诉我们,为它建立一个音量控制,控制扬声器的分贝。这让我很困惑,因为据我所知,这个节目中没有扬声器使用JavaScript和HTML5创建音量控制,javascript,html,Javascript,Html,我很难理解讲师给我的作业。他给我们提供了一个程序,该程序应该是从计算机麦克风录音,并告诉我们,为它建立一个音量控制,控制扬声器的分贝。这让我很困惑,因为据我所知,这个节目中没有扬声器 <html> <head> <title>Audio Renderer -chrome</title> <style> </style> </head> <body> <h1&
<html>
<head>
<title>Audio Renderer -chrome</title>
<style>
</style>
</head>
<body>
<h1>HTML5 webmic-Renderer </h1>
<h4>Chrome</h4>
<pre id="preLog">Access to micro</pre>
<p>
<input type="button" id="buttonStart" value="Start" onclick="start()" />
<input type="button" id="buttonStop" value="Stop" onclick="stop()" />
</p>
<script>
var audioContext = new webkitAudioContext();
var realAudioInput = null;
var preLog ;
var zeroGain;
var channel = 2;
var bufferSize =1024;
function log(text){
preLog = document.getElementById('preLog');
if (preLog) preLog.textContent += ('\n' + text);
else alert(text);
}
function start() {
log('Get user media..');
if (navigator.webkitGetUserMedia) navigator.webkitGetUserMedia({audio:true}, gotStream, noStream);
else log('getUserMedia() not available from your Web browser!');
}
function noStream() {
log('Access to Micro was denied!');
}
function gotStream(stream) {
log('Access to Micro was started');
// Create an AudioNode from the stream.
realAudioInput = audioContext.createMediaStreamSource(stream);
// Create an GainNode .
zeroGain = audioContext.createGain();
zeroGain.gain.value = 1.0;
// create an audio node with 2 input and 1 output channels, and 1024 byte buffer size per audio frame
jsNode = audioContext.createScriptProcessor(bufferSize, channel, channel-1);
jsNode.onaudioprocess = audioProcess;
// Signal Graph
realAudioInput.connect( jsNode );
// zeroGain.connect(??);
jsNode.connect( audioContext.destination );
}
function stop() {
log('Access to Micro stopped');
realAudioInput.disconnect(0);
}
// this function is called every audio frame
function audioProcess(event) {
var sampleIn_l = event.inputBuffer.getChannelData(channel-2); // Stereo: 0 = left channel, 1 = right channel
var sampleIn_r = event.inputBuffer.getChannelData(channel-1);
var sampleOut = event.outputBuffer.getChannelData(channel-2);
// loop through every sample and add sample values to out buffer
for(i = 0; i < event.inputBuffer.length; i++) {
var sample_l = sampleIn_l[i] ;
var sample_r = sampleIn_r[i] ;
sampleOut[i] = ( sample_l );
}
}
</script>
</body>
</html>
在他的作业中说:为节目音频渲染器创建一个节点级扬声器的交互式音量控制:zeroGain.gain.value=1.0;
我只是不明白他想从我们这里得到什么。如果有人能帮助我,我将非常高兴:
非常感谢您的阅读 这不是一个你的讲师能够最好地回答的问题吗?是和否。一个好的讲师应该能够做到这一点,问题是他从不以有帮助的方式回答我们的任何问题。我们以前试过。。。很多次。另外,我还要一个星期才能见到他,邮件回复来得很慢,如果有的话。问题是这是关于工作本身的性质,而不是一个具体的编程问题,因此不太适合StackOverflow。是的,我几乎猜到了。我只是希望有人会发现我在看代码时看不到的明显的东西,因为我刚开始使用JavaScript,我认为问题可能只是我对赋值的理解,或者缺少理解。