@@ 517,7 517,32 @@ structure SpectralPeakPick = struct
f1
}
end
-
+
+ (** Convert a list of bands, constraining their bins to the range
+ 0..count-1 and omitting any that are entirely outside that
+ range.
+ *)
+ fun mapBands { rate, n, count } (bands : band list)
+ : SubBandPeakPick.band list =
+ List.concat
+ (map (fn band =>
+ let val mapped = mapBand { rate = rate, n = n } band
+ in
+ if #start mapped >= count
+ then []
+ else case #count mapped of
+ NONE => [mapped]
+ | SOME bc =>
+ if #start mapped + bc > count
+ then [{ p = #p mapped,
+ start = #start mapped,
+ count = NONE
+ }
+ ]
+ else [mapped]
+ end)
+ bands)
+
(** Return a list of indices of local peaks within the vector,
dividing it up into sub-bands following the given band
list. The parameter n is the number of bins, used for
@@ 531,7 556,10 @@ structure SpectralPeakPick = struct
} (v : RealVector.vector)
: int list =
SubBandPeakPick.findPeaks {
- bands = map (mapBand { rate = rate, n = n }) bands
+ bands = mapBands { rate = rate,
+ n = n,
+ count = RealVector.length v
+ } bands
} v
(** Return a list of indices of local peaks within the vector,
@@ 545,7 573,10 @@ structure SpectralPeakPick = struct
} (v : RealVector.vector)
: int list =
SubBandPeakPick.findPeaksSnapped {
- bands = map (mapBand { rate = rate, n = n }) bands,
+ bands = mapBands { rate = rate,
+ n = n,
+ count = RealVector.length v
+ } bands,
resolveDownwards = resolveDownwards
} v