ronw@642: // Copyright 2013, Google, Inc. ronw@642: // Author: Ron Weiss ronw@642: // ronw@642: // This C++ file is part of an implementation of Lyon's cochlear model: ronw@642: // "Cascade of Asymmetric Resonators with Fast-Acting Compression" ronw@642: // to supplement Lyon's upcoming book "Human and Machine Hearing" ronw@642: // ronw@642: // Licensed under the Apache License, Version 2.0 (the "License"); ronw@642: // you may not use this file except in compliance with the License. ronw@642: // You may obtain a copy of the License at ronw@642: // ronw@642: // http://www.apache.org/licenses/LICENSE-2.0 ronw@642: // ronw@642: // Unless required by applicable law or agreed to in writing, software ronw@642: // distributed under the License is distributed on an "AS IS" BASIS, ronw@642: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ronw@642: // See the License for the specific language governing permissions and ronw@642: // limitations under the License. ronw@642: ronw@642: #ifndef CARFAC_SAI_H_ ronw@642: #define CARFAC_SAI_H_ ronw@642: ronw@642: #include ronw@642: alexbrandmeyer@643: #include "common.h" ronw@642: ronw@642: // Design parameters for a single SAI. ronw@642: struct SAIParams { ronw@642: // Number of channels (height) of the SAI. ronw@654: int num_channels; ronw@642: ronw@642: // TODO(ronw): Consider parameterizing this as past_lags and ronw@642: // future_lags, with width == past_lags + 1 + future_lags. ronw@642: // ronw@642: // Total width (i.e. number of lag samples) of the SAI. ronw@642: int width; ronw@642: // Number of lag samples that should come from the future. ronw@642: int future_lags; ronw@642: // Number of windows (triggers) to consider during each SAI frame. ronw@654: int num_window_pos; ronw@642: ronw@642: // TODO(ronw): more carefully define terms "window" and "frame" ronw@642: ronw@642: // Size of the window to compute. ronw@642: int window_width; ronw@642: ronw@642: FPType channel_smoothing_scale; ronw@642: }; ronw@642: ronw@642: class SAI { ronw@642: public: ronw@642: explicit SAI(const SAIParams& params); ronw@642: ronw@650: // Reinitialize using the specified parameters. ronw@650: void Redesign(const SAIParams& params); ronw@650: ronw@650: // Reset the internal state. ronw@650: void Reset(); ronw@650: ronw@654: // Fills output_frame with a params_.num_channels by params_.width SAI frame ronw@642: // computed from the given input frames. ronw@642: // ronw@642: // The input should have dimensionality of params_.window_width by ronw@654: // params_.num_channels. Inputs containing too few frames are zero-padded. alexbrandmeyer@643: // FIXME: ArrayXX input type would be less awkward. alexbrandmeyer@643: void RunSegment(const std::vector& input, alexbrandmeyer@643: ArrayXX* output_output_frame); ronw@642: ronw@642: private: ronw@649: // Processes successive windows within input_buffer, choose trigger ronw@642: // points, and blend each window into output_buffer. alexbrandmeyer@643: void StabilizeSegment(const ArrayXX& input_buffer, alexbrandmeyer@643: ArrayXX* output_buffer) const; ronw@642: ronw@642: SAIParams params_; ronw@642: // Window function to apply before selecting a trigger point. ronw@642: // Size: params_.window_width. alexbrandmeyer@643: ArrayX window_; ronw@642: // Buffer to store a large enough window of input frames to compute ronw@654: // a full SAI frame. Size: params_.num_channels by params_.buffer_width. alexbrandmeyer@643: ArrayXX input_buffer_; ronw@654: // Output frame buffer. Size: params_.num_channels by params_.width. alexbrandmeyer@643: ArrayXX output_buffer_; ronw@642: }; ronw@642: ronw@646: #endif // CARFAC_SAI_H_