Mercurial > hg > dmlib
annotate src/dmwav.c @ 1315:7687412f9aef
Fix jssmod sample conversion flags storing .. urgh.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 20 Aug 2017 01:54:54 +0300 |
parents | e06abfde6c39 |
children |
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 { |
560
7e73d733b96f
Simplify wav chunk header writing slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
205
diff
changeset
|
13 return dm_fwrite_str(f, ch->chunkID, 4) && dm_fwrite_le32(f, ch->chunkSize); |
205
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 } |
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 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
|
18 { |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 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
|
20 ch->chunkSize = chunkSize; |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 } |
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 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
|
25 { |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 DMWaveFile wav; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
812
diff
changeset
|
27 |
205
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 // PCM WAVE chunk |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 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
|
30 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 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
|
32 wav.nChannels = sampChn; |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 wav.nSamplesPerSec = sampFreq; |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 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
|
35 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
|
36 wav.wBitsPerSample = sampBits; |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 // Data chunk |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 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
|
40 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 // RIFF header |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 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
|
43 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
|
44 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
|
45 |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 // Write header |
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 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
|
48 dm_fwrite_le32(outFile, wav.fileSize); |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
812
diff
changeset
|
49 |
205
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 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
|
51 dmWriteWAVChunk(outFile, &wav.chFormat); |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
812
diff
changeset
|
52 |
205
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 dm_fwrite_le16(outFile, wav.wBitsPerSample); |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
812
diff
changeset
|
59 |
205
9622c139cb9f
Separate the WAV header / chunk writing functions from mod2wav into dmwav.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 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
|
61 } |