Import the current wip animation datatype and subclasses. further development will...
[AROS.git] / workbench / classes / datatypes / 8svx / 8svxclass.c
blobeb1fa08b99ec902ad58a058b0d7927bb84d85499
1 /*
2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /**********************************************************************/
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
12 #include <exec/types.h>
13 #include <exec/memory.h>
14 #include <dos/dostags.h>
15 #include <intuition/imageclass.h>
16 #include <intuition/icclass.h>
17 #include <intuition/gadgetclass.h>
18 #include <intuition/cghooks.h>
19 #include <datatypes/datatypesclass.h>
20 #include <datatypes/soundclass.h>
22 #include <clib/alib_protos.h>
23 #include <proto/exec.h>
24 #include <proto/dos.h>
25 #include <proto/intuition.h>
26 #include <proto/utility.h>
27 #include <proto/iffparse.h>
28 #include <proto/datatypes.h>
30 #include <aros/symbolsets.h>
32 #define DEBUG 1
33 #include "debug.h"
35 #include "methods.h"
37 /* Open superclass */
38 ADD2LIBS("datatypes/sound.datatype", 0, struct Library *, SoundBase);
40 /**************************************************************************************************/
42 struct FileVoiceHeader
44 UBYTE vh_OneShotHiSamples[4];
45 UBYTE vh_RepeatHiSamples[4];
46 UBYTE vh_SamplesPerHiCycle[4];
47 UBYTE vh_SamplesPerSec[2];
48 UBYTE vh_Octaves;
49 UBYTE vh_Compression;
50 UBYTE vh_Volume[4];
53 /**************************************************************************************************/
55 static LONG propchunks[] =
57 ID_8SVX, ID_VHDR
60 /**************************************************************************************************/
61 /**************************************************************************************************/
63 BOOL Read8SVX(Class *cl, Object *o)
66 struct FileVoiceHeader *file_vhd;
67 struct VoiceHeader *vhd;
68 struct IFFHandle *handle;
69 struct StoredProperty *vhdr_prop;
70 struct ContextNode *cn;
71 UBYTE *sample;
72 ULONG samplesize;
73 IPTR sourcetype;
74 LONG error;
77 D(bug("8svx.datatype/Read8SVX()\n"));
79 if (GetDTAttrs(o, DTA_SourceType , (IPTR)&sourcetype ,
80 DTA_Handle , (IPTR)&handle ,
81 SDTA_VoiceHeader , (IPTR)&vhd ,
82 TAG_DONE ) != 3)
84 SetIoErr(ERROR_OBJECT_NOT_FOUND);
85 return FALSE;
88 if ((sourcetype != DTST_FILE) && (sourcetype != DTST_CLIPBOARD))
90 SetIoErr(ERROR_OBJECT_NOT_FOUND);
91 return FALSE;
94 if (!handle || !vhd)
96 SetIoErr(ERROR_OBJECT_NOT_FOUND);
97 return FALSE;
100 if (PropChunks(handle, propchunks, 3) != 0)
102 SetIoErr(ERROR_NO_FREE_STORE);
103 D(bug("8svx.datatype error propchunks\n"));
104 return FALSE;
107 if (StopChunk(handle, ID_8SVX, ID_BODY) != 0)
109 SetIoErr(ERROR_NO_FREE_STORE);
110 D(bug("8svx.datatype error stopchunks\n"));
111 return FALSE;
114 error = ParseIFF(handle, IFFPARSE_SCAN);
115 if (error)
117 SetIoErr(ERROR_OBJECT_WRONG_TYPE);
118 D(bug("8svx.datatype error parseiff\n"));
119 return FALSE;
122 vhdr_prop = FindProp(handle, ID_8SVX, ID_VHDR);
124 cn = CurrentChunk(handle);
125 if ((cn->cn_Type != ID_8SVX) ||
126 (cn->cn_ID != ID_BODY) ||
127 (vhdr_prop == NULL))
129 SetIoErr(ERROR_REQUIRED_ARG_MISSING);
130 D(bug("8svx.datatype error currentchunk\n"));
131 return FALSE;
134 file_vhd = (struct FileVoiceHeader *)vhdr_prop->sp_Data;
135 vhd->vh_OneShotHiSamples = file_vhd->vh_OneShotHiSamples[0] * 0x1000000 +
136 file_vhd->vh_OneShotHiSamples[1] * 0x10000 +
137 file_vhd->vh_OneShotHiSamples[2] * 0x100 +
138 file_vhd->vh_OneShotHiSamples[3];
139 vhd->vh_RepeatHiSamples = file_vhd->vh_RepeatHiSamples[0] * 0x1000000 +
140 file_vhd->vh_RepeatHiSamples[1] * 0x10000 +
141 file_vhd->vh_RepeatHiSamples[2] * 0x100 +
142 file_vhd->vh_RepeatHiSamples[3];
143 vhd->vh_SamplesPerHiCycle = file_vhd->vh_SamplesPerHiCycle[0] * 0x1000000 +
144 file_vhd->vh_SamplesPerHiCycle[1] * 0x10000 +
145 file_vhd->vh_SamplesPerHiCycle[2] * 0x100 +
146 file_vhd->vh_SamplesPerHiCycle[3];
147 vhd->vh_SamplesPerSec = file_vhd->vh_SamplesPerSec[0] * 0x100 +
148 file_vhd->vh_SamplesPerSec[1];
149 vhd->vh_Octaves = file_vhd->vh_Octaves;
150 vhd->vh_Compression = file_vhd->vh_Compression;
151 vhd->vh_Volume = file_vhd->vh_Volume[0] * 0x1000000 +
152 file_vhd->vh_Volume[1] * 0x10000 +
153 file_vhd->vh_Volume[2] * 0x100 +
154 file_vhd->vh_Volume[3];
156 D(bug("8svx.datatype: OneShotHiSamples : %d\n"
157 " RepeatHiSampoles : %d\n"
158 " SamplesPerHiCycle: %d\n"
159 " SamplesPerSec : %d\n"
160 " Octaves : %d\n"
161 " Compression : %d\n"
162 " Volume : %d\n",
163 vhd->vh_OneShotHiSamples,
164 vhd->vh_RepeatHiSamples,
165 vhd->vh_SamplesPerHiCycle,
166 vhd->vh_SamplesPerSec,
167 vhd->vh_Octaves,
168 vhd->vh_Compression,
169 vhd->vh_Volume));
171 if (vhd->vh_Compression != 0)
173 SetIoErr(ERROR_NOT_IMPLEMENTED);
174 return FALSE;
177 D(bug("8svx.datatype: BODY chunk size %d\n", cn->cn_Size));
179 samplesize = vhd->vh_OneShotHiSamples + vhd->vh_RepeatHiSamples;
181 if (samplesize > cn->cn_Size)
183 SetIoErr(ERROR_BAD_NUMBER);
184 return FALSE;
187 sample = AllocVec(samplesize, MEMF_PUBLIC);
188 if (!sample)
190 SetIoErr(ERROR_NO_FREE_STORE);
191 return FALSE;
194 if (ReadChunkBytes(handle, sample, samplesize) != samplesize)
196 FreeVec(sample);
197 SetIoErr(ERROR_UNKNOWN);
198 return FALSE;
201 SetDTAttrs(o, NULL, NULL, DTA_ObjName, (IPTR)"Unknown",
202 SDTA_Sample, (IPTR)sample,
203 SDTA_SampleLength, samplesize,
204 SDTA_Period, 709379 * 5 / vhd->vh_SamplesPerSec,
205 SDTA_Volume, 64,
206 SDTA_Cycles, 1,
207 TAG_DONE);
209 return TRUE;
212 /**************************************************************************************************/
214 IPTR EIGHTSVX__OM_NEW(Class *cl, Object *o, struct opSet *msg)
216 IPTR retval;
218 retval = DoSuperMethodA(cl, o, (Msg)msg);
219 if (retval)
221 if (!Read8SVX(cl, (Object *)retval))
223 CoerceMethod(cl, (Object *)retval, OM_DISPOSE);
224 retval = 0;
228 return retval;
231 /**************************************************************************************************/