MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / SaveHeader

Method SaveHeader

stream_audio/osfarchive.cpp:177–225  ·  view source on GitHub ↗

write out operations.

Source from the content-addressed store, hash-verified

175
176// write out operations.
177bool OSFArchive::SaveHeader(uint8_t type, uint8_t comp, uint8_t flags, uint32_t rate, uint32_t length, void *hdr, const char *name) {
178 char chbuf[OSF_HDR_SIZE];
179 int hdrstart, hdrcur;
180
181 if (!m_fp || !m_writemode)
182 return false;
183
184 // write out data.
185 try {
186 char osftitle[OSF_HDR_TITLE_LEN];
187 memset((uint8_t *)chbuf, 0, OSF_HDR_SIZE);
188 cf_WriteBytes((uint8_t *)chbuf, OSF_HDR_SIZE, m_fp);
189 cfseek(m_fp, -OSF_HDR_SIZE, SEEK_CUR);
190
191 hdrstart = cftell(m_fp);
192 if (!cf_WriteBytes((uint8_t *)OSF_TAG, strlen(OSF_TAG), m_fp))
193 return false;
194
195 cf_WriteByte(m_fp, (int8_t)type);
196 cf_WriteByte(m_fp, (int8_t)comp);
197 cf_WriteByte(m_fp, (int8_t)flags);
198
199 if (type == OSF_DIGITAL_STRM) {
200 tOSFDigiHdr *digihdr = (tOSFDigiHdr *)hdr;
201 cf_WriteByte(m_fp, (rate == 11025) ? 11 : (rate == 22050) ? 22 : (rate == 44100) ? 44 : 0);
202 cf_WriteInt(m_fp, (int)digihdr->measure);
203 } else {
204 return false;
205 }
206
207 cf_WriteInt(m_fp, (int)length);
208 hdrcur = cftell(m_fp);
209
210 if ((hdrcur - hdrstart) > OSF_HDR_TITLE_OFS) {
211 mprintf(0, "stream header too big for title!\n");
212 return false;
213 }
214
215 cfseek(m_fp, OSF_HDR_TITLE_OFS - (hdrcur - hdrstart), SEEK_CUR);
216 strncpy(osftitle, name, OSF_HDR_TITLE_LEN);
217 osftitle[OSF_HDR_TITLE_LEN - 1] = 0;
218 if (!cf_WriteBytes((uint8_t *)name, OSF_HDR_TITLE_LEN, m_fp))
219 return false;
220 } catch (...) {
221 return false;
222 }
223
224 return true;
225}
226
227bool OSFArchive::WriteBlock(uint8_t *blk, int size) { return (cf_WriteBytes(blk, size, m_fp) < size) ? false : true; }
228

Callers 2

SaveDigitalStreamMethod · 0.80
taunt_ImportWaveFunction · 0.80

Calls 5

cf_WriteBytesFunction · 0.85
cfseekFunction · 0.85
cftellFunction · 0.85
cf_WriteByteFunction · 0.85
cf_WriteIntFunction · 0.85

Tested by

no test coverage detected