int w64_open (SF_PRIVATE *psf) { WAV_PRIVATE * wpriv ; int subformat, error, blockalign = 0, framesperblock = 0 ; if ((wpriv = calloc (1, sizeof (WAV_PRIVATE))) == NULL) return SFE_MALLOC_FAILED ; psf->container_data = wpriv ; if (psf->file.mode == SFM_READ || (psf->file.mode == SFM_RDWR &&psf->filelength > 0)) { if ((error = w64_read_header (psf, &blockalign, &framesperblock))) return error ; } ; if ((SF_CONTAINER (psf->sf.format)) != SF_FORMAT_W64) return SFE_BAD_OPEN_FORMAT ; subformat = SF_CODEC (psf->sf.format) ; if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR) { if (psf->is_pipe) return SFE_NO_PIPE_WRITE ; psf->endian = SF_ENDIAN_LITTLE ; /* All W64 files are little endian. */ psf->blockwidth = psf->bytewidth * psf->sf.channels ; if (subformat == SF_FORMAT_IMA_ADPCM || subformat == SF_FORMAT_MS_ADPCM) { blockalign = wav_w64_srate2blocksize (psf->sf.samplerate * psf->sf.channels) ; framesperblock = -1 ; /* ** At this point we don't know the file length so set it stupidly high, but not ** so high that it triggers undefined behaviour whan something is added to it. */ psf->filelength = SF_COUNT_MAX - 10000 ; psf->datalength = psf->filelength ; if (psf->sf.frames <= 0) psf->sf.frames = (psf->blockwidth) ? psf->filelength / psf->blockwidth : psf->filelength ; } ; if ((error = w64_write_header (psf, SF_FALSE))) return error ; psf->write_header = w64_write_header ; } ; psf->container_close = w64_close ; switch (subformat) { case SF_FORMAT_PCM_U8 : 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 ; /* Lite remove start */ case SF_FORMAT_FLOAT : error = float32_init (psf) ; break ; case SF_FORMAT_DOUBLE : error = double64_init (psf) ; break ; case SF_FORMAT_IMA_ADPCM : error = wav_w64_ima_init (psf, blockalign, framesperblock) ; break ; case SF_FORMAT_MS_ADPCM : error = wav_w64_msadpcm_init (psf, blockalign, framesperblock) ; break ; /* Lite remove end */ case SF_FORMAT_GSM610 : error = gsm610_init (psf) ; break ; default : return SFE_UNIMPLEMENTED ; } ; return error ; } /* w64_open */
int au_open (SF_PRIVATE *psf) { int subformat ; int error = 0 ; if (psf->file.mode == SFM_READ || (psf->file.mode == SFM_RDWR && psf->filelength > 0)) { if ((error = au_read_header (psf))) return error ; } ; if ((SF_CONTAINER (psf->sf.format)) != SF_FORMAT_AU) return SFE_BAD_OPEN_FORMAT ; subformat = SF_CODEC (psf->sf.format) ; if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR) { psf->endian = SF_ENDIAN (psf->sf.format) ; if (CPU_IS_LITTLE_ENDIAN && psf->endian == SF_ENDIAN_CPU) psf->endian = SF_ENDIAN_LITTLE ; else if (psf->endian != SF_ENDIAN_LITTLE) psf->endian = SF_ENDIAN_BIG ; if (au_write_header (psf, SF_FALSE)) return psf->error ; psf->write_header = au_write_header ; } ; psf->container_close = au_close ; psf->blockwidth = psf->bytewidth * psf->sf.channels ; switch (subformat) { case SF_FORMAT_ULAW : /* 8-bit Ulaw encoding. */ ulaw_init (psf) ; break ; case SF_FORMAT_PCM_S8 : /* 8-bit linear PCM. */ error = pcm_init (psf) ; break ; case SF_FORMAT_PCM_16 : /* 16-bit linear PCM. */ case SF_FORMAT_PCM_24 : /* 24-bit linear PCM */ case SF_FORMAT_PCM_32 : /* 32-bit linear PCM. */ error = pcm_init (psf) ; break ; case SF_FORMAT_ALAW : /* 8-bit Alaw encoding. */ alaw_init (psf) ; break ; /* Lite remove start */ case SF_FORMAT_FLOAT : /* 32-bit floats. */ error = float32_init (psf) ; break ; case SF_FORMAT_DOUBLE : /* 64-bit double precision floats. */ error = double64_init (psf) ; break ; case SF_FORMAT_G721_32 : error = g72x_init (psf) ; psf->sf.seekable = SF_FALSE ; break ; case SF_FORMAT_G723_24 : error = g72x_init (psf) ; psf->sf.seekable = SF_FALSE ; break ; case SF_FORMAT_G723_40 : error = g72x_init (psf) ; psf->sf.seekable = SF_FALSE ; break ; /* Lite remove end */ default : break ; } ; return error ; } /* au_open */
int caf_open (SF_PRIVATE *psf) { CAF_PRIVATE * pcaf ; int subformat, format, error = 0 ; if ((psf->container_data = calloc (1, sizeof (CAF_PRIVATE))) == NULL) return SFE_MALLOC_FAILED ; pcaf = psf->container_data ; if (psf->file.mode == SFM_READ || (psf->file.mode == SFM_RDWR && psf->filelength > 0)) { if ((error = caf_read_header (psf))) return error ; psf->next_chunk_iterator = caf_next_chunk_iterator ; psf->get_chunk_size = caf_get_chunk_size ; psf->get_chunk_data = caf_get_chunk_data ; } ; subformat = SF_CODEC (psf->sf.format) ; if (psf->file.mode == SFM_WRITE || psf->file.mode == SFM_RDWR) { if (psf->is_pipe) return SFE_NO_PIPE_WRITE ; format = SF_CONTAINER (psf->sf.format) ; if (format != SF_FORMAT_CAF) return SFE_BAD_OPEN_FORMAT ; psf->blockwidth = psf->bytewidth * psf->sf.channels ; if (psf->file.mode != SFM_RDWR || psf->filelength < 44) { psf->filelength = 0 ; psf->datalength = 0 ; psf->dataoffset = 0 ; psf->sf.frames = 0 ; } ; psf->strings.flags = SF_STR_ALLOW_START | SF_STR_ALLOW_END ; /* ** By default, add the peak chunk to floating point files. Default behaviour ** can be switched off using sf_command (SFC_SET_PEAK_CHUNK, SF_FALSE). */ if (psf->file.mode == SFM_WRITE && (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE)) { if ((psf->peak_info = peak_info_calloc (psf->sf.channels)) == NULL) return SFE_MALLOC_FAILED ; psf->peak_info->peak_loc = SF_PEAK_START ; } ; if ((error = caf_write_header (psf, SF_FALSE)) != 0) return error ; psf->write_header = caf_write_header ; psf->set_chunk = caf_set_chunk ; } ; psf->container_close = caf_close ; psf->command = caf_command ; switch (subformat) { case SF_FORMAT_PCM_S8 : 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 ; /* Lite remove start */ case SF_FORMAT_FLOAT : error = float32_init (psf) ; break ; case SF_FORMAT_DOUBLE : error = double64_init (psf) ; break ; case SF_FORMAT_ALAC_16 : case SF_FORMAT_ALAC_20 : case SF_FORMAT_ALAC_24 : case SF_FORMAT_ALAC_32 : if (psf->file.mode == SFM_READ) /* Only pass the ALAC_DECODER_INFO in read mode. */ error = alac_init (psf, &pcaf->alac) ; else error = alac_init (psf, NULL) ; break ; /* Lite remove end */ default : return SFE_UNSUPPORTED_ENCODING ; } ; return error ; } /* caf_open */
int raw_open (SF_PRIVATE *psf) { int subformat, error = SFE_NO_ERROR ; subformat = psf->sf.format & SF_FORMAT_SUBMASK ; psf->endian = psf->sf.format & SF_FORMAT_ENDMASK ; if (CPU_IS_BIG_ENDIAN && (psf->endian == 0 || psf->endian == SF_ENDIAN_CPU)) psf->endian = SF_ENDIAN_BIG ; else if (CPU_IS_LITTLE_ENDIAN && (psf->endian == 0 || psf->endian == SF_ENDIAN_CPU)) psf->endian = SF_ENDIAN_LITTLE ; psf->blockwidth = psf->bytewidth * psf->sf.channels ; psf->dataoffset = 0 ; psf->datalength = psf->filelength ; switch (subformat) { case SF_FORMAT_PCM_S8 : error = pcm_init (psf) ; break ; case SF_FORMAT_PCM_U8 : 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 ; case SF_FORMAT_GSM610 : error = gsm610_init (psf) ; break ; /* Lite remove start */ case SF_FORMAT_FLOAT : error = float32_init (psf) ; break ; case SF_FORMAT_DOUBLE : error = double64_init (psf) ; break ; case SF_FORMAT_DWVW_12 : error = dwvw_init (psf, 12) ; break ; case SF_FORMAT_DWVW_16 : error = dwvw_init (psf, 16) ; break ; case SF_FORMAT_DWVW_24 : error = dwvw_init (psf, 24) ; break ; case SF_FORMAT_VOX_ADPCM : error = vox_adpcm_init (psf) ; break ; /* Lite remove end */ default : return SFE_BAD_OPEN_FORMAT ; } ; return error ; } /* raw_open */
int w64_open (SF_PRIVATE *psf) { int subformat, error, blockalign = 0, framesperblock = 0 ; if (psf->mode == SFM_READ || (psf->mode == SFM_RDWR &&psf->filelength > 0)) { if ((error = w64_read_header (psf, &blockalign, &framesperblock))) return error ; }; if ((psf->sf.format & SF_FORMAT_TYPEMASK) != SF_FORMAT_W64) return SFE_BAD_OPEN_FORMAT ; subformat = psf->sf.format & SF_FORMAT_SUBMASK ; if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR) { psf->endian = SF_ENDIAN_LITTLE ; /* All W64 files are little endian. */ psf->blockwidth = psf->bytewidth * psf->sf.channels ; if (subformat == SF_FORMAT_IMA_ADPCM || subformat == SF_FORMAT_MS_ADPCM) { blockalign = wav_w64_srate2blocksize (psf->sf.samplerate * psf->sf.channels) ; framesperblock = -1 ; /* FIXME : This block must go */ SF_COUNT_MAX_POSITIVE (psf->filelength) ; psf->datalength = psf->filelength ; if (psf->sf.frames <= 0) psf->sf.frames = (psf->blockwidth) ? psf->filelength / psf->blockwidth : psf->filelength ; /* EMXIF : This block must go */ } ; if ((error = w64_write_header (psf, SF_FALSE))) return error ; psf->write_header = w64_write_header ; } ; psf->close = w64_close ; switch (subformat) { case SF_FORMAT_PCM_U8 : 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_FLOAT : error = float32_init (psf) ; break ; case SF_FORMAT_DOUBLE : error = double64_init (psf) ; break ; case SF_FORMAT_ULAW : error = ulaw_init (psf) ; break ; case SF_FORMAT_ALAW : error = alaw_init (psf) ; break ; case SF_FORMAT_IMA_ADPCM : error = wav_w64_ima_init (psf, blockalign, framesperblock) ; break ; case SF_FORMAT_MS_ADPCM : error = wav_w64_msadpcm_init (psf, blockalign, framesperblock) ; break ; case SF_FORMAT_GSM610 : error = gsm610_init (psf) ; break ; default : return SFE_UNIMPLEMENTED ; } ; return error ; } /* w64_open */