static int nist_close (SF_PRIVATE *psf) { if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR) nist_write_header (psf, SF_TRUE) ; return 0 ; } /* nist_close */
static int nist_close (SF_PRIVATE *psf) { #if defined(USE_LIBSND_ALL) || defined(USE_LIBSND_WRITE) if (psf->mode == SF_MODE_WRITE) { /* Now we know for certain the length of the file we can ** re-write correct values for the datasize header element. */ fseek (psf->file, 0, SEEK_END) ; psf->filelength = ftell (psf->file) ; psf->dataoffset = NIST_HEADER_LENGTH ; psf->datalength = psf->filelength - psf->dataoffset ; psf->sf.samples = psf->datalength / psf->blockwidth ; nist_write_header (psf) ; } ; #endif if (psf->fdata) free (psf->fdata) ; psf->fdata = NULL ; return 0 ; } /* nist_close */
int nist_open (SF_PRIVATE *psf) { int error ; if (psf->file.mode == SFM_READ || (psf->file.mode == SFM_RDWR && psf->filelength > 0)) { if ((error = nist_read_header (psf))) return error ; } ; if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR) { if (psf->is_pipe) return SFE_NO_PIPE_WRITE ; if ((SF_CONTAINER (psf->sf.format)) != SF_FORMAT_NIST) return SFE_BAD_OPEN_FORMAT ; psf->endian = SF_ENDIAN (psf->sf.format) ; if (psf->endian == 0 || psf->endian == SF_ENDIAN_CPU) psf->endian = (CPU_IS_BIG_ENDIAN) ? SF_ENDIAN_BIG : SF_ENDIAN_LITTLE ; psf->blockwidth = psf->bytewidth * psf->sf.channels ; psf->sf.frames = 0 ; if ((error = nist_write_header (psf, SF_FALSE))) return error ; psf->write_header = nist_write_header ; } ; psf->container_close = nist_close ; switch (SF_CODEC (psf->sf.format)) { case SF_FORMAT_PCM_S8 : error = pcm_init (psf) ; break ; case SF_FORMAT_PCM_16 : case SF_FORMAT_PCM_24 : case SF_FORMAT_PCM_32 : error = pcm_init (psf) ; break ; case SF_FORMAT_ULAW : error = ulaw_init (psf) ; break ; case SF_FORMAT_ALAW : error = alaw_init (psf) ; break ; default : error = SFE_UNIMPLEMENTED ; break ; } ; return error ; } /* nist_open */
int nist_open (SF_PRIVATE *psf) { int subformat, error ; if (psf->mode == SFM_READ || (psf->mode == SFM_RDWR && psf->filelength > 0)) { if ((error = nist_read_header (psf))) return error ; } ; subformat = psf->sf.format & SF_FORMAT_SUBMASK ; if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR) { if ((psf->sf.format & SF_FORMAT_TYPEMASK) != SF_FORMAT_NIST) return SFE_BAD_OPEN_FORMAT ; psf->endian = psf->sf.format & SF_FORMAT_ENDMASK ; if (psf->endian == 0 || psf->endian == SF_ENDIAN_CPU) psf->endian = (CPU_IS_BIG_ENDIAN) ? SF_ENDIAN_BIG : SF_ENDIAN_LITTLE ; psf->blockwidth = psf->bytewidth * psf->sf.channels ; if ((error = nist_write_header (psf, SF_FALSE))) return error ; psf->write_header = nist_write_header ; } ; psf->close = nist_close ; switch (psf->sf.format & SF_FORMAT_SUBMASK) { case SF_FORMAT_PCM_S8 : error = pcm_init (psf) ; break ; case SF_FORMAT_PCM_16 : case SF_FORMAT_PCM_24 : case SF_FORMAT_PCM_32 : error = pcm_init (psf) ; break ; case SF_FORMAT_ULAW : error = ulaw_init (psf) ; break ; case SF_FORMAT_ALAW : error = alaw_init (psf) ; break ; default : error = SFE_UNIMPLEMENTED ; break ; } ; return error ; } /* nist_open */
static int nist_close (SF_PRIVATE *psf) { if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR) { /* Now we know for certain the length of the file we can ** re-write correct values for the datasize header element. */ psf_fseek (psf->filedes, 0, SEEK_END) ; psf->filelength = psf_ftell (psf->filedes) ; psf->dataoffset = NIST_HEADER_LENGTH ; psf->datalength = psf->filelength - psf->dataoffset ; psf->sf.frames = psf->datalength / psf->blockwidth ; nist_write_header (psf, SF_FALSE) ; } ; return 0 ; } /* nist_close */
int nist_open_write (SF_PRIVATE *psf) { int subformat, error ; if ((psf->sf.format & SF_FORMAT_TYPEMASK) != SF_FORMAT_NIST) return SFE_BAD_OPEN_FORMAT ; subformat = psf->sf.format & SF_FORMAT_SUBMASK ; if (subformat == SF_FORMAT_PCM_BE) psf->endian = SF_ENDIAN_BIG ; else if (subformat == SF_FORMAT_PCM_LE) psf->endian = SF_ENDIAN_LITTLE ; else if (CPU_IS_BIG_ENDIAN && subformat == SF_FORMAT_PCM) psf->endian = SF_ENDIAN_BIG ; else if (CPU_IS_LITTLE_ENDIAN && subformat == SF_FORMAT_PCM) psf->endian = SF_ENDIAN_LITTLE ; else return SFE_BAD_OPEN_FORMAT ; psf->bytewidth = BITWIDTH2BYTES (psf->sf.pcmbitwidth) ; psf->blockwidth = psf->bytewidth * psf->sf.channels ; psf->dataoffset = NIST_HEADER_LENGTH ; psf->datalength = psf->blockwidth * psf->sf.samples ; psf->filelength = psf->datalength + psf->dataoffset ; psf->error = 0 ; if ((error = pcm_write_init (psf))) return error ; psf->close = (func_close) nist_close ; psf->write_header = (func_wr_hdr) nist_write_header ; nist_write_header (psf) ; return 0 ; } /* nist_open_write */