Lines Matching refs:handle
75 SNDFILE *handle = (SNDFILE *) malloc(sizeof(SNDFILE)); in sf_open_read() local
76 handle->mode = SFM_READ; in sf_open_read()
77 handle->temp = NULL; in sf_open_read()
78 handle->stream = stream; in sf_open_read()
79 handle->info.format = SF_FORMAT_WAV; in sf_open_read()
209 handle->bytesPerFrame = bytesPerFrame; in sf_open_read()
210 handle->info.samplerate = samplerate; in sf_open_read()
211 handle->info.channels = channels; in sf_open_read()
214 handle->info.format |= SF_FORMAT_PCM_U8; in sf_open_read()
217 handle->info.format |= SF_FORMAT_PCM_16; in sf_open_read()
220 handle->info.format |= SF_FORMAT_PCM_24; in sf_open_read()
224 handle->info.format |= SF_FORMAT_FLOAT; in sf_open_read()
226 handle->info.format |= SF_FORMAT_PCM_32; in sf_open_read()
243 handle->remaining = chunkSize / handle->bytesPerFrame; in sf_open_read()
244 handle->info.frames = handle->remaining; in sf_open_read()
280 *info = handle->info; in sf_open_read()
281 return handle; in sf_open_read()
284 free(handle); in sf_open_read()
367 SNDFILE *handle = (SNDFILE *) malloc(sizeof(SNDFILE)); in sf_open_write() local
368 handle->mode = SFM_WRITE; in sf_open_write()
369 handle->temp = NULL; in sf_open_write()
370 handle->stream = stream; in sf_open_write()
371 handle->bytesPerFrame = blockAlignment; in sf_open_write()
372 handle->remaining = 0; in sf_open_write()
373 handle->info = *info; in sf_open_write()
374 return handle; in sf_open_write()
398 void sf_close(SNDFILE *handle) in sf_close() argument
400 if (handle == NULL) in sf_close()
402 free(handle->temp); in sf_close()
403 if (handle->mode == SFM_WRITE) { in sf_close()
404 (void) fflush(handle->stream); in sf_close()
405 rewind(handle->stream); in sf_close()
407 size_t extra = (handle->info.format & SF_FORMAT_SUBMASK) == SF_FORMAT_FLOAT ? 14 : 0; in sf_close()
408 (void) fread(wav, 44 + extra, 1, handle->stream); in sf_close()
409 unsigned dataSize = handle->remaining * handle->bytesPerFrame; in sf_close()
412 rewind(handle->stream); in sf_close()
413 (void) fwrite(wav, 44 + extra, 1, handle->stream); in sf_close()
415 (void) fclose(handle->stream); in sf_close()
416 free(handle); in sf_close()
419 sf_count_t sf_readf_short(SNDFILE *handle, short *ptr, sf_count_t desiredFrames) in sf_readf_short() argument
421 if (handle == NULL || handle->mode != SFM_READ || ptr == NULL || !handle->remaining || in sf_readf_short()
425 if (handle->remaining < (size_t) desiredFrames) { in sf_readf_short()
426 desiredFrames = handle->remaining; in sf_readf_short()
429 size_t desiredBytes = desiredFrames * handle->bytesPerFrame; in sf_readf_short()
432 unsigned format = handle->info.format & SF_FORMAT_SUBMASK; in sf_readf_short()
435 actualBytes = fread(temp, sizeof(char), desiredBytes, handle->stream); in sf_readf_short()
437 actualBytes = fread(ptr, sizeof(char), desiredBytes, handle->stream); in sf_readf_short()
439 size_t actualFrames = actualBytes / handle->bytesPerFrame; in sf_readf_short()
440 handle->remaining -= actualFrames; in sf_readf_short()
443 memcpy_to_i16_from_u8(ptr, (unsigned char *) ptr, actualFrames * handle->info.channels); in sf_readf_short()
447 my_swab(ptr, actualFrames * handle->info.channels); in sf_readf_short()
450 memcpy_to_i16_from_i32(ptr, (const int *) temp, actualFrames * handle->info.channels); in sf_readf_short()
454 memcpy_to_i16_from_float(ptr, (const float *) temp, actualFrames * handle->info.channels); in sf_readf_short()
458 memcpy_to_i16_from_p24(ptr, (const uint8_t *) temp, actualFrames * handle->info.channels); in sf_readf_short()
462 memset(ptr, 0, actualFrames * handle->info.channels * sizeof(short)); in sf_readf_short()
468 sf_count_t sf_readf_float(SNDFILE *handle, float *ptr, sf_count_t desiredFrames) in sf_readf_float() argument
470 if (handle == NULL || handle->mode != SFM_READ || ptr == NULL || !handle->remaining || in sf_readf_float()
474 if (handle->remaining < (size_t) desiredFrames) { in sf_readf_float()
475 desiredFrames = handle->remaining; in sf_readf_float()
478 size_t desiredBytes = desiredFrames * handle->bytesPerFrame; in sf_readf_float()
481 unsigned format = handle->info.format & SF_FORMAT_SUBMASK; in sf_readf_float()
484 actualBytes = fread(temp, sizeof(char), desiredBytes, handle->stream); in sf_readf_float()
486 actualBytes = fread(ptr, sizeof(char), desiredBytes, handle->stream); in sf_readf_float()
488 size_t actualFrames = actualBytes / handle->bytesPerFrame; in sf_readf_float()
489 handle->remaining -= actualFrames; in sf_readf_float()
493 actualFrames * handle->info.channels); in sf_readf_float()
497 memcpy_to_float_from_i16(ptr, (const short *) temp, actualFrames * handle->info.channels); in sf_readf_float()
501 memcpy_to_float_from_i32(ptr, (const int *) ptr, actualFrames * handle->info.channels); in sf_readf_float()
506 memcpy_to_float_from_p24(ptr, (const uint8_t *) temp, actualFrames * handle->info.channels); in sf_readf_float()
510 memset(ptr, 0, actualFrames * handle->info.channels * sizeof(float)); in sf_readf_float()
516 sf_count_t sf_readf_int(SNDFILE *handle, int *ptr, sf_count_t desiredFrames) in sf_readf_int() argument
518 if (handle == NULL || handle->mode != SFM_READ || ptr == NULL || !handle->remaining || in sf_readf_int()
522 if (handle->remaining < (size_t) desiredFrames) { in sf_readf_int()
523 desiredFrames = handle->remaining; in sf_readf_int()
526 size_t desiredBytes = desiredFrames * handle->bytesPerFrame; in sf_readf_int()
528 unsigned format = handle->info.format & SF_FORMAT_SUBMASK; in sf_readf_int()
532 actualBytes = fread(temp, sizeof(char), desiredBytes, handle->stream); in sf_readf_int()
534 actualBytes = fread(ptr, sizeof(char), desiredBytes, handle->stream); in sf_readf_int()
536 size_t actualFrames = actualBytes / handle->bytesPerFrame; in sf_readf_int()
537 handle->remaining -= actualFrames; in sf_readf_int()
541 actualFrames * handle->info.channels); in sf_readf_int()
545 memcpy_to_i32_from_i16(ptr, (const short *) temp, actualFrames * handle->info.channels); in sf_readf_int()
551 memcpy_to_i32_from_float(ptr, (const float *) ptr, actualFrames * handle->info.channels); in sf_readf_int()
554 memcpy_to_i32_from_p24(ptr, (const uint8_t *) temp, actualFrames * handle->info.channels); in sf_readf_int()
558 memset(ptr, 0, actualFrames * handle->info.channels * sizeof(int)); in sf_readf_int()
564 sf_count_t sf_writef_short(SNDFILE *handle, const short *ptr, sf_count_t desiredFrames) in sf_writef_short() argument
566 if (handle == NULL || handle->mode != SFM_WRITE || ptr == NULL || desiredFrames <= 0) in sf_writef_short()
568 size_t desiredBytes = desiredFrames * handle->bytesPerFrame; in sf_writef_short()
570 switch (handle->info.format & SF_FORMAT_SUBMASK) { in sf_writef_short()
572 handle->temp = realloc(handle->temp, desiredBytes); in sf_writef_short()
573 memcpy_to_u8_from_i16(handle->temp, ptr, desiredBytes); in sf_writef_short()
574 actualBytes = fwrite(handle->temp, sizeof(char), desiredBytes, handle->stream); in sf_writef_short()
579 actualBytes = fwrite(ptr, sizeof(char), desiredBytes, handle->stream); in sf_writef_short()
581 handle->temp = realloc(handle->temp, desiredBytes); in sf_writef_short()
582 memcpy(handle->temp, ptr, desiredBytes); in sf_writef_short()
583 my_swab((short *) handle->temp, desiredFrames * handle->info.channels); in sf_writef_short()
584 actualBytes = fwrite(handle->temp, sizeof(char), desiredBytes, handle->stream); in sf_writef_short()
588 handle->temp = realloc(handle->temp, desiredBytes); in sf_writef_short()
589 memcpy_to_float_from_i16((float *) handle->temp, ptr, in sf_writef_short()
590 desiredFrames * handle->info.channels); in sf_writef_short()
591 actualBytes = fwrite(handle->temp, sizeof(char), desiredBytes, handle->stream); in sf_writef_short()
596 size_t actualFrames = actualBytes / handle->bytesPerFrame; in sf_writef_short()
597 handle->remaining += actualFrames; in sf_writef_short()
601 sf_count_t sf_writef_float(SNDFILE *handle, const float *ptr, sf_count_t desiredFrames) in sf_writef_float() argument
603 if (handle == NULL || handle->mode != SFM_WRITE || ptr == NULL || desiredFrames <= 0) in sf_writef_float()
605 size_t desiredBytes = desiredFrames * handle->bytesPerFrame; in sf_writef_float()
607 switch (handle->info.format & SF_FORMAT_SUBMASK) { in sf_writef_float()
609 actualBytes = fwrite(ptr, sizeof(char), desiredBytes, handle->stream); in sf_writef_float()
612 handle->temp = realloc(handle->temp, desiredBytes); in sf_writef_float()
613 memcpy_to_i16_from_float((short *) handle->temp, ptr, in sf_writef_float()
614 desiredFrames * handle->info.channels); in sf_writef_float()
615 actualBytes = fwrite(handle->temp, sizeof(char), desiredBytes, handle->stream); in sf_writef_float()
621 size_t actualFrames = actualBytes / handle->bytesPerFrame; in sf_writef_float()
622 handle->remaining += actualFrames; in sf_writef_float()
626 sf_count_t sf_writef_int(SNDFILE *handle, const int *ptr, sf_count_t desiredFrames) in sf_writef_int() argument
628 if (handle == NULL || handle->mode != SFM_WRITE || ptr == NULL || desiredFrames <= 0) in sf_writef_int()
630 size_t desiredBytes = desiredFrames * handle->bytesPerFrame; in sf_writef_int()
632 switch (handle->info.format & SF_FORMAT_SUBMASK) { in sf_writef_int()
634 actualBytes = fwrite(ptr, sizeof(char), desiredBytes, handle->stream); in sf_writef_int()
639 size_t actualFrames = actualBytes / handle->bytesPerFrame; in sf_writef_int()
640 handle->remaining += actualFrames; in sf_writef_int()