changeset 24:daa09aecdc40 default tip

lib: rename phase_shift to sample_shift Instead of tracking the phase shift in signals, we should track the sample shift (i.e., delay) of the signal. The sample shift is a constant regardless of the frequency - unlike phase shift. This simplifies the tracking considerably.
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Thu, 15 Apr 2021 22:26:06 -0400
parents 2d5ae243921c
children
files src/lib/signal.rs src/lib/signal/filesource.rs src/lib/signal/gain.rs src/lib/signal/mixer.rs src/lib/signal/sinusoid.rs
diffstat 5 files changed, 20 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/signal.rs	Wed Jun 10 12:29:27 2020 -0400
+++ b/src/lib/signal.rs	Thu Apr 15 22:26:06 2021 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2020-2021 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -41,8 +41,8 @@
         Self: Sized {
     fn sample_rate(&self) -> u64;
     fn sample_size(&self) -> usize;
+    fn sample_shift(&self) -> u64;
     fn freq(&self) -> u64;
-    fn phase_shift(&self) -> u64;
 
     fn shift_freq(self, delta: i64) -> Mixer<Self, Sinusoid> {
         let rate = self.sample_rate();
--- a/src/lib/signal/filesource.rs	Wed Jun 10 12:29:27 2020 -0400
+++ b/src/lib/signal/filesource.rs	Thu Apr 15 22:26:06 2021 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2020-2021 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -59,13 +59,13 @@
         U::sample_size()
     }
 
+    fn sample_shift(&self) -> u64 {
+        0
+    }
+
     fn freq(&self) -> u64 {
         self.freq
     }
-
-    fn phase_shift(&self) -> u64 {
-        0
-    }
 }
 
 impl<T: BufRead, U: SignalFormatter> Iterator for FileSourceSignal<T, U> {
--- a/src/lib/signal/gain.rs	Wed Jun 10 12:29:27 2020 -0400
+++ b/src/lib/signal/gain.rs	Thu Apr 15 22:26:06 2021 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2020-2021 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -49,13 +49,13 @@
         std::mem::size_of::<IQSample>()
     }
 
+    fn sample_shift(&self) -> u64 {
+        self.lhs.sample_shift()
+    }
+
     fn freq(&self) -> u64 {
         self.lhs.freq()
     }
-
-    fn phase_shift(&self) -> u64 {
-        self.lhs.phase_shift()
-    }
 }
 
 impl<T: Signal> Iterator for Gain<T> {
--- a/src/lib/signal/mixer.rs	Wed Jun 10 12:29:27 2020 -0400
+++ b/src/lib/signal/mixer.rs	Thu Apr 15 22:26:06 2021 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2020-2021 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -56,11 +56,11 @@
         std::mem::size_of::<IQSample>()
     }
 
-    fn freq(&self) -> u64 {
+    fn sample_shift(&self) -> u64 {
         panic!("TODO");
     }
 
-    fn phase_shift(&self) -> u64 {
+    fn freq(&self) -> u64 {
         panic!("TODO");
     }
 }
--- a/src/lib/signal/sinusoid.rs	Wed Jun 10 12:29:27 2020 -0400
+++ b/src/lib/signal/sinusoid.rs	Thu Apr 15 22:26:06 2021 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2020-2021 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -60,13 +60,13 @@
         std::mem::size_of::<IQSample>()
     }
 
+    fn sample_shift(&self) -> u64 {
+        0
+    }
+
     fn freq(&self) -> u64 {
         0 /* the center frequency is always 0 */
     }
-
-    fn phase_shift(&self) -> u64 {
-        0
-    }
 }
 
 impl Iterator for Sinusoid {