f583d0823bfd06420dfc5d944dc134f13d4d62c4
[platform/upstream/gst-plugins-good.git] / ext / mikmod / mikmod_types.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <gst/gst.h>
25 #include "mikmod_types.h"
26 #include <string.h>             /* memcmp */
27 #include <ctype.h>              /* isdigit */
28
29 #define MODULEHEADERSIZE 0x438
30
31  
32 gboolean MOD_CheckType( GstBuffer *buf )
33 {
34 gchar *data;
35                 
36         data = GST_BUFFER_DATA( buf ) + MODULEHEADERSIZE;       
37         
38         /* Protracker and variants */
39         if (( ! memcmp( data, "M.K.", 4 )) || ( ! memcmp( data, "M!K!", 4 )))
40                 return TRUE;
41         
42         /* Star Tracker */
43         if ((( ! memcmp( data, "FLT", 3 )) || ( ! memcmp( data, "EXO", 3 ))) && ( isdigit( data[3] )))
44                 return TRUE;
45         
46         /* Oktalyzer (Amiga) */
47         if (! memcmp( data, "OKTA", 4 )) 
48                 return TRUE;
49         
50         /* Oktalyser (Atari) */
51         if ( ! memcmp( data, "CD81", 4 ))
52                 return TRUE;
53         
54         /* Fasttracker */
55         if (( ! memcmp( data + 1, "CHN", 3 )) && ( isdigit( data[0] ))) 
56                 return TRUE;
57                 
58         /* Fasttracker or Taketracker */
59         if ((( ! memcmp( data + 2, "CH", 2 )) || ( ! memcmp( data + 2, "CN", 2 ))) && ( isdigit( data[0] )) && ( isdigit( data[1] ))) 
60                 return TRUE;
61         
62         return FALSE;
63 }
64
65 gboolean Mod_669_CheckType( GstBuffer *buf )
66 {
67 gchar *data;
68         
69         data = GST_BUFFER_DATA( buf );
70         
71         if( ! memcmp( data, "if", 2 ) || ! memcmp( data, "JN", 2 )) 
72                 return TRUE;
73         
74         return FALSE;
75 }
76
77 gboolean Amf_CheckType( GstBuffer *buf )
78 {
79 gchar *data;
80         
81     data = GST_BUFFER_DATA( buf );
82         
83     if( memcmp( data, "AMF", 3) ) 
84       return FALSE;   
85         
86     data = GST_BUFFER_DATA( buf ) + 3;
87                 
88         if (( (gint)*data >= 10 ) && ( (gint)*data <= 14 )) 
89           return TRUE;
90         
91         return FALSE;
92 }
93
94 gboolean Dsm_CheckType( GstBuffer *buf )
95 {
96 gchar *data;
97         
98     data = GST_BUFFER_DATA( buf );
99         
100         if( ! memcmp( data, "RIFF", 4 ) && ! memcmp( data + 8, "DSMF", 4 )) 
101           return TRUE;
102         
103         return FALSE;
104 }
105
106 gboolean Fam_CheckType( GstBuffer *buf )
107 {
108 gchar *data;    
109 static  unsigned char FARSIG[4+3]={'F','A','R',0xfe,13,10,26};
110
111         data = GST_BUFFER_DATA( buf );
112         
113         if(( memcmp( data, FARSIG, 4 )) || ( memcmp( data + 44, FARSIG + 4, 3 )))
114           return FALSE;
115         
116         return 1;
117 }
118
119 gboolean Gdm_CheckType( GstBuffer *buf )
120 {
121 gchar *data;
122         
123         data = GST_BUFFER_DATA( buf );
124         
125         if ( ! memcmp( data, "GDM\xfe", 4 ) &&  ! memcmp( data + 71, "GMFS", 4 ))
126                 return TRUE;
127         
128         return FALSE;
129 }
130
131 gboolean Imf_CheckType( GstBuffer *buf )
132 {
133 gchar *data;
134         
135         data = GST_BUFFER_DATA( buf ) + 0x3c;
136                 
137         if( ! memcmp( data, "IM10", 4))
138                 return TRUE;
139                 
140         return FALSE;
141 }
142
143 gboolean It_CheckType( GstBuffer *buf )
144 {
145 gchar *data;
146         
147         data = GST_BUFFER_DATA( buf );
148                 
149         if( ! memcmp( data, "IMPM", 4 )) 
150                 return TRUE;
151                 
152         return FALSE;
153 }
154
155 gboolean M15_CheckType( GstBuffer *buf )
156 {
157         /* FIXME: M15 CheckType to do */
158         return FALSE;
159 }
160
161 gboolean Med_CheckType( GstBuffer *buf )
162 {
163 gchar *data;
164         
165         data = GST_BUFFER_DATA( buf );
166                 
167         if(( ! memcmp(data, "MMD0", 4 )) || ( memcmp( data, "MMD1", 4 )))
168                 return TRUE;
169         
170         return FALSE;
171 }
172
173 gboolean Mtm_CheckType( GstBuffer *buf )
174 {
175 gchar *data;
176         
177         data = GST_BUFFER_DATA( buf );
178
179         if( ! memcmp( data, "MTM", 3 ))
180                 return TRUE;
181         
182         return FALSE;
183 }
184
185 gboolean Okt_CheckType( GstBuffer *buf )
186 {
187 gchar *data;
188         
189         data = GST_BUFFER_DATA( buf );
190
191         if( ! memcmp( data, "OKTSONG", 8 ))
192                 return TRUE;
193         
194         return FALSE;
195 }
196
197 gboolean S3m_CheckType( GstBuffer *buf )
198 {
199 gchar *data;
200         
201         data = GST_BUFFER_DATA( buf ) + 0x2c;
202
203         if( ! memcmp( data, "SCRM", 4 ))
204                 return TRUE;
205         
206         return FALSE;
207 }
208
209 gboolean Xm_CheckType( GstBuffer *buf )
210 {
211 gchar *data;
212         
213         data = GST_BUFFER_DATA( buf );
214
215         if( memcmp( data, "Extended Module: ", 17 ))
216                 return FALSE;
217         
218         if( data[ 37 ] == 0x1a )
219                 return TRUE;
220         
221         return FALSE;
222 }
223
224