Adding 16 bit LFSR , to Noise Signal Generator App

This commit is contained in:
Brumi-2021
2023-05-02 17:19:23 +02:00
parent 06643df6a5
commit d5f20c45b9
3 changed files with 37 additions and 21 deletions

View File

@@ -75,6 +75,17 @@ void SigGenProcessor::execute(const buffer_c8_t& buffer) {
bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 4)) & 1;
lfsr = (lfsr >> 1) | (bit << 7);
sample = lfsr;
} else if (tone_shape == 9) { // 16 bits LFSR .taps: 16, 15, 13, 4 ;feedback polynomial: x^16 + x^15 + x^13 + x^4 + 1
// Periode 65535= 2^n-1, harmonics every < 1Khz , quite continuous .
if (counter == 0) {
bit_16 = ((lfsr_16 >> 0) ^ (lfsr_16 >> 1) ^ (lfsr_16 >> 3) ^ (lfsr_16 >> 4) ^ (lfsr_16 >> 12) & 1);
lfsr_16 = (lfsr_16 >> 1) | (bit_16 << 15);
sample = (lfsr_16 & 0x00FF);
counter++;
} else { // counter == 1 , no need to shift the register again, just use the top 8 bits.
// sample = ((lfsr_16 & 0XFF00) >> 8); // it becomes less continuous the spectrum. Better skip it .
counter = 0;
}
}
if (tone_shape < 6) {
@@ -114,8 +125,8 @@ void SigGenProcessor::on_message(const Message* const msg) {
fm_delta = message.bw * (0xFFFFFFULL / 1536000);
tone_shape = message.shape;
// lfsr = 0x54DF0119;
lfsr = seed_value ;
lfsr = seed_value ; // init lfsr 8 bits.
lfsr_16 = seed_value_16; // init lfsr 16 bits.
configured = true;
break;

View File

@@ -44,9 +44,12 @@ private:
bool auto_off { };
int32_t phase { 0 }, sphase { 0 }, delta { 0 }; // they may have sign .
int8_t sample { 0 }, re { 0 }, im { 0 }; // they may have sign .
uint8_t seed_value = {0x56}; // seed : any nonzero start state will work.
uint8_t seed_value = {0x56}; // seed 8 bits lfsr : any nonzero start state will work.
uint16_t seed_value_16 = {0xACE1}; // seed 16 bits lfsr : any nonzero start state will work.
uint8_t lfsr { }, bit { }; // bit must be 8-bit to allow bit<<7 later in the code */
uint16_t lfsr_16 { }, bit_16 { }; // bit must be 8-bit to allow bit<<7 later in the code */
uint8_t counter {0};
TXProgressMessage txprogress_message { };
};