Lines Matching refs:handle

70     SNDFILE *handle = (SNDFILE *) malloc(sizeof(SNDFILE));
71 handle->mode = SFM_READ;
72 handle->temp = NULL;
73 handle->stream = stream;
74 handle->info.format = SF_FORMAT_WAV;
172 handle->bytesPerFrame = bytesPerFrame;
173 handle->info.samplerate = samplerate;
174 handle->info.channels = channels;
177 handle->info.format |= SF_FORMAT_PCM_U8;
180 handle->info.format |= SF_FORMAT_PCM_16;
184 handle->info.format |= SF_FORMAT_FLOAT;
186 handle->info.format |= SF_FORMAT_PCM_32;
199 handle->remaining = chunkSize / handle->bytesPerFrame;
200 handle->info.frames = handle->remaining;
225 *info = handle->info;
226 return handle;
229 free(handle);
297 SNDFILE *handle = (SNDFILE *) malloc(sizeof(SNDFILE));
298 handle->mode = SFM_WRITE;
299 handle->temp = NULL;
300 handle->stream = stream;
301 handle->bytesPerFrame = blockAlignment;
302 handle->remaining = 0;
303 handle->info = *info;
304 return handle;
324 void sf_close(SNDFILE *handle)
326 if (handle == NULL)
328 free(handle->temp);
329 if (handle->mode == SFM_WRITE) {
330 (void) fflush(handle->stream);
331 rewind(handle->stream);
333 size_t extra = (handle->info.format & SF_FORMAT_SUBMASK) == SF_FORMAT_FLOAT ? 14 : 0;
334 (void) fread(wav, 44 + extra, 1, handle->stream);
335 unsigned dataSize = handle->remaining * handle->bytesPerFrame;
338 rewind(handle->stream);
339 (void) fwrite(wav, 44 + extra, 1, handle->stream);
341 (void) fclose(handle->stream);
342 free(handle);
345 sf_count_t sf_readf_short(SNDFILE *handle, short *ptr, sf_count_t desiredFrames)
347 if (handle == NULL || handle->mode != SFM_READ || ptr == NULL || !handle->remaining ||
351 if (handle->remaining < (size_t) desiredFrames)
352 desiredFrames = handle->remaining;
354 size_t desiredBytes = desiredFrames * handle->bytesPerFrame;
357 unsigned format = handle->info.format & SF_FORMAT_SUBMASK;
360 actualBytes = fread(temp, sizeof(char), desiredBytes, handle->stream);
362 actualBytes = fread(ptr, sizeof(char), desiredBytes, handle->stream);
364 size_t actualFrames = actualBytes / handle->bytesPerFrame;
365 handle->remaining -= actualFrames;
368 memcpy_to_i16_from_u8(ptr, (unsigned char *) ptr, actualFrames * handle->info.channels);
372 my_swab(ptr, actualFrames * handle->info.channels);
375 memcpy_to_i16_from_i32(ptr, (const int *) temp, actualFrames * handle->info.channels);
379 memcpy_to_i16_from_float(ptr, (const float *) temp, actualFrames * handle->info.channels);
383 memset(ptr, 0, actualFrames * handle->info.channels * sizeof(short));
389 sf_count_t sf_readf_float(SNDFILE *handle, float *ptr, sf_count_t desiredFrames)
394 sf_count_t sf_writef_short(SNDFILE *handle, const short *ptr, sf_count_t desiredFrames)
396 if (handle == NULL || handle->mode != SFM_WRITE || ptr == NULL || desiredFrames <= 0)
398 size_t desiredBytes = desiredFrames * handle->bytesPerFrame;
400 switch (handle->info.format & SF_FORMAT_SUBMASK) {
402 handle->temp = realloc(handle->temp, desiredBytes);
403 memcpy_to_u8_from_i16(handle->temp, ptr, desiredBytes);
404 actualBytes = fwrite(handle->temp, sizeof(char), desiredBytes, handle->stream);
409 actualBytes = fwrite(ptr, sizeof(char), desiredBytes, handle->stream);
411 handle->temp = realloc(handle->temp, desiredBytes);
412 memcpy(handle->temp, ptr, desiredBytes);
413 my_swab((short *) handle->temp, desiredFrames * handle->info.channels);
414 actualBytes = fwrite(handle->temp, sizeof(char), desiredBytes, handle->stream);
421 size_t actualFrames = actualBytes / handle->bytesPerFrame;
422 handle->remaining += actualFrames;
426 sf_count_t sf_writef_float(SNDFILE *handle, const float *ptr, sf_count_t desiredFrames)
428 if (handle == NULL || handle->mode != SFM_WRITE || ptr == NULL || desiredFrames <= 0)
430 size_t desiredBytes = desiredFrames * handle->bytesPerFrame;
432 switch (handle->info.format & SF_FORMAT_SUBMASK) {
434 actualBytes = fwrite(ptr, sizeof(char), desiredBytes, handle->stream);
441 size_t actualFrames = actualBytes / handle->bytesPerFrame;
442 handle->remaining += actualFrames;