Home | History | Annotate | Download | only in audio_utils

Lines Matching refs:handle

97         SNDFILE *handle = (SNDFILE *) malloc(sizeof(SNDFILE));
98 handle->mode = SFM_READ;
99 handle->temp = NULL;
100 handle->stream = stream;
101 handle->bytesPerFrame = bytesPerFrame;
102 handle->remaining = dataSize / bytesPerFrame;
103 handle->info.frames = handle->remaining;
104 handle->info.samplerate = samplerate;
105 handle->info.channels = channels;
106 handle->info.format = SF_FORMAT_WAV;
108 handle->info.format |= SF_FORMAT_PCM_U8;
110 handle->info.format |= SF_FORMAT_PCM_16;
111 *info = handle->info;
112 return handle;
155 SNDFILE *handle = (SNDFILE *) malloc(sizeof(SNDFILE));
156 handle->mode = SFM_WRITE;
157 handle->temp = NULL;
158 handle->stream = stream;
159 handle->bytesPerFrame = blockAlignment;
160 handle->remaining = 0;
161 handle->info = *info;
162 return handle;
179 void sf_close(SNDFILE *handle)
181 if (handle == NULL)
183 free(handle->temp);
184 if (handle->mode == SFM_WRITE) {
185 (void) fflush(handle->stream);
186 rewind(handle->stream);
188 (void) fread(wav, sizeof(wav), 1, handle->stream);
189 unsigned dataSize = handle->remaining * handle->bytesPerFrame;
192 rewind(handle->stream);
193 (void) fwrite(wav, sizeof(wav), 1, handle->stream);
195 (void) fclose(handle->stream);
196 free(handle);
199 sf_count_t sf_readf_short(SNDFILE *handle, short *ptr, sf_count_t desiredFrames)
201 if (handle == NULL || handle->mode != SFM_READ || ptr == NULL || !handle->remaining ||
205 if (handle->remaining < (size_t) desiredFrames)
206 desiredFrames = handle->remaining;
207 size_t desiredBytes = desiredFrames * handle->bytesPerFrame;
209 size_t actualBytes = fread(ptr, sizeof(char), desiredBytes, handle->stream);
210 size_t actualFrames = actualBytes / handle->bytesPerFrame;
211 handle->remaining -= actualFrames;
212 switch (handle->info.format & SF_FORMAT_SUBMASK) {
214 memcpy_to_i16_from_u8(ptr, (unsigned char *) ptr, actualFrames * handle->info.channels);
218 my_swab(ptr, actualFrames * handle->info.channels);
224 sf_count_t sf_writef_short(SNDFILE *handle, const short *ptr, sf_count_t desiredFrames)
226 if (handle == NULL || handle->mode != SFM_WRITE || ptr == NULL || desiredFrames <= 0)
228 size_t desiredBytes = desiredFrames * handle->bytesPerFrame;
230 switch (handle->info.format & SF_FORMAT_SUBMASK) {
232 handle->temp = realloc(handle->temp, desiredBytes);
233 memcpy_to_u8_from_i16(handle->temp, ptr, desiredBytes);
234 actualBytes = fwrite(handle->temp, sizeof(char), desiredBytes, handle->stream);
239 actualBytes = fwrite(ptr, sizeof(char), desiredBytes, handle->stream);
241 handle->temp = realloc(handle->temp, desiredBytes);
242 memcpy(handle->temp, ptr, desiredBytes);
243 my_swab((short *) handle->temp, desiredFrames * handle->info.channels);
244 actualBytes = fwrite(handle->temp, sizeof(char), desiredBytes, handle->stream);
248 size_t actualFrames = actualBytes / handle->bytesPerFrame;
249 handle->remaining += actualFrames;