Created
August 27, 2014 09:16
-
-
Save niusounds/b359389e8f6493d29f50 to your computer and use it in GitHub Desktop.
WebAudio + WebRTC (getUserMedia) + AngularJS sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="myApp"> | |
<head> | |
<title>HelloAudio</title> | |
</head> | |
<body ng-controller="Main"> | |
<input type="range" min="20" max="4000" ng-model="hz.value" step="0.01"> | |
<input type="range" min="0" max="1" ng-model="gain.value" step="0.01"> | |
<script src="angular.min.js"></script> | |
<script src="window.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myApp', []).factory('audioContext', function() { | |
return new AudioContext(); | |
}).factory('getUserMedia', function($window) { | |
return function(opts) { | |
return new Promise(function(resolve, reject) { | |
$window.navigator.webkitGetUserMedia(opts, resolve, reject); | |
}); | |
}; | |
}).controller('Main', function($scope, audioContext, getUserMedia) { | |
getUserMedia({ | |
audio: true | |
}).then(function(stream) { | |
// mic in | |
var source = audioContext.createMediaStreamSource(stream); | |
var filter = audioContext.createBiquadFilter(); | |
filter.frequency.value = 200; | |
filter.type = 'highpass'; | |
var gain = audioContext.createGain(); | |
gain.gain.value = 0; | |
source.connect(filter); | |
filter.connect(gain); | |
gain.connect(audioContext.destination); | |
$scope.hz = filter.frequency; | |
$scope.gain = gain.gain; | |
$scope.$apply(); | |
}, function(err) { | |
console.log(err) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment