Lines Matching refs:ft
213 static int startread(sox_format_t * ft) in startread() argument
216 priv_t * v = (priv_t *) ft->priv; in startread()
222 if (lsx_readbuf(ft, header, (size_t)20) != 20) { in startread()
223 lsx_fail_errno(ft, SOX_EHDR, "unexpected EOF in VOC header"); in startread()
227 lsx_fail_errno(ft, SOX_EHDR, "VOC file header incorrect"); in startread()
233 lsx_readw(ft, &sbseek); in startread()
238 lsx_readb(ft, &uc); in startread()
248 rc = getblock(ft); in startread()
254 lsx_fail_errno(ft, SOX_EOF, "Input .voc file had no sound!"); in startread()
263 ft->encoding.encoding = SOX_ENCODING_UNSIGNED; in startread()
267 ft->encoding.encoding = SOX_ENCODING_CL_ADPCM; in startread()
271 ft->encoding.encoding = SOX_ENCODING_CL_ADPCM; in startread()
275 ft->encoding.encoding = SOX_ENCODING_CL_ADPCM; in startread()
279 ft->encoding.encoding = SOX_ENCODING_SIGN2; in startread()
283 ft->encoding.encoding = SOX_ENCODING_ALAW; in startread()
287 ft->encoding.encoding = SOX_ENCODING_ULAW; in startread()
291 ft->encoding.encoding = SOX_ENCODING_CL_ADPCM16; in startread()
298 ft->encoding.bits_per_sample = v->size; in startread()
301 if (ft->signal.channels == 0) in startread()
302 ft->signal.channels = v->channels; in startread()
312 static size_t read_samples(sox_format_t * ft, sox_sample_t * buf, in read_samples() argument
315 priv_t * v = (priv_t *) ft->priv; in read_samples()
322 rc = getblock(ft); in read_samples()
339 rc = getblock(ft); in read_samples()
351 if (lsx_readb(ft, &uc) == SOX_EOF) { in read_samples()
357 lsx_adpcm_init(&v->adpcm, 6 - v->size, SOX_SAMPLE_TO_SIGNED_16BIT(*buf, ft->clips)); in read_samples()
362 if (lsx_readb(ft, &uc) == SOX_EOF) { in read_samples()
408 if (lsx_readb(ft, &uc) == SOX_EOF) { in read_samples()
422 lsx_readsw(ft, &sw); in read_samples()
423 if (lsx_eof(ft)) { in read_samples()
454 static int startwrite(sox_format_t * ft) in startwrite() argument
456 priv_t * v = (priv_t *) ft->priv; in startwrite()
458 if (!ft->seekable) { in startwrite()
459 lsx_fail_errno(ft, SOX_EOF, in startwrite()
467 lsx_writes(ft, "Creative Voice File\032"); in startwrite()
468 lsx_writew(ft, 26); /* size of header */ in startwrite()
469 lsx_writew(ft, 0x10a); /* major/minor version number */ in startwrite()
470 lsx_writew(ft, 0x1129); /* checksum of version number */ in startwrite()
478 static size_t write_samples(sox_format_t * ft, const sox_sample_t * buf, in write_samples() argument
481 priv_t * v = (priv_t *) ft->priv; in write_samples()
489 blockstart(ft); in write_samples()
494 if (ft->encoding.bits_per_sample == 8) { in write_samples()
495 uc = SOX_SAMPLE_TO_UNSIGNED_8BIT(*buf++, ft->clips); in write_samples()
496 lsx_writeb(ft, uc); in write_samples()
498 sw = (int) SOX_SAMPLE_TO_SIGNED_16BIT(*buf++, ft->clips); in write_samples()
499 lsx_writesw(ft, sw); in write_samples()
510 static void blockstop(sox_format_t * ft) in blockstop() argument
512 priv_t * v = (priv_t *) ft->priv; in blockstop()
515 lsx_writeb(ft, 0); /* End of file block code */ in blockstop()
516 lsx_seeki(ft, (off_t) v->blockseek, 0); /* seek back to block length */ in blockstop()
517 lsx_seeki(ft, (off_t)1, 1); /* seek forward one */ in blockstop()
519 lsx_writesw(ft, (signed)v->samples); in blockstop()
521 if (ft->encoding.bits_per_sample == 8) { in blockstop()
522 if (ft->signal.channels > 1) { in blockstop()
523 lsx_seeki(ft, (off_t)8, 1); /* forward 7 + 1 for new block header */ in blockstop()
527 datum = (v->samples * (ft->encoding.bits_per_sample >> 3)) & 0xff; in blockstop()
528 lsx_writesb(ft, datum); /* low byte of length */ in blockstop()
529 datum = ((v->samples * (ft->encoding.bits_per_sample >> 3)) >> 8) & 0xff; in blockstop()
530 lsx_writesb(ft, datum); /* middle byte of length */ in blockstop()
531 datum = ((v->samples * (ft->encoding.bits_per_sample >> 3)) >> 16) & 0xff; in blockstop()
532 lsx_writesb(ft, datum); /* high byte of length */ in blockstop()
539 static int stopwrite(sox_format_t * ft) in stopwrite() argument
541 blockstop(ft); in stopwrite()
553 static int getblock(sox_format_t * ft) in getblock() argument
555 priv_t * v = (priv_t *) ft->priv; in getblock()
565 if (lsx_eof(ft)) in getblock()
568 if (lsx_readb(ft, &block) == SOX_EOF) in getblock()
574 if (lsx_eof(ft)) in getblock()
577 lsx_read3(ft, &sblen); in getblock()
583 lsx_readb(ft, &uc); in getblock()
588 lsx_fail_errno(ft, SOX_EFMT, "Sample rate is zero?"); in getblock()
592 lsx_fail_errno(ft, SOX_EFMT, in getblock()
598 ft->signal.rate = 1000000.0 / (256 - v->rate); in getblock()
600 lsx_fail_errno(ft, SOX_EFMT, "channel count changed"); in getblock()
605 lsx_readb(ft, &uc); in getblock()
607 lsx_fail_errno(ft, SOX_EFMT, "format changed"); in getblock()
615 lsx_readdw(ft, &new_rate_32); in getblock()
617 lsx_fail_errno(ft, SOX_EFMT, "Sample rate is zero?"); in getblock()
621 lsx_fail_errno(ft, SOX_EFMT, "sample rate codes differ: %ld != %d", in getblock()
626 ft->signal.rate = new_rate_32; in getblock()
627 lsx_readb(ft, &uc); in getblock()
629 lsx_readb(ft, &uc); in getblock()
631 lsx_fail_errno(ft, SOX_EFMT, "channel count changed"); in getblock()
635 lsx_readw(ft, &u16); /* ANN: added format */ in getblock()
637 lsx_fail_errno(ft, SOX_EFMT, "format changed"); in getblock()
641 lsx_skipbytes(ft, (size_t) 4); in getblock()
651 lsx_readw(ft, &period); in getblock()
652 lsx_readb(ft, &uc); in getblock()
654 lsx_fail_errno(ft, SOX_EFMT, "Silence sample rate is zero"); in getblock()
671 lsx_readb(ft, &uc); in getblock()
672 lsx_readb(ft, &uc); in getblock()
682 lsx_readsb(ft, &c); in getblock()
701 lsx_skipbytes(ft, (size_t) sblen); in getblock()
709 lsx_readw(ft, &new_rate_16); in getblock()
711 lsx_fail_errno(ft, SOX_EFMT, "Sample rate is zero?"); in getblock()
715 lsx_fail_errno(ft, SOX_EFMT, "sample rate codes differ: %ld != %d", in getblock()
720 lsx_readb(ft, &uc); /* bits_per_sample */ in getblock()
721 lsx_readb(ft, &uc); in getblock()
723 lsx_fail_errno(ft, SOX_EFMT, "channel count changed"); in getblock()
727 ft->signal.channels = uc? 2 : 1; /* Stereo */ in getblock()
730 ft->signal.rate = (256e6 / (65536 - v->rate)) / ft->signal.channels; in getblock()
737 lsx_skipbytes(ft, (size_t) sblen); in getblock()
746 static void blockstart(sox_format_t * ft) in blockstart() argument
748 priv_t * v = (priv_t *) ft->priv; in blockstart()
750 v->blockseek = lsx_tell(ft); in blockstart()
752 lsx_writeb(ft, VOC_SILENCE); /* Silence block code */ in blockstart()
753 lsx_writeb(ft, 0); /* Period length */ in blockstart()
754 lsx_writeb(ft, 0); /* Period length */ in blockstart()
755 lsx_writesb(ft, (signed)v->rate); /* Rate code */ in blockstart()
757 if (ft->encoding.bits_per_sample == 8) { in blockstart()
764 if (ft->signal.channels > 1) { in blockstart()
765 lsx_writeb(ft, VOC_EXTENDED); /* Voice Extended block code */ in blockstart()
766 lsx_writeb(ft, 4); /* block length = 4 */ in blockstart()
767 lsx_writeb(ft, 0); /* block length = 4 */ in blockstart()
768 lsx_writeb(ft, 0); /* block length = 4 */ in blockstart()
769 v->rate = 65536 - (256000000.0 / (2 * ft->signal.rate)) + .5; in blockstart()
770 lsx_writesw(ft, (signed) v->rate); /* Rate code */ in blockstart()
771 lsx_writeb(ft, 0); /* File is not packed */ in blockstart()
772 lsx_writeb(ft, 1); /* samples are in stereo */ in blockstart()
774 lsx_writeb(ft, VOC_DATA); /* Voice Data block code */ in blockstart()
775 lsx_writeb(ft, 0); /* block length (for now) */ in blockstart()
776 lsx_writeb(ft, 0); /* block length (for now) */ in blockstart()
777 lsx_writeb(ft, 0); /* block length (for now) */ in blockstart()
778 v->rate = 256 - (1000000.0 / ft->signal.rate) + .5; in blockstart()
779 lsx_writesb(ft, (signed) v->rate); /* Rate code */ in blockstart()
780 lsx_writeb(ft, 0); /* 8-bit raw data */ in blockstart()
782 lsx_writeb(ft, VOC_DATA_16); /* Voice Data block code */ in blockstart()
783 lsx_writeb(ft, 0); /* block length (for now) */ in blockstart()
784 lsx_writeb(ft, 0); /* block length (for now) */ in blockstart()
785 lsx_writeb(ft, 0); /* block length (for now) */ in blockstart()
786 v->rate = ft->signal.rate + .5; in blockstart()
787 lsx_writedw(ft, (unsigned) v->rate); /* Rate code */ in blockstart()
788 lsx_writeb(ft, 16); /* Sample Size */ in blockstart()
789 lsx_writeb(ft, ft->signal.channels); /* Sample Size */ in blockstart()
790 lsx_writew(ft, 0x0004); /* Encoding */ in blockstart()
791 lsx_writeb(ft, 0); /* Unused */ in blockstart()
792 lsx_writeb(ft, 0); /* Unused */ in blockstart()
793 lsx_writeb(ft, 0); /* Unused */ in blockstart()
794 lsx_writeb(ft, 0); /* Unused */ in blockstart()