Permalink
Browse files

audio: reverse echo cancel order

* bin: connect to last and first clients
  • Loading branch information...
1 parent efdfe5e commit 54b32ebb7e26e1411e91252c7277ee8b570d6755 @indutny committed Jul 27, 2012
Showing with 20 additions and 12 deletions.
  1. +9 −7 bin/vock
  2. +1 −1 example/delay.js
  3. +5 −3 lib/vock/audio.js
  4. +5 −1 lib/vock/instance.js
View
@@ -24,7 +24,7 @@ function getAddress(addr) {
};
var instance = vock.instance.create(argv),
- api = vock.api.create(getAddress(argv.s || 'api.vock.io:43210'),
+ api = vock.api.create(getAddress(argv.s || 'vock.indutny.com:43210'),
instance);
if (cmd === 'create') {
@@ -39,10 +39,11 @@ if (cmd === 'create') {
api.watch(id, function(err, addrs) {
if (err) throw err;
+ var target = addrs[addrs.length - 1];
console.log('Opponent appeared: '.green + '%s %d',
- addrs[0].address,
- addrs[0].port);
- instance.connect(addrs[0].port, addrs[0].address, function() {
+ target.address,
+ target.port);
+ instance.connect(target.port, target.address, function() {
console.log('Connected!'.green);
});
});
@@ -52,10 +53,11 @@ if (cmd === 'create') {
api.connect(argv._[1], function(err, addrs) {
if (err) throw err;
+ var target = addrs[0];
console.log('Got opponent\'s address: '.green + '%s:%d',
- addrs[0].address,
- addrs[0].port);
- instance.connect(addrs[0].port, addrs[0].address, function() {
+ target.address,
+ target.port);
+ instance.connect(target.port, target.address, function() {
console.log('Connected!'.green);
});
});
View
@@ -4,6 +4,6 @@ var a = new binding.Audio(8000, 960);
a.ondata = function(data) {
setTimeout(function() {
a.enqueue(data);
- }, 1000);
+ }, 2000);
};
a.start();
View
@@ -40,8 +40,7 @@ Audio.prototype.computeGain = function(pcm) {
};
Audio.prototype.start = function start() {
- var self = this,
- waiting = 2;
+ var self = this;
this.audio.ondata = self.ondata.bind(self);
this.audio.start();
@@ -56,7 +55,10 @@ Audio.prototype.stop = function stop() {
Audio.prototype.ondata = function ondata(pcm) {
try {
- if (this.last) pcm = this.audio.cancelEcho(this.last, pcm);
+ if (this.last) {
+ pcm = this.audio.cancelEcho(pcm, this.last);
+ this.last = null;
+ }
this.emit('data', this.opus.encode(pcm));
} catch (e) {
this.emit('error', e);
View
@@ -16,7 +16,7 @@ function Instance(options) {
this.jitter = vock.jitter.create(options.jitterWindow || 50);
// Create audio unit
- this.audio = vock.audio.create(options.rate || 8000);
+ this.audio = vock.audio.create(options.rate || 24000);
this.socket = vock.socket.create();
@@ -84,6 +84,10 @@ Instance.prototype.init = function init(options) {
self.audio.play(data);
});
+ this.audio.on('error', function(err) {
+ self.emit('error', err);
+ });
+
// Propogate errors from protocol to
this.protocol.on('error', function(err) {
self.emit('error', err);

0 comments on commit 54b32eb

Please sign in to comment.