return v.s;
}
+
+/*
+ * Compute a nextband map to be used with SF delta constraint utilities.
+ * The nextband array should contain 128 elements, and positions that don't
+ * map to valid, nonzero bands of the form w*16+g (with w being the initial
+ * window of the window group, only) are left indetermined.
+ */
+static inline void ff_init_nextband_map(const SingleChannelElement *sce, uint8_t *nextband)
+{
+ unsigned char prevband = 0;
+ int w, g;
+ /** Just a safe default */
+ for (g = 0; g < 128; g++)
+ nextband[g] = g;
+
+ /** Now really navigate the nonzero band chain */
+ for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
+ for (g = 0; g < sce->ics.num_swb; g++) {
+ if (!sce->zeroes[w*16+g] && sce->band_type[w*16+g] < RESERVED_BT)
+ prevband = nextband[prevband] = w*16+g;
+ }
+ }
+ nextband[prevband] = prevband; /* terminate */
+}
+
+/*
+ * Updates nextband to reflect a removed band (equivalent to
+ * calling ff_init_nextband_map after marking a band as zero)
+ */
+static inline void ff_nextband_remove(uint8_t *nextband, int prevband, int band)
+{
+ nextband[prevband] = nextband[band];
+}
+
+/*
+ * Checks whether the specified band could be removed without inducing
+ * scalefactor delta that violates SF delta encoding constraints.
+ * prev_sf has to be the scalefactor of the previous nonzero, nonspecial
+ * band, in encoding order, or negative if there was no such band.
+ */
+static inline int ff_sfdelta_can_remove_band(const SingleChannelElement *sce,
+ const uint8_t *nextband, int prev_sf, int band)
+{
+ return prev_sf >= 0
+ && sce->sf_idx[nextband[band]] >= (prev_sf - SCALE_MAX_DIFF)
+ && sce->sf_idx[nextband[band]] <= (prev_sf + SCALE_MAX_DIFF);
+}
+
+/*
+ * Checks whether the specified band's scalefactor could be replaced
+ * with another one without violating SF delta encoding constraints.
+ * prev_sf has to be the scalefactor of the previous nonzero, nonsepcial
+ * band, in encoding order, or negative if there was no such band.
+ */
+static inline int ff_sfdelta_can_replace(const SingleChannelElement *sce,
+ const uint8_t *nextband, int prev_sf, int new_sf, int band)
+{
+ return new_sf >= (prev_sf - SCALE_MAX_DIFF)
+ && new_sf <= (prev_sf + SCALE_MAX_DIFF)
+ && sce->sf_idx[nextband[band]] >= (new_sf - SCALE_MAX_DIFF)
+ && sce->sf_idx[nextband[band]] <= (new_sf + SCALE_MAX_DIFF);
+}
+
#define ERROR_IF(cond, ...) \
if (cond) { \
av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \