Skip to content

Commit

Permalink
quick demo of configurable bitrate
Browse files Browse the repository at this point in the history
  • Loading branch information
lepinsk committed Apr 24, 2015
1 parent b4a1632 commit f0802b2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
8 changes: 7 additions & 1 deletion example.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ <h2>Options</h2>
<input id="sampleRate" type="number" value="48000" />
</div>

<div>
<label>bitRate</label>
<input id="bitRate" type="number" value="72000" />
</div>

<h2>Commands</h2>
<button id="init">init</button>
<button id="start" disabled>start</button>
Expand Down Expand Up @@ -80,7 +85,8 @@ <h2>Log</h2>
numberOfChannels: numberOfChannels.value,
bitDepth: bitDepth.options[ bitDepth.selectedIndex ].value,
recordOpus: recordOpus.checked,
sampleRate: sampleRate.value
sampleRate: sampleRate.value,
bitRate: bitRate.value
});

recorder.addEventListener( "start", function(e){
Expand Down
27 changes: 27 additions & 0 deletions oggopus.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var OggOpus = function( config ){
this.maxBuffersPerPage = config.recordOpus.maxBuffersPerPage || 40; // Limit latency for streaming
this.encoderApplication = config.recordOpus.encoderApplication || 2049; // 2048 = Voice, 2049 = Full Band Audio, 2051 = Restricted Low Delay
this.encoderFrameSize = config.recordOpus.encoderFrameSize || 20; // 20ms frame
this.bitRate = config.bitRate;
this.wavepcm = new WavePCM( config );

this.pageIndex = 0;
Expand Down Expand Up @@ -139,6 +140,32 @@ OggOpus.prototype.initChecksumTable = function(){

OggOpus.prototype.initCodec = function() {
this.encoder = _opus_encoder_create( this.outputSampleRate, this.numberOfChannels, this.encoderApplication, allocate(4, 'i32', ALLOC_STACK) );

var bitrateLocation = _malloc(4);
HEAP32[bitrateLocation >>> 2] = this.bitRate;
_opus_encoder_ctl(
this.encoder,
4002, // OPUS_SET_BITRATE_REQUEST
bitrateLocation)
;
_free(bitrateLocation);


var resultLocation = _malloc(4);
var resultLocationLocation = _malloc(4);
HEAP32[resultLocationLocation >>> 2] = resultLocation;

_opus_encoder_ctl(
this.encoder,
4003, // OPUS_GET_BITRATE_REQUEST
resultLocationLocation
);

var result = HEAPU32[resultLocation >>> 2];
_free(resultLocationLocation);
_free(resultLocation);
console.log("OPUS_GET_BITRATE=" + result);

this.encoderBufferIndex = 0;
this.encoderSamplesPerChannelPerPacket = this.outputSampleRate * this.encoderFrameSize / 1000;
this.encoderBufferLength = this.encoderSamplesPerChannelPerPacket * this.numberOfChannels;
Expand Down
3 changes: 2 additions & 1 deletion recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ Recorder.prototype.start = function(){
inputSampleRate: this.audioContext.sampleRate,
numberOfChannels: this.config.numberOfChannels,
outputSampleRate: this.config.sampleRate,
recordOpus: this.config.recordOpus
recordOpus: this.config.recordOpus,
bitRate: this.config.bitRate
});

this.state = "recording";
Expand Down

0 comments on commit f0802b2

Please sign in to comment.