Lines Matching defs:psf

43 {	SF_PRIVATE * psf ;
45 if ((psf = calloc (1, sizeof (SF_PRIVATE))) == NULL)
48 if ((psf->header.ptr = calloc (1, INITIAL_HEADER_SIZE)) == NULL)
49 { free (psf) ;
52 psf->header.len = INITIAL_HEADER_SIZE ;
54 return psf ;
58 psf_bump_header_allocation (SF_PRIVATE * psf, sf_count_t needed)
63 newlen = (needed > psf->header.len) ? 2 * SF_MAX (needed, smallest) : 2 * psf->header.len ;
66 { psf_log_printf (psf, "Request for header allocation of %D denied.\n", newlen) ;
70 if ((ptr = realloc (psf->header.ptr, newlen)) == NULL)
71 { psf_log_printf (psf, "realloc (%p, %D) failed\n", psf->header.ptr, newlen) ;
72 psf->error = SFE_MALLOC_FAILED ;
77 if (newlen > psf->header.len)
78 memset ((char *) ptr + psf->header.len, 0, newlen - psf->header.len) ;
80 psf->header.ptr = ptr ;
81 psf->header.len = newlen ;
95 log_putchar (SF_PRIVATE *psf, char ch)
96 { if (psf->parselog.indx < SIGNED_SIZEOF (psf->parselog.buf) - 1)
97 { psf->parselog.buf [psf->parselog.indx++] = ch ;
98 psf->parselog.buf [psf->parselog.indx] = 0 ;
104 psf_log_printf (SF_PRIVATE *psf, const char *format, ...)
114 { log_putchar (psf, c) ;
119 { log_putchar (psf, '%') ;
178 log_putchar (psf, ' ') ;
180 log_putchar (psf, *strptr++) ;
182 log_putchar (psf, ' ') ;
209 { log_putchar (psf, ' ') ;
218 log_putchar (psf, lead_char) ;
222 { log_putchar (psf, sign_char) ;
228 log_putchar (psf, lead_char) ;
231 { log_putchar (psf, '0' + u / tens) ;
237 log_putchar (psf, lead_char) ;
248 log_putchar (psf, lead_char) ;
249 log_putchar (psf, '0') ;
254 { log_putchar (psf, '-') ;
270 { log_putchar (psf, lead_char) ;
275 { log_putchar (psf, '0' + U / Tens) ;
295 { log_putchar (psf, ' ') ;
304 log_putchar (psf, lead_char) ;
308 { log_putchar (psf, sign_char) ;
314 log_putchar (psf, lead_char) ;
317 { log_putchar (psf, '0' + u / tens) ;
323 log_putchar (psf, lead_char) ;
328 log_putchar (psf, c) ;
337 log_putchar (psf, lead_char) ;
338 log_putchar (psf, '0') ;
349 { log_putchar (psf, lead_char) ;
355 log_putchar (psf, (c > 9) ? c + 'A' - 10 : c + '0') ;
378 log_putchar (psf, psf_isprint (c) ? c : '.') ;
383 log_putchar (psf, '*') ;
384 log_putchar (psf, c) ;
385 log_putchar (psf, '*') ;
403 psf_asciiheader_printf (SF_PRIVATE *psf, const char *format, ...)
411 maxlen = strlen ((char*) psf->header.ptr) ;
412 start = ((char*) psf->header.ptr) + maxlen ;
413 maxlen = psf->header.len - maxlen ;
422 psf->header.indx = strlen ((char*) psf->header.ptr) ;
474 header_put_byte (SF_PRIVATE *psf, char x)
475 { psf->header.ptr [psf->header.indx++] = x ;
480 header_put_marker (SF_PRIVATE *psf, int x)
481 { psf->header.ptr [psf->header.indx++] = (x >> 24) ;
482 psf->header.ptr [psf->header.indx++] = (x >> 16) ;
483 psf->header.ptr [psf->header.indx++] = (x >> 8) ;
484 psf->header.ptr [psf->header.indx++] = x ;
489 header_put_marker (SF_PRIVATE *psf, int x)
490 { psf->header.ptr [psf->header.indx++] = x ;
491 psf->header.ptr [psf->header.indx++] = (x >> 8) ;
492 psf->header.ptr [psf->header.indx++] = (x >> 16) ;
493 psf->header.ptr [psf->header.indx++] = (x >> 24) ;
502 header_put_be_short (SF_PRIVATE *psf, int x)
503 { psf->header.ptr [psf->header.indx++] = (x >> 8) ;
504 psf->header.ptr [psf->header.indx++] = x ;
508 header_put_le_short (SF_PRIVATE *psf, int x)
509 { psf->header.ptr [psf->header.indx++] = x ;
510 psf->header.ptr [psf->header.indx++] = (x >> 8) ;
514 header_put_be_3byte (SF_PRIVATE *psf, int x)
515 { psf->header.ptr [psf->header.indx++] = (x >> 16) ;
516 psf->header.ptr [psf->header.indx++] = (x >> 8) ;
517 psf->header.ptr [psf->header.indx++] = x ;
521 header_put_le_3byte (SF_PRIVATE *psf, int x)
522 { psf->header.ptr [psf->header.indx++] = x ;
523 psf->header.ptr [psf->header.indx++] = (x >> 8) ;
524 psf->header.ptr [psf->header.indx++] = (x >> 16) ;
528 header_put_be_int (SF_PRIVATE *psf, int x)
529 { psf->header.ptr [psf->header.indx++] = (x >> 24) ;
530 psf->header.ptr [psf->header.indx++] = (x >> 16) ;
531 psf->header.ptr [psf->header.indx++] = (x >> 8) ;
532 psf->header.ptr [psf->header.indx++] = x ;
536 header_put_le_int (SF_PRIVATE *psf, int x)
537 { psf->header.ptr [psf->header.indx++] = x ;
538 psf->header.ptr [psf->header.indx++] = (x >> 8) ;
539 psf->header.ptr [psf->header.indx++] = (x >> 16) ;
540 psf->header.ptr [psf->header.indx++] = (x >> 24) ;
544 header_put_be_8byte (SF_PRIVATE *psf, sf_count_t x)
545 { psf->header.ptr [psf->header.indx++] = (x >> 56) ;
546 psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 48) ;
547 psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 40) ;
548 psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 32) ;
549 psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 24) ;
550 psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 16) ;
551 psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 8) ;
552 psf->header.ptr [psf->header.indx++] = (unsigned char) x ;
556 header_put_le_8byte (SF_PRIVATE *psf, sf_count_t x)
557 { psf->header.ptr [psf->header.indx++] = (unsigned char) x ;
558 psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 8) ;
559 psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 16) ;
560 psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 24) ;
561 psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 32) ;
562 psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 40) ;
563 psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 48) ;
564 psf->header.ptr [psf->header.indx++] = (x >> 56) ;
568 psf_binheader_writef (SF_PRIVATE *psf, const char *format, ...)
581 return psf_ftell (psf) ;
587 if (psf->header.indx + 16 >= psf->header.len && psf_bump_header_allocation (psf, 16))
595 psf->rwf_endian = SF_ENDIAN_LITTLE ;
599 psf->rwf_endian = SF_ENDIAN_BIG ;
612 header_put_marker (psf, data) ;
618 header_put_byte (psf, data) ;
624 if (psf->rwf_endian == SF_ENDIAN_BIG)
625 { header_put_be_short (psf, data) ;
628 { header_put_le_short (psf, data) ;
635 if (psf->rwf_endian == SF_ENDIAN_BIG)
636 { header_put_be_3byte (psf, data) ;
639 { header_put_le_3byte (psf, data) ;
646 if (psf->rwf_endian == SF_ENDIAN_BIG)
647 { header_put_be_int (psf, data) ;
650 { header_put_le_int (psf, data) ;
657 if (psf->rwf_endian == SF_ENDIAN_BIG && trunc_8to4 == SF_FALSE)
658 { header_put_be_8byte (psf, countdata) ;
661 else if (psf->rwf_endian == SF_ENDIAN_LITTLE && trunc_8to4 == SF_FALSE)
662 { header_put_le_8byte (psf, countdata) ;
665 else if (psf->rwf_endian == SF_ENDIAN_BIG && trunc_8to4 == SF_TRUE)
667 header_put_be_int (psf, longdata) ;
670 else if (psf->rwf_endian == SF_ENDIAN_LITTLE && trunc_8to4 == SF_TRUE)
672 header_put_le_int (psf, longdata) ;
680 if (psf->rwf_endian == SF_ENDIAN_BIG)
681 float32_be_write (floatdata, psf->header.ptr + psf->header.indx) ;
683 float32_le_write (floatdata, psf->header.ptr + psf->header.indx) ;
684 psf->header.indx += 4 ;
690 if (psf->rwf_endian == SF_ENDIAN_BIG)
691 double64_be_write (doubledata, psf->header.ptr + psf->header.indx) ;
693 double64_le_write (doubledata, psf->header.ptr + psf->header.indx) ;
694 psf->header.indx += 8 ;
703 if (psf->header.indx + 4 + (sf_count_t) size + (sf_count_t) (size & 1) > psf->header.len && psf_bump_header_allocation (psf, 4 + size + (size & 1)))
706 if (psf->rwf_endian == SF_ENDIAN_BIG)
707 header_put_be_int (psf, size + (size & 1)) ;
709 header_put_le_int (psf, size + (size & 1)) ;
710 memcpy (&(psf->header.ptr [psf->header.indx]), strptr, size) ;
712 psf->header.indx += size ;
713 psf->header.ptr [psf->header.indx - 1] = 0 ;
724 if (psf->header.indx + 4 + (sf_count_t) size + (sf_count_t) (size & 1) > psf->header.len && psf_bump_header_allocation (psf, 4 + size + (size & 1)))
726 if (psf->rwf_endian == SF_ENDIAN_BIG)
727 header_put_be_int (psf, size) ;
729 header_put_le_int (psf, size) ;
730 memcpy (&(psf->header.ptr [psf->header.indx]), strptr, size + (size & 1)) ;
732 psf->header.indx += size ;
744 if (psf->header.indx + 1 + (sf_count_t) size > psf->header.len && psf_bump_header_allocation (psf, 1 + size))
747 header_put_byte (psf, size) ;
748 memcpy (&(psf->header.ptr [psf->header.indx]), strptr, size) ;
749 psf->header.indx += size ;
757 if (psf->header.indx + (sf_count_t) size > psf->header.len && psf_bump_header_allocation (psf, size))
760 memcpy (&(psf->header.ptr [psf->header.indx]), bindata, size) ;
761 psf->header.indx += size ;
768 if (psf->header.indx + (sf_count_t) size > psf->header.len && psf_bump_header_allocation (psf, size))
773 { psf->header.ptr [psf->header.indx] = 0 ;
774 psf->header.indx ++ ;
781 memcpy (&(psf->header.ptr [psf->header.indx]), bindata, 16) ;
782 psf->header.indx += 16 ;
789 if (psf->header.indx + (sf_count_t) size > psf->header.len && psf_bump_header_allocation (psf, size))
792 psf->header.indx += size ;
799 if ((sf_count_t) size >= psf->header.len && psf_bump_header_allocation (psf, size))
802 psf->header.indx = size ;
806 psf_log_printf (psf, "*** Invalid format specifier `%c'\n", c) ;
807 psf->error = SFE_INTERNAL ;
864 header_read (SF_PRIVATE *psf, void *ptr, int bytes)
867 if (psf->header.indx + bytes >= psf->header.len && psf_bump_header_allocation (psf, bytes))
870 if (psf->header.indx + bytes > psf->header.end)
871 { count = psf_fread (psf->header.ptr + psf->header.end, 1, bytes - (psf->header.end - psf->header.indx), psf) ;
872 if (count != bytes - (int) (psf->header.end - psf->header.indx))
873 { psf_log_printf (psf, "Error : psf_fread returned short count.\n") ;
876 psf->header.end += count ;
879 memcpy (ptr, psf->header.ptr + psf->header.indx, bytes) ;
880 psf->header.indx += bytes ;
886 header_seek (SF_PRIVATE *psf, sf_count_t position, int whence)
890 if (psf->header.indx + position >= psf->header.len)
891 psf_bump_header_allocation (psf, position) ;
892 if (position > psf->header.len)
894 psf->header.indx = psf->header.end = 0 ;
895 psf_fseek (psf, position, whence) ;
898 if (position > psf->header.end)
899 psf->header.end += psf_fread (psf->header.ptr + psf->header.end, 1, position - psf->header.end, psf) ;
900 psf->header.indx = position ;
904 if (psf->header.indx + position >= psf->header.len)
905 psf_bump_header_allocation (psf, position) ;
907 if (psf->header.indx + position < 0)
910 if (psf->header.indx >= psf->header.len)
911 { psf_fseek (psf, position, whence) ;
915 if (psf->header.indx + position <= psf->header.end)
916 { psf->header.indx += position ;
920 if (psf->header.indx + position > psf->header.len)
922 position -= (psf->header.end - psf->header.indx) ;
923 psf->header.indx = psf->header.end ;
924 if (psf->is_pipe)
931 psf_fread (junk, 1, to_skip, psf) ;
936 { psf_fseek (psf, position, SEEK_CUR) ;
941 psf->header.end += psf_fread (psf->header.ptr + psf->header.end, 1, position - (psf->header.end - psf->header.indx), psf) ;
942 psf->header.indx = psf->header.end ;
947 psf_log_printf (psf, "Bad whence param in header_seek().\n") ;
955 header_gets (SF_PRIVATE *psf, char *ptr, int bufsize)
958 if (psf->header.indx + bufsize >= psf->header.len && psf_bump_header_allocation (psf, bufsize))
962 { if (psf->header.indx < psf->header.end)
963 { ptr [k] = psf->header.ptr [psf->header.indx] ;
964 psf->header.indx ++ ;
967 { psf->header.end += psf_fread (psf->header.ptr + psf->header.end, 1, 1, psf) ;
968 ptr [k] = psf->header.ptr [psf->header.indx] ;
969 psf->header.indx = psf->header.end ;
982 psf_binheader_readf (SF_PRIVATE *psf, char const *format, ...)
995 return psf_ftell (psf) ;
1001 if (psf->header.indx + 16 >= psf->header.len && psf_bump_header_allocation (psf, 16))
1006 psf->rwf_endian = SF_ENDIAN_LITTLE ;
1010 psf->rwf_endian = SF_ENDIAN_BIG ;
1017 byte_count += header_read (psf, ucptr, sizeof (int)) ;
1025 byte_count += header_read (psf, sixteen_bytes, sizeof (sixteen_bytes)) ;
1037 byte_count += header_read (psf, charptr, sizeof (char)) ;
1044 byte_count += header_read (psf, ucptr, sizeof (short)) ;
1045 if (psf->rwf_endian == SF_ENDIAN_BIG)
1054 byte_count += header_read (psf, sixteen_bytes, 3) ;
1055 if (psf->rwf_endian == SF_ENDIAN_BIG)
1065 byte_count += header_read (psf, ucptr, sizeof (int)) ;
1066 if (psf->rwf_endian == SF_ENDIAN_BIG)
1075 byte_count += header_read (psf, sixteen_bytes, 8) ;
1076 if (psf->rwf_endian == SF_ENDIAN_BIG)
1086 byte_count += header_read (psf, floatptr, sizeof (float)) ;
1087 if (psf->rwf_endian == SF_ENDIAN_BIG)
1096 byte_count += header_read (psf, doubleptr, sizeof (double)) ;
1097 if (psf->rwf_endian == SF_ENDIAN_BIG)
1104 psf_log_printf (psf, "Format conversion 's' not implemented yet.\n") ;
1110 get_int (psf, longdata) ;
1111 memcpy (&(psf->header.ptr [psf->header.indx]), strptr, size) ;
1112 psf->header.indx += size ;
1120 byte_count += header_read (psf, charptr, count) ;
1128 if (psf->header.indx + count >= psf->header.len && psf_bump_header_allocation (psf, count))
1131 byte_count += header_gets (psf, charptr, count) ;
1135 psf_log_printf (psf, "Format conversion 'z' not implemented yet.\n") ;
1139 { psf->header.ptr [psf->header.indx] = 0 ;
1140 psf->header.indx ++ ;
1148 header_seek (psf, count, SEEK_SET) ;
1154 header_seek (psf, count, SEEK_CUR) ;
1159 psf->header.end = psf->header.indx = 0 ;
1163 psf_log_printf (psf, "*** Invalid format specifier `%c'\n", c) ;
1164 psf->error = SFE_INTERNAL ;
1178 psf_default_seek (SF_PRIVATE *psf, int UNUSED (mode), sf_count_t samples_from_start)
1181 if (! (psf->blockwidth && psf->dataoffset >= 0))
1182 { psf->error = SFE_BAD_SEEK ;
1186 if (! psf->sf.seekable)
1187 { psf->error = SFE_NOT_SEEKABLE ;
1191 position = psf->dataoffset + psf->blockwidth * samples_from_start ;
1193 if ((retval = psf_fseek (psf, position, SEEK_SET)) != position)
1194 { psf->error = SFE_SEEK_FAILED ;
1236 psf_log_SF_INFO (SF_PRIVATE *psf)
1237 { psf_log_printf (psf, "---------------------------------\n") ;
1239 psf_log_printf (psf, " Sample rate : %d\n", psf->sf.samplerate) ;
1240 if (psf->sf.frames == SF_COUNT_MAX)
1241 psf_log_printf (psf, " Frames : unknown\n") ;
1243 psf_log_printf (psf, " Frames : %D\n", psf->sf.frames) ;
1244 psf_log_printf (psf, " Channels : %d\n", psf->sf.channels) ;
1246 psf_log_printf (psf, " Format : 0x%X\n", psf->sf.format) ;
1247 psf_log_printf (psf, " Sections : %d\n", psf->sf.sections) ;
1248 psf_log_printf (psf, " Seekable : %s\n", psf->sf.seekable ? "TRUE" : "FALSE") ;
1250 psf_log_printf (psf, "---------------------------------\n") ;
1348 psf_get_cues (SF_PRIVATE * psf, void * data, size_t datasize)
1350 if (psf->cues)
1353 cue_count = SF_MIN (cue_count, psf->cues->cue_count) ;
1354 memcpy (data, psf->cues, SF_CUES_VAR_SIZE (cue_count)) ;
1546 psf_decode_frame_count (SF_PRIVATE *psf)
1551 if (psf_is_pipe (psf) || psf->datalength > 0x1000000)
1554 psf_fseek (psf, psf->dataoffset, SEEK_SET) ;
1556 readlen = ARRAY_LEN (ubuf.ibuf) / psf->sf.channels ;
1557 readlen *= psf->sf.channels ;
1559 while ((count = psf->read_int (psf, ubuf.ibuf, readlen)) > 0)
1562 psf_fseek (psf, psf->dataoffset, SEEK_SET) ;
1564 return total / psf->sf.channels ;