home *** CD-ROM | disk | FTP | other *** search
- /*
- * July 5, 1991
- * Copyright 1991 Lance Norskog And Sundry Contributors
- * This source code is freely redistributable and may be used for
- * any purpose. This copyright notice must be maintained.
- * Lance Norskog And Sundry Contributors are not responsible for
- * the consequences of using this software.
- */
-
- /*
- * AUX IRCAM SoundFile format handler.
- *
- * Derived from: AUX skeleton handler file.
- */
-
- #include "aux.h"
- #include "sfheader.h"
-
- /* Private data for SF file */
- typedef struct sfstuff {
- struct sfinfo info;
- } *sf_t;
-
- extern int summary, verbose;
-
- /*
- * Do anything required before you start reading samples.
- * Read file header.
- * Find out sampling rate,
- * size and style of samples,
- * mono/stereo/quad.
- */
- sfstartread(ft)
- ft_t ft;
- {
- sf_t sf = (sf_t) ft->priv;
- int i;
-
- fread(&sf->info, 1, sizeof(sf->info), ft->fp);
- if (ft->swap) sf->info.sf_magic = swapl(sf->info.sf_magic);
- if (ft->swap) sf->info.sf_srate = swapl(sf->info.sf_srate);
- if (ft->swap) sf->info.sf_packmode = swapl(sf->info.sf_packmode);
- if (ft->swap) sf->info.sf_chans = swapl(sf->info.sf_chans);
- if (ft->swap) sf->info.sf_codes = swapl(sf->info.sf_codes);
- if (sf->info.sf_magic != SF_MAGIC)
- if (sf->info.sf_magic == swapl(SF_MAGIC))
- fail("SF %s file: can't read, it is probably byte-swapped");
- else
- fail("SF %s file: can't read, it is not an IRCAM SoundFile");
-
- /*
- * If your format specifies or your file header contains
- * any of the following information.
- */
- ft->rate = sf->info.sf_srate;
- switch(sf->info.sf_packmode) {
- case SF_SHORT:
- ft->size = WORD;
- ft->style = SIGN2;
- break;
- case SF_FLOAT:
- ft->size = FLOAT;
- ft->style = SIGN2;
- break;
- }
- ft->channels = sf->info.sf_chans;
- /* Future: Read codes and print as comments. */
-
- /* Skip all the comments */
- for(i = sizeof(struct sfinfo); i < SIZEOF_BSD_HEADER; i++)
- getc(ft->fp);
-
- /* It's raw from here. */
- ft->h = &handlers[RAWTYPE];
- }
-
- sfstartwrite(ft)
- ft_t ft;
- {
- sf_t sf = (sf_t) ft->priv;
- int i;
-
- sf->info.sf_magic = SF_MAGIC;
- sf->info.sf_srate = ft->rate;
- if (ft->size == WORD) {
- sf->info.sf_packmode = SF_SHORT;
- ft->style = SIGN2; /* Default to signed words */
- } else if (ft->size == FLOAT)
- sf->info.sf_packmode = SF_FLOAT;
- else
- fail("SoundFile %s: must set output as signed shorts or floats",
- ft->which);
- sf->info.sf_chans = ft->channels;
- sf->info.sf_codes = SF_END; /* No comments */
-
- fwrite(&sf->info, 1, sizeof(sf->info), ft->fp);
- /* Skip all the comments */
- for(i = sizeof(struct sfinfo); i < SIZEOF_BSD_HEADER; i++)
- putc(0, ft->fp);
-
- /* It's raw from here. */
- ft->h = &handlers[RAWTYPE];
- }
-
-
-
-
-