annotate carfac/sai.h @ 654:a1b82b240328

Rename variables to be consistent with the rest of the library.
author ronw@google.com
date Thu, 27 Jun 2013 15:30:46 +0000
parents f926e0892dee
children
rev   line source
ronw@642 1 // Copyright 2013, Google, Inc.
ronw@642 2 // Author: Ron Weiss <ronw@google.com>
ronw@642 3 //
ronw@642 4 // This C++ file is part of an implementation of Lyon's cochlear model:
ronw@642 5 // "Cascade of Asymmetric Resonators with Fast-Acting Compression"
ronw@642 6 // to supplement Lyon's upcoming book "Human and Machine Hearing"
ronw@642 7 //
ronw@642 8 // Licensed under the Apache License, Version 2.0 (the "License");
ronw@642 9 // you may not use this file except in compliance with the License.
ronw@642 10 // You may obtain a copy of the License at
ronw@642 11 //
ronw@642 12 // http://www.apache.org/licenses/LICENSE-2.0
ronw@642 13 //
ronw@642 14 // Unless required by applicable law or agreed to in writing, software
ronw@642 15 // distributed under the License is distributed on an "AS IS" BASIS,
ronw@642 16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ronw@642 17 // See the License for the specific language governing permissions and
ronw@642 18 // limitations under the License.
ronw@642 19
ronw@642 20 #ifndef CARFAC_SAI_H_
ronw@642 21 #define CARFAC_SAI_H_
ronw@642 22
ronw@642 23 #include <vector>
ronw@642 24
alexbrandmeyer@643 25 #include "common.h"
ronw@642 26
ronw@642 27 // Design parameters for a single SAI.
ronw@642 28 struct SAIParams {
ronw@642 29 // Number of channels (height) of the SAI.
ronw@654 30 int num_channels;
ronw@642 31
ronw@642 32 // TODO(ronw): Consider parameterizing this as past_lags and
ronw@642 33 // future_lags, with width == past_lags + 1 + future_lags.
ronw@642 34 //
ronw@642 35 // Total width (i.e. number of lag samples) of the SAI.
ronw@642 36 int width;
ronw@642 37 // Number of lag samples that should come from the future.
ronw@642 38 int future_lags;
ronw@642 39 // Number of windows (triggers) to consider during each SAI frame.
ronw@654 40 int num_window_pos;
ronw@642 41
ronw@642 42 // TODO(ronw): more carefully define terms "window" and "frame"
ronw@642 43
ronw@642 44 // Size of the window to compute.
ronw@642 45 int window_width;
ronw@642 46
ronw@642 47 FPType channel_smoothing_scale;
ronw@642 48 };
ronw@642 49
ronw@642 50 class SAI {
ronw@642 51 public:
ronw@642 52 explicit SAI(const SAIParams& params);
ronw@642 53
ronw@650 54 // Reinitialize using the specified parameters.
ronw@650 55 void Redesign(const SAIParams& params);
ronw@650 56
ronw@650 57 // Reset the internal state.
ronw@650 58 void Reset();
ronw@650 59
ronw@654 60 // Fills output_frame with a params_.num_channels by params_.width SAI frame
ronw@642 61 // computed from the given input frames.
ronw@642 62 //
ronw@642 63 // The input should have dimensionality of params_.window_width by
ronw@654 64 // params_.num_channels. Inputs containing too few frames are zero-padded.
alexbrandmeyer@643 65 // FIXME: ArrayXX input type would be less awkward.
alexbrandmeyer@643 66 void RunSegment(const std::vector<ArrayX>& input,
alexbrandmeyer@643 67 ArrayXX* output_output_frame);
ronw@642 68
ronw@642 69 private:
ronw@649 70 // Processes successive windows within input_buffer, choose trigger
ronw@642 71 // points, and blend each window into output_buffer.
alexbrandmeyer@643 72 void StabilizeSegment(const ArrayXX& input_buffer,
alexbrandmeyer@643 73 ArrayXX* output_buffer) const;
ronw@642 74
ronw@642 75 SAIParams params_;
ronw@642 76 // Window function to apply before selecting a trigger point.
ronw@642 77 // Size: params_.window_width.
alexbrandmeyer@643 78 ArrayX window_;
ronw@642 79 // Buffer to store a large enough window of input frames to compute
ronw@654 80 // a full SAI frame. Size: params_.num_channels by params_.buffer_width.
alexbrandmeyer@643 81 ArrayXX input_buffer_;
ronw@654 82 // Output frame buffer. Size: params_.num_channels by params_.width.
alexbrandmeyer@643 83 ArrayXX output_buffer_;
ronw@642 84 };
ronw@642 85
ronw@646 86 #endif // CARFAC_SAI_H_