diff --git a/cpp/car.h b/cpp/car.h index 435d928..76fc69b 100644 --- a/cpp/car.h +++ b/cpp/car.h @@ -35,7 +35,7 @@ struct CARParams { first_pole_theta = 0.85 * M_PI; zero_ratio = sqrt(2.0); high_f_damping_compression = 0.5; - erb_per_step = 0.5; + erb_per_step = 0.35; min_pole_hz = 30; erb_break_freq = 165.3; // The Greenwood map's break frequency in Hertz. // Glassberg and Moore's high-cf ratio. diff --git a/cpp/carfac.html b/cpp/carfac.html index a855ab7..cd40f57 100644 --- a/cpp/carfac.html +++ b/cpp/carfac.html @@ -8,19 +8,13 @@ console.log("sampleRate = " + context.sampleRate); console.assert(context.sampleRate == 44100); - // Use as a (not very good) anti-aliasing filter. - antiAliasFilterNode = context.createBiquadFilter(); - antiAliasFilterNode.type = "lowpass"; - antiAliasFilterNode.frequency = 8000; // Hertz. - antiAliasFilterNode.Q = 1; - - InitInputNodes(context, antiAliasFilterNode); // Control the input level with a slider. - gainNode = context.createGainNode(); + gainNode = context.createGain(); document.getElementById('input_gain').onchange = - function () { gainNode.gain.value = this.value; }; - antiAliasFilterNode.connect(gainNode); + function () { gainNode.gain.value = Math.pow(this.value, 3); }; + + InitInputNodes(context, gainNode); saiNode = CreateSAINode(context); gainNode.connect(saiNode); @@ -29,6 +23,11 @@ saiNode.connect(context.destination); } +navigator.getUserMedia = ( navigator.getUserMedia || + navigator.webkitGetUserMedia || + navigator.mozGetUserMedia || + navigator.msGetUserMedia); + function InitInputNodes(context, antiAliasFilterNode) { var inputNodes = [ context.createMediaElementSource(document.getElementById('test_audio')), @@ -36,18 +35,22 @@ ]; inputNodes[0].connect(antiAliasFilterNode); - navigator.webkitGetUserMedia( - {audio: true}, - function(e) { - // Microphone input available. - inputNodes[1] = context.createMediaStreamSource(e); - }, - function(e) { - // Microphone input unavailable. - console.log(e); - alert('Error accessing microphone:\n' + e); - }); - + if (navigator.getUserMedia) { + navigator.getUserMedia( + {audio: true}, + function(e) { + // Microphone input available. + inputNodes[1] = context.createMediaStreamSource(e); + }, + function(e) { + // Microphone input unavailable. + console.log(e); + alert('Error accessing microphone:\n' + e); + }); + } else { + console.log("getUserMedia not supported"); + } + // Input selector controls. function selectInputNode(i) { inputNodes[1 - i].disconnect(); diff --git a/cpp/emscripten_bindings.cc b/cpp/emscripten_bindings.cc index 4e3fdea..78bc7f0 100644 --- a/cpp/emscripten_bindings.cc +++ b/cpp/emscripten_bindings.cc @@ -47,11 +47,11 @@ class SAIPlotter { carfac_output_buffer_.reset(new CARFACOutput(true, false, false, false)); sai_params_.num_channels = carfac_->num_channels(); - sai_params_.sai_width = num_samples_per_segment; - sai_params_.input_segment_width = num_samples_per_segment; - sai_params_.trigger_window_width = sai_params_.input_segment_width + 1; + sai_params_.sai_width = num_samples_per_segment / 2; + sai_params_.input_segment_width = num_samples_per_segment / 2; + sai_params_.trigger_window_width = sai_params_.input_segment_width * 2 + 1; // Half of the SAI should come from the future. - sai_params_.future_lags = sai_params_.sai_width / 2; + sai_params_.future_lags = sai_params_.sai_width; sai_params_.num_triggers_per_frame = 2; sai_.reset(new SAI(sai_params_));