void channel_mask_splits(struct i_array *counts, unsigned int channel_count, unsigned int channel_mask) { /*Although the WAVEFORMATEXTENSIBLE channel mask supports more left/right channels than these, everything beyond side-left/side-right is stored with a center channel in-between which means we can't pull them apart in pairs.*/ unsigned int masks[] = {0x3, 0x1, 0x2, /*fLfR, fL, fR*/ 0x4, 0x8, /*fC, LFE*/ 0x30, 0x10, 0x20, /*bLbR, bL, bR*/ 0xC0, 0x40, 0x80, /*fLoC, fRoC, fLoC, fRoC*/ 0x100, /*bC*/ 0x600, 0x200, 0x400, /*sLsR, sL, sR*/ 0}; unsigned int channels; int i; assert(channel_count > 0); /*first, try to pull left/right channels out of the mask*/ for (i = 0; channel_mask && masks[i]; i++) { if (channel_mask & masks[i]) { channels = count_one_bits(masks[i]); ia_append(counts, channels); channel_count -= channels; channel_mask ^= masks[i]; } } /*any leftover channels are sent out in separate blocks (which may happen with a mask of 0)*/ for (; channel_count > 0; channel_count--) { ia_append(counts, 1); } }
static int build_array(char *plink_dir) { int err; DIR *dp; struct dirent *de; char *p; ino_t ino; err = access(plink_dir, F_OK); if (err) return 0; err = 0; dp = opendir(plink_dir); if (!dp) AuFin("%s", plink_dir); while ((de = readdir(dp))) { if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) continue; #if 0 if (de->d_type == DT_DIR) { errno = EISDIR; AuFin(de->d_name); } #endif err = na_append(plink_dir, de->d_name); if (err) break; p = strchr(de->d_name, '.'); if (!p) { errno = EINVAL; AuFin("internal error, %s", de->d_name); } *p = 0; errno = 0; ino = strtoull(de->d_name, NULL, 0); if (ino == /*ULLONG_MAX*/-1 && errno == ERANGE) AuFin("internal error, %s", de->d_name); err = ia_append(ino); if (err) break; } closedir(dp); return err; }