Mercurial > hg > dmlib
annotate dmwav.c @ 526:f7df57cafdd9
Add support for Interpaint (unpacked) and Doodle (unpacked) hires formats.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 22 Nov 2012 01:07:45 +0200 |
parents | 9622c139cb9f |
children | 7e73d733b96f |
rev | line source |
---|---|
205
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * DMLib |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * -- Wav file writing |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 * Programmed and designed by Matti 'ccr' Hamalainen |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 * (C) Copyright 2012 Tecnic Software productions (TNSP) |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 */ |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 #include "dmwav.h" |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 #include "dmfile.h" |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 BOOL dmWriteWAVChunk(FILE * f, DMWaveChunk *ch) |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 { |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 if (!dm_fwrite_str(f, ch->chunkID, 4)) return FALSE; |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 return dm_fwrite_le32(f, ch->chunkSize); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 } |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 void dmMakeWAVChunk(DMWaveChunk *ch, const char *chunkID, const Uint32 chunkSize) |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 { |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 memcpy(&(ch->chunkID), (const void *) chunkID, 4); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 ch->chunkSize = chunkSize; |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 } |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 void dmWriteWAVHeader(FILE *outFile, int sampBits, int sampFreq, int sampChn, size_t sampLen) |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 { |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 DMWaveFile wav; |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 // PCM WAVE chunk |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 dmMakeWAVChunk(&wav.chFormat, DM_WAVE_FMT_ID, (2 + 2 + 4 + 4 + 2 + 2)); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 wav.wFormatTag = DM_WAVE_FORMAT_PCM; |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 wav.nChannels = sampChn; |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 wav.nSamplesPerSec = sampFreq; |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 wav.nAvgBytesPerSec = (sampBits * sampChn * sampFreq) / 8; |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 wav.nBlockAlign = (sampBits * sampChn) / 8; |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 wav.wBitsPerSample = sampBits; |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 // Data chunk |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 dmMakeWAVChunk(&wav.chData, DM_WAVE_DATA_ID, (sampLen * wav.nBlockAlign)); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 // RIFF header |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 memcpy(&wav.riffID, (const void *) DM_WAVE_RIFF_ID, 4); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 memcpy(&wav.riffType, (const void *) DM_WAVE_WAVE_ID, 4); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 wav.fileSize = ((4 + 4 + 4) + wav.chFormat.chunkSize + wav.chData.chunkSize); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 // Write header |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 dm_fwrite_str(outFile, wav.riffID, sizeof(wav.riffID)); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 dm_fwrite_le32(outFile, wav.fileSize); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 dm_fwrite_str(outFile, wav.riffType, sizeof(wav.riffType)); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 dmWriteWAVChunk(outFile, &wav.chFormat); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 dm_fwrite_le16(outFile, wav.wFormatTag); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 dm_fwrite_le16(outFile, wav.nChannels); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 dm_fwrite_le32(outFile, wav.nSamplesPerSec); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 dm_fwrite_le32(outFile, wav.nAvgBytesPerSec); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 dm_fwrite_le16(outFile, wav.nBlockAlign); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 dm_fwrite_le16(outFile, wav.wBitsPerSample); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 dmWriteWAVChunk(outFile, &wav.chData); |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 } |