status _af_wave_update (AFfilehandle file) { _Track *track; _WAVEInfo *wave = (_WAVEInfo *) file->formatSpecific; track = _af_filehandle_get_track(file, AF_DEFAULT_TRACK); if (track->fpos_first_frame != 0) { u_int32_t dataLength, fileLength; /* Update the frame count chunk if present. */ WriteFrameCount(file); /* Update the length of the data chunk. */ af_fseek(file->fh, wave->dataSizeOffset, SEEK_SET); /* We call _af_format_frame_size to calculate the frame size of normal PCM data or compressed data. */ dataLength = (u_int32_t) track->totalfframes * _af_format_frame_size(&track->f, AF_FALSE); dataLength = HOST_TO_LENDIAN_INT32(dataLength); af_fwrite(&dataLength, 4, 1, file->fh); /* Update the length of the RIFF chunk. */ fileLength = (u_int32_t) af_flength(file->fh); fileLength -= 8; fileLength = HOST_TO_LENDIAN_INT32(fileLength); af_fseek(file->fh, 4, SEEK_SET); af_fwrite(&fileLength, 4, 1, file->fh); } /* Write the actual data that was set after initializing the miscellaneous IDs. The size of the data will be unchanged. */ WriteMiscellaneous(file); /* Write the new positions; the size of the data will be unchanged. */ WriteCues(file); return AF_SUCCEED; }
status _af_wave_write_init (AFfilesetup setup, AFfilehandle filehandle) { uint32_t zero = 0; if (_af_filesetup_make_handle(setup, filehandle) == AF_FAIL) return AF_FAIL; filehandle->formatSpecific = waveinfo_new(); af_fseek(filehandle->fh, 0, SEEK_SET); af_fwrite("RIFF", 4, 1, filehandle->fh); af_fwrite(&zero, 4, 1, filehandle->fh); af_fwrite("WAVE", 4, 1, filehandle->fh); WriteMiscellaneous(filehandle); WriteCues(filehandle); WriteFormat(filehandle); WriteFrameCount(filehandle); WriteData(filehandle); return AF_SUCCEED; }