123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- #ifndef MODULES_AUDIO_CODING_NETEQ_EXPAND_H_
- #define MODULES_AUDIO_CODING_NETEQ_EXPAND_H_
- #include <assert.h>
- #include <memory>
- #include "modules/audio_coding/neteq/audio_vector.h"
- #include "rtc_base/constructor_magic.h"
- namespace webrtc {
- class AudioMultiVector;
- class BackgroundNoise;
- class RandomVector;
- class StatisticsCalculator;
- class SyncBuffer;
- class Expand {
- public:
- Expand(BackgroundNoise* background_noise,
- SyncBuffer* sync_buffer,
- RandomVector* random_vector,
- StatisticsCalculator* statistics,
- int fs,
- size_t num_channels);
- virtual ~Expand();
-
- virtual void Reset();
-
-
- virtual int Process(AudioMultiVector* output);
-
-
- virtual void SetParametersForNormalAfterExpand();
-
-
- virtual void SetParametersForMergeAfterExpand();
-
- int16_t MuteFactor(size_t channel) const {
- assert(channel < num_channels_);
- return channel_parameters_[channel].mute_factor;
- }
-
-
- bool Muted() const;
-
- virtual size_t overlap_length() const;
- size_t max_lag() const { return max_lag_; }
- protected:
- static const int kMaxConsecutiveExpands = 200;
- void GenerateRandomVector(int16_t seed_increment,
- size_t length,
- int16_t* random_vector);
-
- void InitializeForAnExpandPeriod();
- bool TooManyExpands();
-
-
- void AnalyzeSignal(int16_t* random_vector);
- RandomVector* const random_vector_;
- SyncBuffer* const sync_buffer_;
- bool first_expand_;
- const int fs_hz_;
- const size_t num_channels_;
- int consecutive_expands_;
- private:
- static const size_t kUnvoicedLpcOrder = 6;
- static const size_t kNumCorrelationCandidates = 3;
- static const size_t kDistortionLength = 20;
- static const size_t kLpcAnalysisLength = 160;
- static const size_t kMaxSampleRate = 48000;
- static const int kNumLags = 3;
- struct ChannelParameters {
- ChannelParameters();
- int16_t mute_factor;
- int16_t ar_filter[kUnvoicedLpcOrder + 1];
- int16_t ar_filter_state[kUnvoicedLpcOrder];
- int16_t ar_gain;
- int16_t ar_gain_scale;
- int16_t voice_mix_factor;
- int16_t current_voice_mix_factor;
- AudioVector expand_vector0;
- AudioVector expand_vector1;
- bool onset;
- int mute_slope;
- };
-
-
-
- void Correlation(const int16_t* input,
- size_t input_length,
- int16_t* output) const;
- void UpdateLagIndex();
- BackgroundNoise* const background_noise_;
- StatisticsCalculator* const statistics_;
- const size_t overlap_length_;
- size_t max_lag_;
- size_t expand_lags_[kNumLags];
- int lag_index_direction_;
- int current_lag_index_;
- bool stop_muting_;
- size_t expand_duration_samples_;
- std::unique_ptr<ChannelParameters[]> channel_parameters_;
- RTC_DISALLOW_COPY_AND_ASSIGN(Expand);
- };
- struct ExpandFactory {
- ExpandFactory() {}
- virtual ~ExpandFactory() {}
- virtual Expand* Create(BackgroundNoise* background_noise,
- SyncBuffer* sync_buffer,
- RandomVector* random_vector,
- StatisticsCalculator* statistics,
- int fs,
- size_t num_channels) const;
- };
- }
- #endif
|