source: oup/releases/0.22a/Unit4_Exporters.pas@ 836

Last change on this file since 836 was 22, checked in by alloc, 18 years ago
File size: 5.9 KB
Line 
1UNIT Unit4_Exporters;
2INTERFACE
3USES Classes, Dialogs, StrUtils, SysUtils, Math, Unit3_data, Unit6_imgfuncs;
4
5PROCEDURE ExportDatFile(fileid:LongWord; filename:String);
6
7FUNCTION ExportSNDD(fileid:LongWord; filename:String; convert:Boolean):Integer;
8FUNCTION ExportTRAC(fileid:LongWord; filename:String; convert:Boolean):Integer;
9FUNCTION ExportTXAN(fileid:LongWord; filename:String; convert:Boolean):Integer;
10FUNCTION ExportTXMB(fileid:LongWord; filename:String; convert:Boolean):Integer;
11FUNCTION ExportTXMP(fileid:LongWord; filename:String; convert:Boolean):Integer;
12VAR
13 ExportHandlers:Array[1..1] OF TExportHandlers=(
14// (Ext:'ABNA'; needed:False),
15 //(Ext:'AGDB'; needed:False),
16 (Ext:'SNDD'; needed:True; Handler:ExportSNDD)
17{ (Ext:'TRAC'; needed:True; Handler:ExportTRAC),
18 (Ext:'TXAN'; needed:True; Handler:ExportTXAN),
19 (Ext:'TXMB'; needed:True; Handler:ExportTXMB),
20 (Ext:'TXMP'; needed:True; Handler:ExportTXMP)
21} );
22
23
24
25IMPLEMENTATION
26USES Unit2_functions;
27
28PROCEDURE ExportDatFile(fileid:LongWord; filename:String);
29 VAR
30 filestream:TFileStream;
31 data:Tdata;
32 BEGIN
33 data:=LoadDatFile(fileid);
34 IF FileExists(filename) THEN BEGIN
35 filestream:=TFileStream.Create(filename,fmOpenReadWrite);
36 filestream.Seek(0,soFromEnd);
37 END ELSE BEGIN
38 filestream:=TFileStream.Create(filename,fmCreate);
39 END;
40 filestream.Write(data[0],Length(data));
41 filestream.Free;
42 END;
43
44FUNCTION ExportSNDD;
45{ CONST
46 WAVheader:Array[0..0] OF Byte=(
47 Ord('R'),Ord('I'),Ord('F'),Ord('F'),0,0,0,0,Ord('W'),Ord('A'),Ord('V'),Ord('E'),
48 Ord('f'),Ord('m'),Ord('t'),Ord(' '),24,0,0,0,
49 );
50} TYPE
51 TDatData=RECORD
52 _fileid:LongWord;
53 level:LongWord;
54 Flag:LongWord;
55 FormatTag:Word;
56 ChanNo:Word;
57 SampleRate:LongWord;
58 BytesPSec:LongWord;
59 BPSample:LongWord;
60 BitsPS:LongWord;
61 Unknown:Array[1..7] OF LongWord;
62 Unknown2:Word;
63 RawSize:LongWord;
64 RawPos:LongWord;
65 END;
66 VAR
67 filestream:TFileStream;
68
69 DatData:TDatData;
70 //Wave Header Stuff
71 ASCII_Group:LongWord; //"RIFF"
72 WAV_Len:LongWord;
73 ASCII_WAV:LongWord; //"WAVE"
74 ASCII_FMT:LongWord; //"fmt "
75 WAV_FMT_Len:LongWord;
76 ASCII_DATA:LongWord; //"data"
77 WAV_FolLen:LongWord;
78
79 data:Tdata;
80 BEGIN
81 Result:=export_noerror;
82 LoadDatFilePart(fileid,0,SizeOf(DatData),@DatData);
83 WITH DatData DO BEGIN
84 //Initializing Header vars
85 ASCII_Group:=1179011410; // 'RIFF'
86 WAV_Len:=RAWSize+70;
87 ASCII_WAV:=1163280727; // 'WAVE'
88 ASCII_FMT:=544501094; // 'fmt '
89 WAV_FMT_Len:=50; // 50 bytes
90 ASCII_DATA:=1635017060; // 'data'
91 WAV_FolLen:=RAWSize;
92 SetLength(data,RAWSize);
93 LoadRawFile(fileid,68,Length(data),data);
94
95 filestream:=TFileStream.Create(filename+'.raw',fmCreate);
96 filestream.Write(data[0],Length(data));
97 filestream.Free;
98
99 IF convert THEN BEGIN
100 //Now start packing this into a neat wave...
101 filestream:=TFileStream.Create(filename+'.wav',fmCreate);
102 filestream.Write(ASCII_Group,SizeOf(ASCII_Group));
103 filestream.Write(WAV_Len,SizeOf(WAV_Len));
104 filestream.Write(ASCII_WAV,SizeOf(ASCII_WAV));
105 filestream.Write(ASCII_FMT,SizeOf(ASCII_FMT));
106 filestream.Write(WAV_FMT_Len,SizeOf(WAV_FMT_Len));
107 filestream.Write(ChanNo,SizeOf(ChanNo));
108 filestream.Write(Samplerate,SizeOf(Samplerate));
109 filestream.Write(BytesPSec,SizeOf(BytesPSec));
110 filestream.Write(BPSample,SizeOf(BPSample));
111 filestream.Write(BitsPS,SizeOf(BitsPS));
112 filestream.Write(Unknown[1],SizeOf(Unknown));
113 filestream.Write(Unknown2,SizeOf(Unknown2));
114 filestream.Write(ASCII_DATA,SizeOf(ASCII_DATA));
115 filestream.Write(WAV_FolLen,SizeOf(WAV_FolLen));
116 filestream.Write(data[0],Length(data));
117 filestream.Free;
118 END;
119 END;
120 END;
121
122FUNCTION ExportTRAC;
123 VAR
124 link:LongWord;
125 linkcount:Word;
126 i:LongWord;
127 BEGIN
128 Result:=export_noerror;
129
130 LoadDatFilePart(fileid,$18,SizeOf(link),@link);
131 link:=link DIV 256;
132
133 LoadDatFilePart(fileid,$1E,SizeOf(linkcount),@linkcount);
134 FOR i:=1 TO linkcount DO BEGIN
135 LoadDatFilePart(fileid,$20+(i-1)*12+8,SizeOf(link),@link);
136 link:=link DIV 256;
137 END;
138 END;
139
140FUNCTION ExportTXAN;
141 VAR
142 loop_speed,unknown:Word;
143 linkcount:LongWord;
144 link:LongWord;
145 i:Byte;
146 BEGIN
147 Result:=export_noerror;
148
149 LoadDatFilePart(fileid,$14,SizeOf(loop_speed),@loop_speed);
150 LoadDatFilePart(fileid,$16,SizeOf(unknown),@unknown);
151
152 LoadDatFilePart(fileid,$1C,SizeOf(linkcount),@linkcount);
153 FOR i:=0 TO linkcount-1 DO BEGIN
154 LoadDatFilePart(fileid,$20+i*4,SizeOf(link),@link);
155 link:=link DIV 256;
156 IF link=0 THEN link:=fileid-1;
157 END;
158 END;
159
160FUNCTION ExportTXMB;
161 VAR
162 filestream:TFileStream;
163 img:TImgPackage;
164 data:Tdata;
165 BEGIN
166 Result:=export_noerror;
167 IF convert THEN BEGIN
168 img:=LoadTXMBconnected(fileid);
169 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
170 filestream:=TFileStream.Create(filename+'.bmp',fmCreate);
171 filestream.Write(data[0],Length(data));
172 filestream.Free;
173 END;
174 END;
175
176FUNCTION ExportTXMP;
177 VAR
178 filestream:TFileStream;
179 img:TImgPackage;
180 BEGIN
181 Result:=export_noerror;
182 img:=LoadImgData(fileid);
183
184 filestream:=TFileStream.Create(filename+'.raw',fmCreate);
185 filestream.Write(img.imgdata[0],Length(img.imgdata));
186 filestream.Free;
187
188 IF convert THEN BEGIN
189 img.imgdata:=ImgdataToBMP(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
190 filestream:=TFileStream.Create(filename+'.bmp',fmCreate);
191 filestream.Write(img.imgdata[0],Length(img.imgdata));
192 filestream.Free;
193 END;
194 END;
195
196END.
Note: See TracBrowser for help on using the repository browser.