int broadcast_add_coding_history (SF_BROADCAST_INFO* bext, unsigned int channels, unsigned int samplerate) { char chnstr [16] ; int count ; switch (channels) { case 0 : return SF_FALSE ; case 1 : strncpy (chnstr, "mono", sizeof (chnstr)) ; break ; case 2 : strncpy (chnstr, "stereo", sizeof (chnstr)) ; break ; default : LSF_SNPRINTF (chnstr, sizeof (chnstr), "%uchn", channels) ; break ; } count = LSF_SNPRINTF (bext->coding_history, sizeof (bext->coding_history), "F=%u,A=PCM,M=%s,W=24,T=%s-%s", samplerate, chnstr, PACKAGE, VERSION) ; if (count >= SIGNED_SIZEOF (bext->coding_history)) bext->coding_history_size = sizeof (bext->coding_history) ; else { count += count & 1 ; bext->coding_history_size = count ; } ; return SF_TRUE ; } /* broadcast_add_coding_history */
static const char * mat4_marker_to_str (int marker) { static char str [32] ; switch (marker) { case MAT4_BE_PCM_16 : return "big endian 16 bit PCM" ; case MAT4_LE_PCM_16 : return "little endian 16 bit PCM" ; case MAT4_BE_PCM_32 : return "big endian 32 bit PCM" ; case MAT4_LE_PCM_32 : return "little endian 32 bit PCM" ; case MAT4_BE_FLOAT : return "big endian float" ; case MAT4_LE_FLOAT : return "big endian float" ; case MAT4_BE_DOUBLE : return "big endian double" ; case MAT4_LE_DOUBLE : return "little endian double" ; } ; /* This is a little unsafe but is really only for debugging. */ str [sizeof (str) - 1] = 0 ; LSF_SNPRINTF (str, sizeof (str) - 1, "%08X", marker) ; return str ; } /* mat4_marker_to_str */
static void psf_log_syserr (SF_PRIVATE *psf, int error) { /* Only log an error if no error has been set yet. */ if (psf->error == 0) { psf->error = SFE_SYSTEM ; LSF_SNPRINTF (psf->syserr, sizeof (psf->syserr), "System error : %s", strerror (error)) ; } ; return ; } /* psf_log_syserr */
static int gen_coding_history (char * added_history, int added_history_max, const SF_INFO * psfinfo) { char chnstr [16] ; int count, width ; /* ** From : http://www.sr.se/utveckling/tu/bwf/docs/codhist2.htm ** ** Parameter Variable string <allowed option> Unit ** ========================================================================================== ** Coding Algorithm A=<ANALOGUE, PCM, MPEG1L1, MPEG1L2, MPEG1L3, ** MPEG2L1, MPEG2L2, MPEG2L3> ** Sampling frequency F=<11000,22050,24000,32000,44100,48000> [Hz] ** Bit-rate B=<any bit-rate allowed in MPEG 2 (ISO/IEC [kbit/s per channel] ** 13818-3)> ** Word Length W=<8, 12, 14, 16, 18, 20, 22, 24> [bits] ** Mode M=<mono, stereo, dual-mono, joint-stereo> ** Text, free string T=<a free ASCII-text string for in house use. ** This string should contain no commas (ASCII ** 2Chex). Examples of the contents: ID-No; codec ** type; A/D type> */ switch (psfinfo->channels) { case 0 : return SF_FALSE ; case 1 : strncpy (chnstr, "mono", sizeof (chnstr)) ; break ; case 2 : strncpy (chnstr, "stereo", sizeof (chnstr)) ; break ; default : LSF_SNPRINTF (chnstr, sizeof (chnstr), "%uchn", psfinfo->channels) ; break ; } ; switch (SF_CODEC (psfinfo->format)) { case SF_FORMAT_PCM_U8 : case SF_FORMAT_PCM_S8 : width = 8 ; break ; case SF_FORMAT_PCM_16 : width = 16 ; break ; case SF_FORMAT_PCM_24 : width = 24 ; break ; case SF_FORMAT_PCM_32 : width = 32 ; break ; case SF_FORMAT_FLOAT : width = 24 ; /* Bits in the mantissa + 1 */ break ; case SF_FORMAT_DOUBLE : width = 53 ; /* Bits in the mantissa + 1 */ break ; case SF_FORMAT_ULAW : case SF_FORMAT_ALAW : width = 12 ; break ; default : width = 42 ; break ; } ; count = LSF_SNPRINTF (added_history, added_history_max, "A=PCM,F=%u,W=%hu,M=%s,T=%s-%s\r\n", psfinfo->samplerate, width, chnstr, PACKAGE, VERSION) ; if (count >= added_history_max) return 0 ; return count ; } /* gen_coding_history */
static int mat4_read_header (SF_PRIVATE *psf) { int marker, namesize, rows, cols, imag ; double value ; const char *marker_str ; char name [64] ; psf_binheader_readf (psf, "pm", 0, &marker) ; /* MAT4 file must start with a double for the samplerate. */ if (marker == MAT4_BE_DOUBLE) { psf->endian = psf->rwf_endian = SF_ENDIAN_BIG ; marker_str = "big endian double" ; } else if (marker == MAT4_LE_DOUBLE) { psf->endian = psf->rwf_endian = SF_ENDIAN_LITTLE ; marker_str = "little endian double" ; } else return SFE_UNIMPLEMENTED ; psf_log_printf (psf, "GNU Octave 2.0 / MATLAB v4.2 format\nMarker : %s\n", marker_str) ; psf_binheader_readf (psf, "444", &rows, &cols, &imag) ; psf_log_printf (psf, " Rows : %d\n Cols : %d\n Imag : %s\n", rows, cols, imag ? "True" : "False") ; psf_binheader_readf (psf, "4", &namesize) ; if (namesize >= SIGNED_SIZEOF (name)) return SFE_MAT4_BAD_NAME ; psf_binheader_readf (psf, "b", name, namesize) ; name [namesize] = 0 ; psf_log_printf (psf, " Name : %s\n", name) ; psf_binheader_readf (psf, "d", &value) ; LSF_SNPRINTF (psf->u.scbuf, sizeof (psf->u.scbuf), " Value : %f\n", value) ; psf_log_printf (psf, psf->u.scbuf) ; if ((rows != 1) || (cols != 1)) return SFE_MAT4_NO_SAMPLERATE ; psf->sf.samplerate = lrint (value) ; /* Now write out the audio data. */ psf_binheader_readf (psf, "m", &marker) ; psf_log_printf (psf, "Marker : %s\n", mat4_marker_to_str (marker)) ; psf_binheader_readf (psf, "444", &rows, &cols, &imag) ; psf_log_printf (psf, " Rows : %d\n Cols : %d\n Imag : %s\n", rows, cols, imag ? "True" : "False") ; psf_binheader_readf (psf, "4", &namesize) ; if (namesize >= SIGNED_SIZEOF (name)) return SFE_MAT4_BAD_NAME ; psf_binheader_readf (psf, "b", name, namesize) ; name [namesize] = 0 ; psf_log_printf (psf, " Name : %s\n", name) ; psf->dataoffset = psf_ftell (psf) ; if (rows == 0 && cols == 0) { psf_log_printf (psf, "*** Error : zero channel count.\n") ; return SFE_MAT4_ZERO_CHANNELS ; } ; psf->sf.channels = rows ; psf->sf.frames = cols ; psf->sf.format = psf->endian | SF_FORMAT_MAT4 ; switch (marker) { case MAT4_BE_DOUBLE : case MAT4_LE_DOUBLE : psf->sf.format |= SF_FORMAT_DOUBLE ; psf->bytewidth = 8 ; break ; case MAT4_BE_FLOAT : case MAT4_LE_FLOAT : psf->sf.format |= SF_FORMAT_FLOAT ; psf->bytewidth = 4 ; break ; case MAT4_BE_PCM_32 : case MAT4_LE_PCM_32 : psf->sf.format |= SF_FORMAT_PCM_32 ; psf->bytewidth = 4 ; break ; case MAT4_BE_PCM_16 : case MAT4_LE_PCM_16 : psf->sf.format |= SF_FORMAT_PCM_16 ; psf->bytewidth = 2 ; break ; default : psf_log_printf (psf, "*** Error : Bad marker %08X\n", marker) ; return SFE_UNIMPLEMENTED ; } ; if ((psf->filelength - psf->dataoffset) < psf->sf.channels * psf->sf.frames * psf->bytewidth) { psf_log_printf (psf, "*** File seems to be truncated. %D <--> %D\n", psf->filelength - psf->dataoffset, psf->sf.channels * psf->sf.frames * psf->bytewidth) ; } else if ((psf->filelength - psf->dataoffset) > psf->sf.channels * psf->sf.frames * psf->bytewidth) psf->dataend = psf->dataoffset + rows * cols * psf->bytewidth ; psf->datalength = psf->filelength - psf->dataoffset - psf->dataend ; psf->sf.sections = 1 ; return 0 ; } /* mat4_read_header */