Last change
on this file since 28388 was 28388, checked in by davidb, 11 years ago |
Set of JS, CSS, PNG etc web resources to support a mixture of audio player/document display capabilities
|
File size:
1.1 KB
|
Line | |
---|
1 | void function (Sink) {
|
---|
2 |
|
---|
3 | var cubeb;
|
---|
4 |
|
---|
5 | try {
|
---|
6 | cubeb = require('cubeb');
|
---|
7 | } catch (e) {
|
---|
8 | return;
|
---|
9 | }
|
---|
10 |
|
---|
11 | var getContext = function () {
|
---|
12 | var ctx;
|
---|
13 |
|
---|
14 | return function () {
|
---|
15 | ctx = new cubeb.Context(
|
---|
16 | "sink.js " + process.pid + ' ' + new Date()
|
---|
17 | );
|
---|
18 |
|
---|
19 | getContext = function () { return ctx; };
|
---|
20 |
|
---|
21 | return ctx;
|
---|
22 | };
|
---|
23 | }();
|
---|
24 |
|
---|
25 | var streamCount = 0;
|
---|
26 |
|
---|
27 | Sink.sinks('cubeb', function () {
|
---|
28 | var self = this;
|
---|
29 |
|
---|
30 | self.start.apply(self, arguments);
|
---|
31 |
|
---|
32 | self._ctx = getContext();
|
---|
33 | self._stream = new cubeb.Stream(
|
---|
34 | self._ctx,
|
---|
35 | self._ctx.name + ' ' + streamCount++,
|
---|
36 | cubeb.SAMPLE_FLOAT32LE,
|
---|
37 | self.channelCount,
|
---|
38 | self.sampleRate,
|
---|
39 | self.bufferSize,
|
---|
40 | self._latency,
|
---|
41 | function (frameCount) {
|
---|
42 | var buffer = new Buffer(
|
---|
43 | 4 * frameCount * self.channelCount);
|
---|
44 | var soundData = new Float32Array(buffer);
|
---|
45 |
|
---|
46 | self.process(soundData, self.channelCount);
|
---|
47 |
|
---|
48 | self._stream.write(buffer);
|
---|
49 | self._stream.release();
|
---|
50 | },
|
---|
51 | function (state) {}
|
---|
52 | );
|
---|
53 |
|
---|
54 | self._stream.start();
|
---|
55 | }, {
|
---|
56 | _ctx: null,
|
---|
57 | _stream: null,
|
---|
58 | _latency: 250,
|
---|
59 | bufferSize: 4096,
|
---|
60 |
|
---|
61 | kill: function () {
|
---|
62 | this._stream.stop();
|
---|
63 | this.emit('kill');
|
---|
64 | },
|
---|
65 |
|
---|
66 | getPlaybackTime: function () {
|
---|
67 | return this._stream.position;
|
---|
68 | }
|
---|
69 | });
|
---|
70 |
|
---|
71 | }(this.Sink);
|
---|
Note:
See
TracBrowser
for help on using the repository browser.