Lines Matching refs:pms
92 static int msadpcm_decode_block (SF_PRIVATE *psf, MSADPCM_PRIVATE *pms) ;
93 static sf_count_t msadpcm_read_block (SF_PRIVATE *psf, MSADPCM_PRIVATE *pms, short *ptr, int len) ;
95 static int msadpcm_encode_block (SF_PRIVATE *psf, MSADPCM_PRIVATE *pms) ;
96 static sf_count_t msadpcm_write_block (SF_PRIVATE *psf, MSADPCM_PRIVATE *pms, const short *ptr, int…
119 { MSADPCM_PRIVATE *pms ; in wavlike_msadpcm_init() local
140 pms = (MSADPCM_PRIVATE*) psf->codec_data ; in wavlike_msadpcm_init()
142 pms->sync_error = 0 ; in wavlike_msadpcm_init()
143 pms->samples = pms->dummydata ; in wavlike_msadpcm_init()
144 pms->block = (unsigned char*) (pms->dummydata + psf->sf.channels * samplesperblock) ; in wavlike_msadpcm_init()
146 pms->channels = psf->sf.channels ; in wavlike_msadpcm_init()
147 pms->blocksize = blockalign ; in wavlike_msadpcm_init()
148 pms->samplesperblock = samplesperblock ; in wavlike_msadpcm_init()
150 if (pms->blocksize <= 0) in wavlike_msadpcm_init()
156 { pms->dataremaining = psf->datalength ; in wavlike_msadpcm_init()
158 if (psf->datalength % pms->blocksize) in wavlike_msadpcm_init()
159 pms->blocks = psf->datalength / pms->blocksize + 1 ; in wavlike_msadpcm_init()
161 pms->blocks = psf->datalength / pms->blocksize ; in wavlike_msadpcm_init()
163 count = 2 * (pms->blocksize - 6 * pms->channels) / pms->channels ; in wavlike_msadpcm_init()
164 if (pms->samplesperblock != count) in wavlike_msadpcm_init()
169 psf->sf.frames = (psf->datalength / pms->blocksize) * pms->samplesperblock ; in wavlike_msadpcm_init()
171 msadpcm_decode_block (psf, pms) ; in wavlike_msadpcm_init()
180 { pms->samples = pms->dummydata ; in wavlike_msadpcm_init()
182 pms->samplecount = 0 ; in wavlike_msadpcm_init()
198 msadpcm_get_bpred (SF_PRIVATE *psf, MSADPCM_PRIVATE *pms, unsigned char value) in msadpcm_get_bpred() argument
200 { if (pms->sync_error == 0) in msadpcm_get_bpred()
201 { pms->sync_error = 1 ; in msadpcm_get_bpred()
211 msadpcm_decode_block (SF_PRIVATE *psf, MSADPCM_PRIVATE *pms) in msadpcm_decode_block() argument
219 pms->blockcount ++ ; in msadpcm_decode_block()
220 pms->samplecount = 0 ; in msadpcm_decode_block()
222 if (pms->blockcount > pms->blocks) in msadpcm_decode_block()
223 { memset (pms->samples, 0, pms->samplesperblock * pms->channels) ; in msadpcm_decode_block()
227 if ((k = psf_fread (pms->block, 1, pms->blocksize, psf)) != pms->blocksize) in msadpcm_decode_block()
228 { psf_log_printf (psf, "*** Warning : short read (%d != %d).\n", k, pms->blocksize) ; in msadpcm_decode_block()
235 if (pms->channels == 1) in msadpcm_decode_block()
236 { bpred [0] = msadpcm_get_bpred (psf, pms, pms->block [0]) ; in msadpcm_decode_block()
238 chan_idelta [0] = pms->block [1] | (pms->block [2] << 8) ; in msadpcm_decode_block()
241 pms->samples [1] = pms->block [3] | (pms->block [4] << 8) ; in msadpcm_decode_block()
242 pms->samples [0] = pms->block [5] | (pms->block [6] << 8) ; in msadpcm_decode_block()
246 { bpred [0] = msadpcm_get_bpred (psf, pms, pms->block [0]) ; in msadpcm_decode_block()
247 bpred [1] = msadpcm_get_bpred (psf, pms, pms->block [1]) ; in msadpcm_decode_block()
249 chan_idelta [0] = pms->block [2] | (pms->block [3] << 8) ; in msadpcm_decode_block()
250 chan_idelta [1] = pms->block [4] | (pms->block [5] << 8) ; in msadpcm_decode_block()
252 pms->samples [2] = pms->block [6] | (pms->block [7] << 8) ; in msadpcm_decode_block()
253 pms->samples [3] = pms->block [8] | (pms->block [9] << 8) ; in msadpcm_decode_block()
255 pms->samples [0] = pms->block [10] | (pms->block [11] << 8) ; in msadpcm_decode_block()
256 pms->samples [1] = pms->block [12] | (pms->block [13] << 8) ; in msadpcm_decode_block()
276 sampleindx = 2 * pms->channels ; in msadpcm_decode_block()
277 while (blockindx < pms->blocksize) in msadpcm_decode_block()
278 { bytecode = pms->block [blockindx++] ; in msadpcm_decode_block()
279 pms->samples [sampleindx++] = (bytecode >> 4) & 0x0F ; in msadpcm_decode_block()
280 pms->samples [sampleindx++] = bytecode & 0x0F ; in msadpcm_decode_block()
285 for (k = 2 * pms->channels ; k < (pms->samplesperblock * pms->channels) ; k ++) in msadpcm_decode_block()
286 { chan = (pms->channels > 1) ? (k % 2) : 0 ; in msadpcm_decode_block()
288 bytecode = pms->samples [k] & 0xF ; in msadpcm_decode_block()
298 predict = ((pms->samples [k - pms->channels] * AdaptCoeff1 [bpred [chan]]) in msadpcm_decode_block()
299 …+ (pms->samples [k - 2 * pms->channels] * AdaptCoeff2 [bpred [chan]])) >> 8 ; /* => / 256 => FIXED… in msadpcm_decode_block()
307 pms->samples [k] = current ; in msadpcm_decode_block()
314 msadpcm_read_block (SF_PRIVATE *psf, MSADPCM_PRIVATE *pms, short *ptr, int len) in msadpcm_read_block() argument
318 { if (pms->blockcount >= pms->blocks && pms->samplecount >= pms->samplesperblock) in msadpcm_read_block()
323 if (pms->samplecount >= pms->samplesperblock) in msadpcm_read_block()
324 if (msadpcm_decode_block (psf, pms) != 0) in msadpcm_read_block()
327 count = (pms->samplesperblock - pms->samplecount) * pms->channels ; in msadpcm_read_block()
330 …memcpy (&(ptr [indx]), &(pms->samples [pms->samplecount * pms->channels]), count * sizeof (short))… in msadpcm_read_block()
332 pms->samplecount += count / pms->channels ; in msadpcm_read_block()
341 { MSADPCM_PRIVATE *pms ; in msadpcm_read_s() local
347 pms = (MSADPCM_PRIVATE*) psf->codec_data ; in msadpcm_read_s()
352 if ((count = msadpcm_read_block (psf, pms, ptr, readcount)) <= 0) in msadpcm_read_s()
366 { MSADPCM_PRIVATE *pms ; in msadpcm_read_i() local
374 pms = (MSADPCM_PRIVATE*) psf->codec_data ; in msadpcm_read_i()
381 if ((count = msadpcm_read_block (psf, pms, sptr, readcount)) <= 0) in msadpcm_read_i()
396 { MSADPCM_PRIVATE *pms ; in msadpcm_read_f() local
405 pms = (MSADPCM_PRIVATE*) psf->codec_data ; in msadpcm_read_f()
413 if ((count = msadpcm_read_block (psf, pms, sptr, readcount)) <= 0) in msadpcm_read_f()
428 { MSADPCM_PRIVATE *pms ; in msadpcm_read_d() local
437 pms = (MSADPCM_PRIVATE*) psf->codec_data ; in msadpcm_read_d()
445 if ((count = msadpcm_read_block (psf, pms, sptr, readcount)) <= 0) in msadpcm_read_d()
461 { MSADPCM_PRIVATE *pms ; in msadpcm_seek() local
466 pms = (MSADPCM_PRIVATE*) psf->codec_data ; in msadpcm_seek()
475 pms->blockcount = 0 ; in msadpcm_seek()
476 msadpcm_decode_block (psf, pms) ; in msadpcm_seek()
477 pms->samplecount = 0 ; in msadpcm_seek()
481 if (offset < 0 || offset > pms->blocks * pms->samplesperblock) in msadpcm_seek()
486 newblock = offset / pms->samplesperblock ; in msadpcm_seek()
487 newsample = offset % pms->samplesperblock ; in msadpcm_seek()
490 { psf_fseek (psf, psf->dataoffset + newblock * pms->blocksize, SEEK_SET) ; in msadpcm_seek()
491 pms->blockcount = newblock ; in msadpcm_seek()
492 msadpcm_decode_block (psf, pms) ; in msadpcm_seek()
493 pms->samplecount = newsample ; in msadpcm_seek()
501 return newblock * pms->samplesperblock + newsample ; in msadpcm_seek()
520 msadpcm_encode_block (SF_PRIVATE *psf, MSADPCM_PRIVATE *pms) in msadpcm_encode_block() argument
526 choose_predictor (pms->channels, pms->samples, bpred, idelta) ; in msadpcm_encode_block()
530 if (pms->channels == 1) in msadpcm_encode_block()
531 { pms->block [0] = bpred [0] ; in msadpcm_encode_block()
532 pms->block [1] = idelta [0] & 0xFF ; in msadpcm_encode_block()
533 pms->block [2] = idelta [0] >> 8 ; in msadpcm_encode_block()
534 pms->block [3] = pms->samples [1] & 0xFF ; in msadpcm_encode_block()
535 pms->block [4] = pms->samples [1] >> 8 ; in msadpcm_encode_block()
536 pms->block [5] = pms->samples [0] & 0xFF ; in msadpcm_encode_block()
537 pms->block [6] = pms->samples [0] >> 8 ; in msadpcm_encode_block()
544 for (k = 2 ; k < pms->samplesperblock ; k++) in msadpcm_encode_block()
545 …{ predict = (pms->samples [k-1] * AdaptCoeff1 [bpred [0]] + pms->samples [k-2] * AdaptCoeff2 [bpre… in msadpcm_encode_block()
546 errordelta = (pms->samples [k] - predict) / idelta [0] ; in msadpcm_encode_block()
561 { pms->block [blockindx++] = byte ; in msadpcm_encode_block()
568 pms->samples [k] = newsamp ; in msadpcm_encode_block()
573 pms->block [0] = bpred [0] ; in msadpcm_encode_block()
574 pms->block [1] = bpred [1] ; in msadpcm_encode_block()
576 pms->block [2] = idelta [0] & 0xFF ; in msadpcm_encode_block()
577 pms->block [3] = idelta [0] >> 8 ; in msadpcm_encode_block()
578 pms->block [4] = idelta [1] & 0xFF ; in msadpcm_encode_block()
579 pms->block [5] = idelta [1] >> 8 ; in msadpcm_encode_block()
581 pms->block [6] = pms->samples [2] & 0xFF ; in msadpcm_encode_block()
582 pms->block [7] = pms->samples [2] >> 8 ; in msadpcm_encode_block()
583 pms->block [8] = pms->samples [3] & 0xFF ; in msadpcm_encode_block()
584 pms->block [9] = pms->samples [3] >> 8 ; in msadpcm_encode_block()
586 pms->block [10] = pms->samples [0] & 0xFF ; in msadpcm_encode_block()
587 pms->block [11] = pms->samples [0] >> 8 ; in msadpcm_encode_block()
588 pms->block [12] = pms->samples [1] & 0xFF ; in msadpcm_encode_block()
589 pms->block [13] = pms->samples [1] >> 8 ; in msadpcm_encode_block()
595 for (k = 4 ; k < 2 * pms->samplesperblock ; k++) in msadpcm_encode_block()
598 …predict = (pms->samples [k-2] * AdaptCoeff1 [bpred [chan]] + pms->samples [k-4] * AdaptCoeff2 [bpr… in msadpcm_encode_block()
599 errordelta = (pms->samples [k] - predict) / idelta [chan] ; in msadpcm_encode_block()
617 { pms->block [blockindx++] = byte ; in msadpcm_encode_block()
624 pms->samples [k] = newsamp ; in msadpcm_encode_block()
630 if ((k = psf_fwrite (pms->block, 1, pms->blocksize, psf)) != pms->blocksize) in msadpcm_encode_block()
631 psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", k, pms->blocksize) ; in msadpcm_encode_block()
633 memset (pms->samples, 0, pms->samplesperblock * sizeof (short)) ; in msadpcm_encode_block()
635 pms->blockcount ++ ; in msadpcm_encode_block()
636 pms->samplecount = 0 ; in msadpcm_encode_block()
642 msadpcm_write_block (SF_PRIVATE *psf, MSADPCM_PRIVATE *pms, const short *ptr, int len) in msadpcm_write_block() argument
646 { count = (pms->samplesperblock - pms->samplecount) * pms->channels ; in msadpcm_write_block()
651 …memcpy (&(pms->samples [pms->samplecount * pms->channels]), &(ptr [total]), count * sizeof (short)… in msadpcm_write_block()
653 pms->samplecount += count / pms->channels ; in msadpcm_write_block()
656 if (pms->samplecount >= pms->samplesperblock) in msadpcm_write_block()
657 msadpcm_encode_block (psf, pms) ; in msadpcm_write_block()
665 { MSADPCM_PRIVATE *pms ; in msadpcm_write_s() local
671 pms = (MSADPCM_PRIVATE*) psf->codec_data ; in msadpcm_write_s()
676 count = msadpcm_write_block (psf, pms, ptr, writecount) ; in msadpcm_write_s()
689 { MSADPCM_PRIVATE *pms ; in msadpcm_write_i() local
697 pms = (MSADPCM_PRIVATE*) psf->codec_data ; in msadpcm_write_i()
705 count = msadpcm_write_block (psf, pms, sptr, writecount) ; in msadpcm_write_i()
716 { MSADPCM_PRIVATE *pms ; in msadpcm_write_f() local
725 pms = (MSADPCM_PRIVATE*) psf->codec_data ; in msadpcm_write_f()
735 count = msadpcm_write_block (psf, pms, sptr, writecount) ; in msadpcm_write_f()
746 { MSADPCM_PRIVATE *pms ; in msadpcm_write_d() local
757 pms = (MSADPCM_PRIVATE*) psf->codec_data ; in msadpcm_write_d()
765 count = msadpcm_write_block (psf, pms, sptr, writecount) ; in msadpcm_write_d()
779 { MSADPCM_PRIVATE *pms ; in msadpcm_close() local
781 pms = (MSADPCM_PRIVATE*) psf->codec_data ; in msadpcm_close()
788 if (pms->samplecount && pms->samplecount < pms->samplesperblock) in msadpcm_close()
789 msadpcm_encode_block (psf, pms) ; in msadpcm_close()