Date: Mon, 6 Apr 1992 08:50:21 PDT From: Victor_J_Heintz.wbst128@xerox.com Received: by launchpad.paa.xerox.com (4.1/SMI-4.0) id AA03010; Mon, 6 Apr 92 11:50:14 EDT Apparently-To: info-mac@sumex-aim.stanford:edu:xerox I have attached a C program I wrote to convert Sun Microsystems u-law encoded audio files to linear sound data files. The latter files can be read by SoundMover ("Open any" mode) and converted to Mac snd resources. Anyone with a Sun Sparcstation and a microphone ought to be able to make their own Mac sounds. You have to remember to set the sampling rate in SoundMover to the value encoded in the audio file (usually, if not always, 8.0 kHz.) SoundMaster will still want to play them at 7.4 kHz, I think, but they sound OK. There is no Makefile. You can simply "cc" it on your Sparcstation. If someone incorporates this into a Mac utility (such as SoundMover, hint, hint) all I ask is a free copy. Please upload this to an appropriate directory. Vic Heintz vic:wbst128@xerox.com >------------------------------------------------------------------------------< /* sun_audio2mac_linear.c * This program was written April 6, 1992 by Victor J. Heintz * (vic:wbst128@xerox.com) * * Converts Sun Microsystems u-law encoded ".au" sound files to * linear sound data files. These files are compatible as input * to SoundMover with the "Open any" option. * Uses a look up table to translate u-law encoded sound bytes to * linear sound bytes as used in Macintosh snd resources. * The look-up table was generated by applying the audio_u2c macro * defined in the Sun ulaw2linear.h file to values from 0 to 255. * The audio file header structure was taken from the audio_filehdr.h * file in the Sun SOUND demo package. * I am distributing this freely in the hopes that someone will write * a Mac tool that recognizes Sun u-law format sounds ( and of course * let me have a free copy.) */ #include #define AU_MAGIC 0x2e736e64 #define U_LAW 1 #define INFO_SIZE (au_head.hdr_size - 24) static unsigned char lut_au2snd[] = { 2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, 112,113,113,114,114,115,115,116,116,117,117,118,118,119,119,120, 120,120,121,121,121,121,122,122,122,122,123,123,123,123,124,124, 124,124,124,124,125,125,125,125,125,125,125,125,126,126,126,126, 126,126,126,126,126,126,126,126,127,127,127,127,127,127,127,127, 127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,128, 254,249,245,241,237,233,229,225,221,217,213,209,205,201,197,193, 190,188,186,184,182,180,178,176,174,172,170,168,166,164,162,160, 159,158,157,156,155,154,153,152,151,150,149,148,147,146,145,144, 143,142,142,141,141,140,140,139,139,138,138,137,137,136,136,135, 135,135,134,134,134,134,133,133,133,133,132,132,132,132,131,131, 131,131,131,131,130,130,130,130,130,130,130,130,129,129,129,129, 129,129,129,129,129,129,129,129,128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128 }; typedef struct { unsigned long magic; /* should be 0x2e736e64 = ".snd" */ unsigned long hdr_size; /* this struct's 24 bytes + info text */ unsigned long data_size; /* number of bytes of sound data */ unsigned long encoding; /* usually (always?) U_LAW = 1 */ unsigned long sample_rate; /* usually (always?) 8000 Hz */ unsigned long channels; /* usually (always?) 1 */ } au_hdrTYPE; main(argc,argv) int argc; char *argv[]; { au_hdrTYPE au_head; FILE *fpIn, *fpOut; char info[255]; /* text immediately following header struct */ unsigned char *sound_bytes; unsigned long whichByte; if (argc != 3) { printf("Usage: %s Sun_audio_file Mac_snd_file\n", argv[0]); exit (-1); } else { fpIn = fopen(argv[1], "r"); if (fpIn == NULL) { fprintf(stderr,"Error opening input file %s\n", argv[1]); exit(-1); } fread(&au_head,sizeof(au_hdrTYPE), 1, fpIn); if (au_head.magic != AU_MAGIC) { fprintf(stderr,"%s is not a valid audio file!\n", argv[1]); exit(-1); } fread(info,INFO_SIZE,1,fpIn); printf("%s %ld Hz %ld bytes: %s\n",argv[1], au_head.sample_rate, au_head.data_size, info); if (au_head.encoding != U_LAW) { fprintf(stderr,"Unknown data encoding!\n"); exit(-1); } fpOut = fopen(argv[2],"w"); if (fpOut == NULL) { fprintf(stderr,"Error opening output file: %s\n", argv[2]); exit(-1); } sound_bytes = (unsigned char *) malloc(au_head.data_size); fread(sound_bytes, au_head.data_size, 1, fpIn); for (whichByte = 0; whichByte < au_head.data_size; whichByte++) { sound_bytes[whichByte] = lut_au2snd[sound_bytes[whichByte]]; } fwrite(sound_bytes, au_head.data_size, 1, fpOut); fclose(fpOut); fclose(fpIn); free(sound_bytes); exit(0); } }