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 rx2_open (SF_PRIVATE *psf) { int error, marker, length, glob_offset, slce_count ; int sdat_length = 0, slce_total = 0 ; /* So far only doing read. */ psf_binheader_readf (psf, "Epm4", 0, &marker, &length) ; if (marker != CAT_MARKER) { psf_log_printf (psf, "length : %d\n", length) ; return -1000 ; } ; if (length != psf->filelength - 8) psf_log_printf (psf, "%M : %d (should be %d)\n", marker, length, psf->filelength - 8) ; else psf_log_printf (psf, "%M : %d\n", marker, length) ; /* 'REX2' marker */ psf_binheader_readf (psf, "m", &marker) ; psf_log_printf (psf, "%M", marker) ; /* 'HEAD' marker */ psf_binheader_readf (psf, "m", &marker) ; psf_log_printf (psf, "%M\n", marker) ; /* Grab 'GLOB' offset. */ psf_binheader_readf (psf, "E4", &glob_offset) ; glob_offset += 0x14 ; /* Add the current file offset. */ /* Jump to offset 0x30 */ psf_binheader_readf (psf, "p", 0x30) ; /* Get name length */ length = 0 ; psf_binheader_readf (psf, "1", &length) ; if (length >= SIGNED_SIZEOF (psf->buffer)) { psf_log_printf (psf, " Text : %d *** Error : Too sf_count_t!\n") ; return -1001 ; } memset (psf->buffer, 0, SIGNED_SIZEOF (psf->buffer)) ; psf_binheader_readf (psf, "b", psf->buffer, length) ; psf_log_printf (psf, " Text : \"%s\"\n", psf->buffer) ; /* Jump to GLOB offset position. */ if (glob_offset & 1) glob_offset ++ ; psf_binheader_readf (psf, "p", glob_offset) ; slce_count = 0 ; /* GLOB */ while (1) { psf_binheader_readf (psf, "m", &marker) ; if (marker != SLCE_MARKER && slce_count > 0) { psf_log_printf (psf, " SLCE count : %d\n", slce_count) ; slce_count = 0 ; } switch (marker) { case GLOB_MARKER: psf_binheader_readf (psf, "E4", &length) ; psf_log_printf (psf, " %M : %d\n", marker, length) ; psf_binheader_readf (psf, "j", length) ; break ; case RECY_MARKER: psf_binheader_readf (psf, "E4", &length) ; psf_log_printf (psf, " %M : %d\n", marker, length) ; psf_binheader_readf (psf, "j", (length+1) & 0xFFFFFFFE) ; /* ?????? */ break ; case CAT_MARKER: psf_binheader_readf (psf, "E4", &length) ; psf_log_printf (psf, " %M : %d\n", marker, length) ; /*-psf_binheader_readf (psf, "j", length) ;-*/ break ; case DEVL_MARKER: psf_binheader_readf (psf, "mE4", &marker, &length) ; psf_log_printf (psf, " DEVL%M : %d\n", marker, length) ; if (length & 1) length ++ ; psf_binheader_readf (psf, "j", length) ; break ; case EQ_MARKER: case COMP_MARKER: psf_binheader_readf (psf, "E4", &length) ; psf_log_printf (psf, " %M : %d\n", marker, length) ; /* This is weird!!!! why make this (length - 1) */ if (length & 1) length ++ ; psf_binheader_readf (psf, "j", length) ; break ; case SLCL_MARKER: psf_log_printf (psf, " %M\n", marker) ; slce_count = 0 ; break ; case SLCE_MARKER: /*-psf_log_printf (psf, " %M\n", marker) ;-*/ psf_binheader_readf (psf, "E4", &length) ; /*-psf_log_printf (psf, " ???????? : 0x%X\n", length) ;-*/ psf_binheader_readf (psf, "E4", &length) ; /*-psf_log_printf (psf, " Start ? : %d\n", length) ;-*/ psf_binheader_readf (psf, "E4", &length) ; /*-psf_log_printf (psf, " Length ? : %d\n", length) ;-*/ slce_total += length ; psf_binheader_readf (psf, "E4", &length) ; /*-psf_log_printf (psf, " ???????? : 0x%X\n", length) ;-*/ slce_count ++ ; break ; case SINF_MARKER: psf_binheader_readf (psf, "E4", &length) ; psf_log_printf (psf, " %M : %d\n", marker, length) ; psf_binheader_readf (psf, "E2", &length) ; psf_log_printf (psf, " REX Version : %X ?\n", length) ; psf_binheader_readf (psf, "E44", &psf->sf.samplerate, &psf->sf.frames) ; psf_log_printf (psf, " Sample Rate : %d\n", psf->sf.samplerate) ; psf_log_printf (psf, " Frames : %d\n", psf->sf.frames) ; psf_binheader_readf (psf, "E4", &length) ; psf_log_printf (psf, " ??????????? : %d\n", length) ; psf_binheader_readf (psf, "E4", &length) ; psf_log_printf (psf, " ??????????? : %d\n", length) ; break ; case SDAT_MARKER: psf_binheader_readf (psf, "E4", &length) ; sdat_length = length ; /* Get the current offset. */ psf->dataoffset = psf_binheader_readf (psf, NULL) ; if (psf->dataoffset + length != psf->filelength) psf_log_printf (psf, " %M : %d (should be %d)\n", marker, length, psf->dataoffset + psf->filelength) ; else psf_log_printf (psf, " %M : %d\n", marker, length) ; break ; default : psf_log_printf (psf, "Unknown marker : 0x%X %M", marker, marker) ; return -1003 ; break ; } ; /* SDAT always last marker in file. */ if (marker == SDAT_MARKER) break ; } ; puts (psf->logbuffer) ; puts ("-----------------------------------") ; printf ("SDAT length : %d\n", sdat_length) ; printf ("SLCE samples : %d\n", slce_total) ; /* Two bytes per sample. */ printf ("Comp Ratio : %f:1\n", (2.0 * slce_total) / sdat_length) ; puts (" ") ; psf->logbuffer [0] = 0 ; /* OK, have the header althought not too sure what it all means. */ psf->endian = SF_ENDIAN_BIG ; psf->datalength = psf->filelength - psf->dataoffset ; if (psf_fseek (psf->filedes, psf->dataoffset, SEEK_SET)) return SFE_BAD_SEEK ; psf->sf.format = (SF_FORMAT_REX2 | SF_FORMAT_DWVW_12) ; psf->sf.channels = 1 ; psf->bytewidth = 2 ; psf->blockwidth = psf->sf.channels * psf->bytewidth ; if ((error = dwvw_init (psf, 16))) return error ; psf->close = rx2_close ; if (! psf->sf.frames && psf->blockwidth) psf->sf.frames = psf->datalength / psf->blockwidth ; /* All done. */ return 0 ; } /* rx2_open */