diff --git a/example.html b/example.html index 796fbee5..8514a4af 100644 --- a/example.html +++ b/example.html @@ -49,6 +49,11 @@

Options

+
+ + +
+

Commands

@@ -80,7 +85,8 @@

Log

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){ diff --git a/oggopus.js b/oggopus.js index 9e3df299..6c0504e2 100644 --- a/oggopus.js +++ b/oggopus.js @@ -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; @@ -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; diff --git a/recorder.js b/recorder.js index f065b094..05f11820 100755 --- a/recorder.js +++ b/recorder.js @@ -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";