This is SNDrecord.c in view mode; [Download] [Up]
/* * SNDrecord * * Version 1.0 Written 1994 by Amir Guindehi * * Plays: Any .snd file and any .snd.gz files * */ #include <sound/sound.h> #include <stdio.h> #include <libc.h> #define VERSION "SNDrecord 1.0 (01.04.94) written by Amir Guindehi.\n" #define USAGE "\nUsage: SNDrecord [-vh] [-s rate] [-f format] file\n" #define HELP VERSION USAGE \ " -v : Switch to verbose mode.\n" \ " -f <data format> : Data encoding type to record.\n" \ " 1 : Mulaw 8\n" \ " 2 : Linear 8\n" \ " 3 : Linear 16 (default)\n" \ " 4 : Linear 24\n" \ " 5 : Linear 32\n" \ " -s <sampling rate> : Sampling rate to record with.\n" \ " -h : This help text.\n" #define DEFAULT_RATE 22050 int verbose = 0, errflag = 0, rate = DEFAULT_RATE; int format = SND_FORMAT_LINEAR_16; void sig_handler(int sig) { signal(sig, sig_handler); if (verbose) fprintf(stderr, "Got signal %d.\n", sig); switch (sig) { case SIGTERM: case SIGQUIT: case SIGINT: exit(0); } return; } int recordfile(char *name) { SNDSoundStruct *sound; int err; if (verbose) fprintf(stdout, "Allocating sound structure.\n"); err = SNDAlloc(&sound, 100000, format, rate, 1, 0); if (err) { fprintf(stderr,"recordfile: Failed to allocate sound structure.\n"); exit(1); } if (verbose) fprintf(stdout, "Waiting for empty sound queue ...\n"); err = SNDWait(0); if (err) { fprintf(stderr, "recordfile: %s\n", SNDSoundError(err)); exit(1); } if (verbose) { fprintf(stdout, "SND-Type: %d sampling rate, %d channels.\n", sound->samplingRate, sound->channelCount); fprintf(stdout, "SND-Encoding: "); switch (sound->dataFormat) { case SND_FORMAT_UNSPECIFIED : fprintf(stdout, "Unspecified\n"); break; case SND_FORMAT_MULAW_8 : fprintf(stdout, "Mulaw 8\n"); break; case SND_FORMAT_LINEAR_8 : fprintf(stdout, "Linear 8\n"); break; case SND_FORMAT_LINEAR_16 : fprintf(stdout, "Linear 16\n"); break; case SND_FORMAT_LINEAR_24 : fprintf(stdout, "Linear 24\n"); break; case SND_FORMAT_LINEAR_32 : fprintf(stdout, "Linear 32\n"); break; case SND_FORMAT_FLOAT : fprintf(stdout, "Float\n"); break; case SND_FORMAT_DOUBLE : fprintf(stdout, "Double\n"); break; case SND_FORMAT_INDIRECT : fprintf(stdout, "Indirect\n"); break; case SND_FORMAT_DISPLAY : fprintf(stdout, "Display\n"); break; case SND_FORMAT_MULAW_SQUELCH: fprintf(stdout, "Mulaw squelch\n"); break; case SND_FORMAT_EMPHASIZED : fprintf(stdout, "Emphasized\n"); break; case SND_FORMAT_COMPRESSED : fprintf(stdout, "Compressed\n"); break; case SND_FORMAT_COMPRESSED_EMPHASIZED: fprintf(stdout, "Compressed emphasized\n"); break; default : fprintf(stdout, "Unknown format.\n"); break; } } if (verbose) fprintf(stdout, "\nPress return to start recording ...\n"); while (getc(stdin) != '\n'); err = SNDStartRecording(sound, 1, 5, 0, 0, 0); if (err) { fprintf(stderr, "recordfile: %s\n", SNDSoundError(err)); exit(1); } if (verbose) fprintf(stdout, "\nPress return to stop recording ...\n"); while (getc(stdin) != '\n'); SNDStop(1); if (verbose) fprintf(stdout, "Waiting for end of sound ...\n"); err = SNDWait(1); if (err) { fprintf(stderr, "recordfile: %s\n", SNDSoundError(err)); exit(1); } if (verbose) fprintf(stdout, "Saving recorded sound to '%s'.\n", name); SNDWriteSoundfile(name, sound); if (verbose) fprintf(stdout, "Freeing sound structure.\n"); SNDFree(sound); return 0; } int main(int argc, char **argv) { int c; extern int optind; while ((c = getopt(argc, argv, "vhs:f:")) != EOF) switch (c) { case 'h': fprintf(stdout, HELP); exit(0); case 'v': verbose++; break; case 's': rate = atoi(optarg); break; case 'f': format = atoi(optarg); break; default: errflag++; break; } if (errflag || (argc-optind != 1)) { fprintf(stderr, VERSION USAGE); exit(2); } if (verbose) fprintf(stdout, VERSION); signal(SIGQUIT, sig_handler); signal(SIGTERM, sig_handler); signal(SIGINT, sig_handler); recordfile(argv[optind]); exit(0); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.