sign = if (f1 >= 0 && f2 >= 0) || (f1 < 0 && f2 < 0)
then 1 else (-1)
-halveFrequency :: Frequency -> Frequency
-halveFrequency freq@(Frequency m o) =
+halveFrequency :: Frequency -> Maybe Frequency
+halveFrequency (Frequency m o) =
if m `mod` 2 == 0
- then Frequency (m `div` 2) (o `div` 2)
- else error $ "Cannot halve frequency " ++ show freq
+ then Just $ Frequency (m `div` 2) (o `div` 2)
+ else Nothing
data Band =
Band Frequency Frequency
wrapContent samplingRate (Band low high, content) =
mergeContent $ undamaged:(damagedPositive ++ damagedNegative)
where
- nyquist = halveFrequency samplingRate
+ nyquist = case halveFrequency samplingRate of
+ Just f -> f
+ Nothing -> error $ "wrapContent cannot halve sampling rate " ++ show samplingRate
numFreqs = nyquist + 1
negNyquist = - nyquist
undamaged = (bandIntersection (Band low high) (Band negNyquist numFreqs), content)
laterBands = if localHigh == newHigh
then []
else wrapBand' (Band 0 (newHigh - samplingRate))
- nyquist = halveFrequency samplingRate
+ nyquist = case halveFrequency samplingRate of
+ Just f -> f
+ Nothing -> error $ "wrapBand cannot halve sampling rate " ++ show samplingRate
numFreqs = nyquist + 1
offsetFrequency = samplingRate `multiplyFrequency` (low `divideFrequency` samplingRate)
newLow = low - offsetFrequency