📄 xi.c
字号:
psf_log_printf (psf, "Sample #%d\n name : %s\n size : %d\n", k + 1, name, sample_sizes [k]) ; psf_log_printf (psf, " loop\n begin : %d\n end : %d\n", loop_begin, loop_end) ; psf_log_printf (psf, " volume : %u\n f. tune : %d\n flags : 0x%02X ", buffer [0] & 0xFF, buffer [1] & 0xFF, buffer [2] & 0xFF) ; psf_log_printf (psf, " (") ; if (buffer [2] & 1) psf_log_printf (psf, " Loop") ; if (buffer [2] & 2) psf_log_printf (psf, " PingPong") ; psf_log_printf (psf, (buffer [2] & 16) ? " 16bit" : " 8bit") ; psf_log_printf (psf, " )\n") ; psf_log_printf (psf, " pan : %u\n note : %d\n namelen : %d\n", buffer [3] & 0xFF, buffer [4], buffer [5]) ; if (k != 0) continue ; if (buffer [2] & 16) { psf->sf.format = SF_FORMAT_XI | SF_FORMAT_DPCM_16 ; psf->bytewidth = 2 ; } else { psf->sf.format = SF_FORMAT_XI | SF_FORMAT_DPCM_8 ; psf->bytewidth = 1 ; } ; } ; while (sample_count > 1 && sample_sizes [sample_count - 1] == 0) sample_count -- ; /* Currently, we can only handle 1 sample per file. */ if (sample_count > 2) { psf_log_printf (psf, "*** Sample count is less than 16 but more than 1.\n") ; psf_log_printf (psf, " sample count : %d sample_sizes [%d] : %d\n", sample_count, sample_count - 1, sample_sizes [sample_count - 1]) ; return SFE_XI_EXCESS_SAMPLES ; } ; psf->dataoffset = psf_fseek (psf, 0, SEEK_CUR) ; psf_log_printf (psf, "Data Offset : %D\n", psf->dataoffset) ; psf->datalength = sample_sizes [0] ; if (psf->dataoffset + psf->datalength > psf->filelength) { psf_log_printf (psf, "*** File seems to be truncated. Should be at least %D bytes long.\n", psf->dataoffset + sample_sizes [0]) ; psf->datalength = psf->filelength - psf->dataoffset ; } ; if (psf_fseek (psf, psf->dataoffset, SEEK_SET) != psf->dataoffset) return SFE_BAD_SEEK ; psf->close = xi_close ; psf->endian = SF_ENDIAN_LITTLE ; psf->sf.channels = 1 ; /* Always mono */ psf->sf.samplerate = 44100 ; /* Always */ psf->blockwidth = psf->sf.channels * psf->bytewidth ; if (! psf->sf.frames && psf->blockwidth) psf->sf.frames = (psf->filelength - psf->dataoffset) / psf->blockwidth ; return 0 ;} /* xi_read_header *//*==============================================================================*/static void dsc2s_array (XI_PRIVATE *pxi, signed char *src, int count, short *dest) ;static void dsc2i_array (XI_PRIVATE *pxi, signed char *src, int count, int *dest) ;static void dsc2f_array (XI_PRIVATE *pxi, signed char *src, int count, float *dest, float normfact) ;static void dsc2d_array (XI_PRIVATE *pxi, signed char *src, int count, double *dest, double normfact) ;static void dles2s_array (XI_PRIVATE *pxi, short *src, int count, short *dest) ;static void dles2i_array (XI_PRIVATE *pxi, short *src, int count, int *dest) ;static void dles2f_array (XI_PRIVATE *pxi, short *src, int count, float *dest, float normfact) ;static void dles2d_array (XI_PRIVATE *pxi, short *src, int count, double *dest, double normfact) ;static sf_count_tdpcm_read_dsc2s (SF_PRIVATE *psf, short *ptr, sf_count_t len){ XI_PRIVATE *pxi ; int bufferlen, readcount ; sf_count_t total = 0 ; if ((pxi = psf->fdata) == NULL) return 0 ; bufferlen = ARRAY_LEN (psf->u.ucbuf) ; while (len > 0) { if (len < bufferlen) bufferlen = (int) len ; readcount = psf_fread (psf->u.scbuf, sizeof (signed char), bufferlen, psf) ; dsc2s_array (pxi, psf->u.scbuf, readcount, ptr + total) ; total += readcount ; if (readcount < bufferlen) break ; len -= readcount ; } ; return total ;} /* dpcm_read_dsc2s */static sf_count_tdpcm_read_dsc2i (SF_PRIVATE *psf, int *ptr, sf_count_t len){ XI_PRIVATE *pxi ; int bufferlen, readcount ; sf_count_t total = 0 ; if ((pxi = psf->fdata) == NULL) return 0 ; bufferlen = ARRAY_LEN (psf->u.ucbuf) ; while (len > 0) { if (len < bufferlen) bufferlen = (int) len ; readcount = psf_fread (psf->u.scbuf, sizeof (signed char), bufferlen, psf) ; dsc2i_array (pxi, psf->u.scbuf, readcount, ptr + total) ; total += readcount ; if (readcount < bufferlen) break ; len -= readcount ; } ; return total ;} /* dpcm_read_dsc2i */static sf_count_tdpcm_read_dsc2f (SF_PRIVATE *psf, float *ptr, sf_count_t len){ XI_PRIVATE *pxi ; int bufferlen, readcount ; sf_count_t total = 0 ; float normfact ; if ((pxi = psf->fdata) == NULL) return 0 ; normfact = (psf->norm_float == SF_TRUE) ? 1.0 / ((float) 0x80) : 1.0 ; bufferlen = ARRAY_LEN (psf->u.ucbuf) ; while (len > 0) { if (len < bufferlen) bufferlen = (int) len ; readcount = psf_fread (psf->u.scbuf, sizeof (signed char), bufferlen, psf) ; dsc2f_array (pxi, psf->u.scbuf, readcount, ptr + total, normfact) ; total += readcount ; if (readcount < bufferlen) break ; len -= readcount ; } ; return total ;} /* dpcm_read_dsc2f */static sf_count_tdpcm_read_dsc2d (SF_PRIVATE *psf, double *ptr, sf_count_t len){ XI_PRIVATE *pxi ; int bufferlen, readcount ; sf_count_t total = 0 ; double normfact ; if ((pxi = psf->fdata) == NULL) return 0 ; normfact = (psf->norm_double == SF_TRUE) ? 1.0 / ((double) 0x80) : 1.0 ; bufferlen = ARRAY_LEN (psf->u.ucbuf) ; while (len > 0) { if (len < bufferlen) bufferlen = (int) len ; readcount = psf_fread (psf->u.scbuf, sizeof (signed char), bufferlen, psf) ; dsc2d_array (pxi, psf->u.scbuf, readcount, ptr + total, normfact) ; total += readcount ; if (readcount < bufferlen) break ; len -= readcount ; } ; return total ;} /* dpcm_read_dsc2d *//*------------------------------------------------------------------------------*/static sf_count_tdpcm_read_dles2s (SF_PRIVATE *psf, short *ptr, sf_count_t len){ XI_PRIVATE *pxi ; int bufferlen, readcount ; sf_count_t total = 0 ; if ((pxi = psf->fdata) == NULL) return 0 ; bufferlen = ARRAY_LEN (psf->u.sbuf) ; while (len > 0) { if (len < bufferlen) bufferlen = (int) len ; readcount = psf_fread (psf->u.sbuf, sizeof (short), bufferlen, psf) ; dles2s_array (pxi, psf->u.sbuf, readcount, ptr + total) ; total += readcount ; if (readcount < bufferlen) break ; len -= readcount ; } ; return total ;} /* dpcm_read_dles2s */static sf_count_tdpcm_read_dles2i (SF_PRIVATE *psf, int *ptr, sf_count_t len){ XI_PRIVATE *pxi ; int bufferlen, readcount ; sf_count_t total = 0 ; if ((pxi = psf->fdata) == NULL) return 0 ; bufferlen = ARRAY_LEN (psf->u.sbuf) ; while (len > 0) { if (len < bufferlen) bufferlen = (int) len ; readcount = psf_fread (psf->u.sbuf, sizeof (short), bufferlen, psf) ; dles2i_array (pxi, psf->u.sbuf, readcount, ptr + total) ; total += readcount ; if (readcount < bufferlen) break ; len -= readcount ; } ; return total ;} /* dpcm_read_dles2i */static sf_count_tdpcm_read_dles2f (SF_PRIVATE *psf, float *ptr, sf_count_t len){ XI_PRIVATE *pxi ; int bufferlen, readcount ; sf_count_t total = 0 ; float normfact ; if ((pxi = psf->fdata) == NULL) return 0 ; normfact = (psf->norm_float == SF_TRUE) ? 1.0 / ((float) 0x8000) : 1.0 ; bufferlen = ARRAY_LEN (psf->u.sbuf) ; while (len > 0) { if (len < bufferlen) bufferlen = (int) len ; readcount = psf_fread (psf->u.sbuf, sizeof (short), bufferlen, psf) ; dles2f_array (pxi, psf->u.sbuf, readcount, ptr + total, normfact) ; total += readcount ; if (readcount < bufferlen) break ; len -= readcount ; } ; return total ;} /* dpcm_read_dles2f */static sf_count_tdpcm_read_dles2d (SF_PRIVATE *psf, double *ptr, sf_count_t len){ XI_PRIVATE *pxi ; int bufferlen, readcount ; sf_count_t total = 0 ; double normfact ; if ((pxi = psf->fdata) == NULL) return 0 ; normfact = (psf->norm_double == SF_TRUE) ? 1.0 / ((double) 0x8000) : 1.0 ; bufferlen = ARRAY_LEN (psf->u.sbuf) ; while (len > 0) { if (len < bufferlen) bufferlen = (int) len ; readcount = psf_fread (psf->u.sbuf, sizeof (short), bufferlen, psf) ; dles2d_array (pxi, psf->u.sbuf, readcount, ptr + total, normfact) ; total += readcount ; if (readcount < bufferlen) break ; len -= readcount ; } ; return total ;} /* dpcm_read_dles2d *//*==============================================================================*/static void s2dsc_array (XI_PRIVATE *pxi, short *src, signed char *dest, int count) ;static void i2dsc_array (XI_PRIVATE *pxi, int *src, signed char *dest, int count) ;static void f2dsc_array (XI_PRIVATE *pxi, float *src, signed char *dest, int count, float normfact) ;static void d2dsc_array (XI_PRIVATE *pxi, double *src, signed char *dest, int count, double normfact) ;static void s2dles_array (XI_PRIVATE *pxi, short *src, short *dest, int count) ;static void i2dles_array (XI_PRIVATE *pxi, int *src, short *dest, int count) ;static void f2dles_array (XI_PRIVATE *pxi, float *src, short *dest, int count, float normfact) ;static void d2dles_array (XI_PRIVATE *pxi, double *src, short *dest, int count, double normfact) ;static sf_count_tdpcm_write_s2dsc (SF_PRIVATE *psf, short *ptr, sf_count_t len){ XI_PRIVATE *pxi ; int bufferlen, writecount ; sf_count_t total = 0 ; if ((pxi = psf->fdata) == NULL) return 0 ; bufferlen = ARRAY_LEN (psf->u.ucbuf) ; while (len > 0) { if (len < bufferlen) bufferlen = (int) len ; s2dsc_array (pxi, ptr + total, psf->u.scbuf, bufferlen) ; writecount = psf_fwrite (psf->u.scbuf, sizeof (signed char), bufferlen, psf) ; total += writecount ; if (writecount < bufferlen) break ; len -= writecount ; } ; return total ;} /* dpcm_write_s2dsc */static sf_count_tdpcm_write_i2dsc (SF_PRIVATE *psf, int *ptr, sf_count_t len){ XI_PRIVATE *pxi ; int bufferlen, writecount ; sf_count_t total = 0 ; if ((pxi = psf->fdata) == NULL) return 0 ; bufferlen = ARRAY_LEN (psf->u.ucbuf) ; while (len > 0) { if (len < bufferlen) bufferlen = (int) len ; i2dsc_array (pxi, ptr + total, psf->u.scbuf, bufferlen) ; writecount = psf_fwrite (psf->u.scbuf, sizeof (signed char), bufferlen, psf) ; total += writecount ; if (writecount < bufferlen) break ; len -= writecount ; } ; return total ;} /* dpcm_write_i2dsc */static sf_count_tdpcm_write_f2dsc (SF_PRIVATE *psf, float *ptr, sf_count_t len){ XI_PRIVATE *pxi ; int bufferlen, writecount ; sf_count_t total = 0 ; float normfact ; if ((pxi = psf->fdata) == NULL) return 0 ; normfact = (psf->norm_float == SF_TRUE) ? (1.0 * 0x7F) : 1.0 ; bufferlen = ARRAY_LEN (psf->u.ucbuf) ; while (len > 0) { if (len < bufferlen) bufferlen = (int) len ; f2dsc_array (pxi, ptr + total, psf->u.scbuf, bufferlen, normfact) ; writecount = psf_fwrite (psf->u.scbuf, sizeof (signed char), bufferlen, psf) ; total += writecount ; if (writecount < bufferlen) break ; len -= writecount ; } ; return total ;} /* dpcm_write_f2dsc */static sf_count_tdpcm_write_d2dsc (SF_PRIVATE *psf, double *ptr, sf_count_t len){ XI_PRIVATE *pxi ; int bufferlen, writecount ; sf_count_t total = 0 ; double normfact ; if ((pxi = psf->fdata) == NULL) return 0 ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -