ftp.nice.ch/pub/next/unix/audio/shorten.1.12.s.tar.gz#/shorten-1.12/shortshift.c

This is shortshift.c in view mode; [Download] [Up]

# include <stdio.h>
# include <limits.h>

int main(argc, argv) int argc; char **argv; {
  int upshift;
  short sample;

  if(argc != 2 || (upshift = atoi(argv[1])) == 0) {
    fprintf(stderr, "Usage: shortshift [+-]upshift\n");
    exit(1);
  }

  if(upshift > 0)
    while(fread(&sample, sizeof(sample), 1, stdin) == 1) {
      long lsam = sample << upshift;
      if(lsam > SHRT_MAX) sample = SHRT_MAX;
      else if(lsam <SHRT_MIN) sample = SHRT_MIN;
      else sample = lsam;

      if(fwrite(&sample, sizeof(sample), 1, stdout) != 1) {
	fprintf(stderr, "shortshift: PANIC: fwrite fails\n");
	exit(2);
      }
    }
  else if(upshift < 0) {
    int downshift = -upshift;
    short offset = 1 << (downshift - 1);
    
    while(fread(&sample, sizeof(sample), 1, stdin) == 1) {
      sample = (sample + offset) >> downshift;

      if(fwrite(&sample, sizeof(sample), 1, stdout) != 1) {
	fprintf(stderr, "shortshift: PANIC: fwrite fails\n");
      exit(3);
      }
    }
  }
  return(0);
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.