diff --git a/SdrsDecoder.Cli/Program.cs b/SdrsDecoder.Cli/Program.cs index 4f2537e..642dcb7 100644 --- a/SdrsDecoder.Cli/Program.cs +++ b/SdrsDecoder.Cli/Program.cs @@ -43,6 +43,8 @@ static void Main(string[] args) samples.Add(s); } + var baud = 1200; + //var sr = file.WaveFormat.SampleRate; //var i = 256; @@ -87,7 +89,7 @@ static void Main(string[] args) //} var chain = new PocsagChain( - 1200, + baud, file.WaveFormat.SampleRate, (message) => { diff --git a/SdrsDecoder/Flex/FlexChain.cs b/SdrsDecoder/Flex/FlexChain.cs index e8c6e93..37560e1 100644 --- a/SdrsDecoder/Flex/FlexChain.cs +++ b/SdrsDecoder/Flex/FlexChain.cs @@ -1,6 +1,7 @@ using SdrsDecoder.Support; using System; using System.Collections.Generic; +using System.Numerics; namespace SdrsDecoder.Flex { @@ -20,21 +21,19 @@ public FlexChain(float baud, float sampleRate, Action messageReceiv { this.baud = baud; - + var targetRate = (int)this.baud * 10; + var gcd = (int)BigInteger.GreatestCommonDivisor((BigInteger)sampleRate, (BigInteger)targetRate); - var i = 1; - var d = 1; + // TODO: refactor this stuff - if (baud == 1600) - { - i = 32; - d = 75; - } + int i = targetRate / gcd; + int d = (int)sampleRate / gcd; - if (baud == 3200) + // if I gets too big then filtering / performance becomes an issue + if (i > 100) { - i = 64; - d = 75; + i = 1; + d = 1; } var isr = sampleRate * i; diff --git a/SdrsDecoder/Pocsag/PocsagChain.cs b/SdrsDecoder/Pocsag/PocsagChain.cs index 6144879..ca29a94 100644 --- a/SdrsDecoder/Pocsag/PocsagChain.cs +++ b/SdrsDecoder/Pocsag/PocsagChain.cs @@ -1,5 +1,6 @@ using SdrsDecoder.Support; using System; +using System.Numerics; namespace SdrsDecoder.Pocsag { @@ -20,19 +21,18 @@ public PocsagChain(float baud, float sampleRate, Action messageRece { this.baud = baud; - var i = 1; - var d = 1; + // TODO: refactor this and stuff in flexchain + var targetRate = (int)this.baud * 10; + var gcd = (int)BigInteger.GreatestCommonDivisor((BigInteger)sampleRate, (BigInteger)targetRate); - if (baud == 1200) - { - i = 8; - d = 25; - } + int i = targetRate / gcd; + int d = (int)sampleRate / gcd; - if (baud == 2400) + // if I gets too big then filtering / performance becomes an issue + if (i > 100) { - i = 16; - d = 25; + i = 1; + d = 1; } var isr = sampleRate * i;