annotate 3rdparty/packages/sierra/convutils/cc3snd.c @ 2076:b2820d3f1e38

Utils written by G. Major for VOL conversion to CoCo interpreter
author boisy
date Fri, 21 Jul 2006 14:41:13 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2076
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
1 /***********************************************************************************
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
2 * Program Name : cc3snd *
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
3 * Description : Converts AGI sounds for the AGI Coco interpreter. *
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
4 * Author : Guillaume Major *
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
5 * Date : July 18, 2006 *
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
6 * License : Freeware. Do whatever you want with it! *
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
7 ***********************************************************************************/
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
8
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
9 #include <stdio.h>
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
10 #include <ctype.h>
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
11 #include <string.h>
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
12 #include <stdlib.h>
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
13 #include <sys/stat.h>
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
14 #include <io.h>
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
15 #include <direct.h>
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
16 #include <windows.h>
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
17
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
18 /* Be sure to set the struct member alignment at 1 in the compiler settings */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
19
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
20 /* AGI sound format */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
21 struct MUSIC_NOTE {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
22 unsigned short duration;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
23 unsigned char tone_2;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
24 unsigned char tone_1;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
25 unsigned char attenuation;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
26 };
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
27
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
28 /* Coco AGI sound format */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
29 struct COCO_MUSIC_NOTE {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
30 unsigned char tone;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
31 unsigned char volume; /* 0x00: Silence, 0x3F: Full volume */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
32 unsigned char unused;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
33 unsigned char duration;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
34 };
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
35
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
36 /* Coco tone frequencies. The position of the freqency in the table gives the coco tone number. */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
37 unsigned short COCO_TONES_TABLE[] = {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
38 130, 138, 146, 155, 164, 174, 184, 195, 207, 220, 233, 246, // O3
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
39 261, 277, 293, 311, 329, 349, 369, 391, 415, 440, 466, 493, // O4
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
40 523, 554, 587, 622, 659, 698, 739, 783, 830, 880, 932, 987, // O5
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
41 1046, 1108, 1174, 1244, 1318, 1396, 1479, 1567, 1661, 1760, 1864, 1975, // O6
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
42 2093, 2217, 2349, 2489, 2637, 2793, 2959, 3135, 3322, 3520, 3729, 3951 // O7
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
43 };
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
44
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
45 /* Function prototypes */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
46 unsigned char GetCocoTone(unsigned short uiFreq);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
47 void ConvertSound(char *sInFile, char *sOutFile);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
48 void ShowUsage();
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
49
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
50 /* Main */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
51 int main(int argc, char **argv) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
52
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
53 char sInFile[MAX_PATH], sOutFile[MAX_PATH];
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
54 char sInPath[MAX_PATH], sOutPath[MAX_PATH];
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
55 char sFullPath[MAX_PATH];
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
56
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
57 long hFind;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
58 struct _finddata_t finddata;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
59
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
60 printf("\n");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
61 printf("cc3snd AGI sound resource converter for the Coco\n");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
62 printf("Version 1.0 (July 2006)\n\n");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
63
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
64 if (argc < 2) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
65 ShowUsage();
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
66 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
67
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
68 if (strcmp(argv[1], "-b") == 0 || strcmp(argv[1], "-B") == 0) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
69 if (argc < 3) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
70 ShowUsage();
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
71 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
72 else if (argc < 4) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
73 sInPath[0] = '\0';
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
74 strncpy(sOutPath, argv[2], MAX_PATH);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
75 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
76 else {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
77 strncpy(sInPath, argv[2], MAX_PATH);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
78 strncpy(sOutPath, argv[3], MAX_PATH);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
79 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
80 /* Get the list of files */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
81 if (sInPath[0] != '\0')
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
82 sprintf(sFullPath, "%s\\sound.???", sInPath);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
83 else
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
84 strncpy(sFullPath, "sound.???", 10);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
85 hFind = _findfirst(sFullPath, &finddata);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
86 if (hFind > -1) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
87 /* Make sure the output path exists */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
88 _mkdir(sOutPath);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
89 /* Loop through the sound files */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
90 do {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
91 if (!(finddata.attrib & _A_SUBDIR) ) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
92 if (sInPath[0] != '\0')
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
93 sprintf(sInFile, "%s\\%s", sInPath, finddata.name);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
94 else
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
95 strncpy(sInFile, finddata.name, strlen(finddata.name)+1);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
96 sprintf(sOutFile, "%s\\%s", sOutPath, finddata.name);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
97 ConvertSound(sInFile, sOutFile);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
98 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
99 else {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
100 printf("Skipping directory %s.\n", finddata.name);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
101 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
102 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
103 while (_findnext(hFind, &finddata) > -1);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
104 _findclose(hFind);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
105 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
106 else {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
107 printf("No SOUND file was found! The sound files name must match this format: sound.xxx where xxx is the number of the sound.\n");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
108 exit(1);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
109 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
110 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
111 else {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
112 if (argc < 2) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
113 ShowUsage();
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
114 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
115 else {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
116 strncpy(sInFile, argv[1], MAX_PATH);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
117 if (argc < 3) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
118 sprintf(sOutFile, "%s.cc3", argv[1]);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
119 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
120 else {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
121 strncpy(sOutFile, argv[2], MAX_PATH);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
122 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
123 ConvertSound(sInFile, sOutFile);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
124 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
125 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
126
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
127 printf("Done!\n\n");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
128
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
129 /* Exit normally */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
130 exit(0);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
131 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
132
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
133 /* Converts an AGI format sound file to the Coco AGI interpreter format */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
134 void ConvertSound(char *sInFile, char *sOutFile) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
135
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
136 FILE *infile, *outfile;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
137 unsigned short uiOffset;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
138 struct MUSIC_NOTE note;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
139 struct COCO_MUSIC_NOTE cocoNote;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
140 unsigned short uiFreq, uiFreqDiv;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
141
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
142 if ((infile = fopen(sInFile, "rb")) == NULL) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
143 perror("Error opening input file");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
144 exit(1);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
145 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
146
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
147 if ((outfile = fopen(sOutFile, "wb")) == NULL) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
148 perror("Error opening output file");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
149 exit(1);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
150 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
151
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
152 printf("Converting %s -> %s\n", sInFile, sOutFile);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
153
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
154 /* Get voice 1 offset */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
155 fseek(infile, 0, SEEK_SET);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
156 fread(&uiOffset, sizeof(unsigned short), 1, infile);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
157
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
158 /* Seek to voice 1 offset */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
159 fseek(infile, uiOffset, SEEK_SET);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
160 memset(&note, 0, sizeof(note));
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
161
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
162 while (!ferror(infile) && !feof(infile) && fread(&note, sizeof(note), 1, infile) && note.duration != 0xFFFF) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
163 /* Verify that it's not a noise tone */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
164 if (note.tone_1 >> 4 != 0x0E) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
165 /* Get the frequency divider */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
166 uiFreqDiv = (((note.tone_2 & 0x3F) << 4) + (note.tone_1 & 0x0F));
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
167 if (uiFreqDiv > 0) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
168 /* Get the frequency of the tone */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
169 uiFreq = 111860 / uiFreqDiv;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
170 /* Get the corresponding coco tone */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
171 cocoNote.tone = GetCocoTone(uiFreq);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
172 if ((note.attenuation & 0x0F) == 0x0F)
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
173 cocoNote.volume = 0x00;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
174 else
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
175 cocoNote.volume = 0x3F;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
176 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
177 else {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
178 /* Insert a silence if the frequency equals zero */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
179 cocoNote.tone = 0;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
180 cocoNote.volume = 0x00;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
181 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
182 cocoNote.unused = 0;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
183 cocoNote.duration = (unsigned char)note.duration / 6;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
184 /* Make sure the duration equals at least 1 or else the sound will play indefinitely */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
185 if (cocoNote.duration == 0)
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
186 cocoNote.duration = 1;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
187 /* Write the note to the file */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
188 fwrite(&cocoNote, sizeof(cocoNote), 1, outfile);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
189 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
190 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
191
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
192 /* Write the footer. The last 2 bytes seems to do nothing but every sound in KQ3 for the coco
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
193 ends with 0xFF and 2 bytes */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
194 fprintf(outfile, "%c%c%c", 0xFF, 0x00, 0x30);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
195
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
196 /* Close files */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
197 fclose(outfile);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
198 fclose(infile);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
199
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
200 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
201
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
202 /* Gets the coco tone number from the specified frequency */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
203 unsigned char GetCocoTone(unsigned short uiFreq) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
204
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
205 int count, i, iTone = 0;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
206
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
207 count = sizeof(COCO_TONES_TABLE) / sizeof(unsigned short);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
208
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
209 for (i = 0; i < count; i++) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
210 if (uiFreq <= COCO_TONES_TABLE[i]) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
211 iTone = i - 1;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
212 break;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
213 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
214 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
215
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
216 /* Make sure the tone is not negative */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
217 if (iTone < 0)
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
218 iTone = 0;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
219
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
220 return iTone;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
221
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
222 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
223
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
224 /* Shows usage */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
225 void ShowUsage() {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
226
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
227 printf("Usage: cc3snd input-file [output-file]\n");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
228 printf(" cc3snd -b [input-path] output-path (batch mode)\n");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
229
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
230 /* Exit normally */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
231 exit(0);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
232
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
233 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
234