1 /* OpenCP Module Player
2 * copyright (c) '94-'10 Niklas Beisert <nbeisert@physik.tu-muenchen.de>
3 * copyright (c) '05-'21 Stian Skjelstad <stian.skjelstad@gmail.com>
4 *
5 * WAVPlay file type detection routines for the fileselector
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 * revision history: (please note changes here)
22 * -nb980510 Niklas Beisert <nbeisert@physik.tu-muenchen.de>
23 * -first release
24 */
25
26 #include "config.h"
27 #include <string.h>
28 #include <stdlib.h>
29 #include "types.h"
30 #include "filesel/filesystem.h"
31 #include "filesel/mdb.h"
32
wavGetModuleType(const char * buf)33 static unsigned char wavGetModuleType(const char *buf)
34 {
35 if ((*(uint32_t *)buf==uint32_little(0x46464952))&&(*(uint32_t *)(buf+8)==uint32_little(0x45564157))&&(*(uint32_t *)(buf+12)==uint32_little(0x20746D66))&&(*(uint16_t *)(buf+20)==uint16_little(1)))
36 return mtWAV;
37 return mtUnRead;
38 }
39
40
wavReadMemInfo(struct moduleinfostruct * m,const char * buf,size_t len)41 static int wavReadMemInfo(struct moduleinfostruct *m, const char *buf, size_t len)
42 {
43 int type=wavGetModuleType(buf);
44 int i,j;
45
46 if (type==mtUnRead)
47 return 0;
48
49 m->modtype=type;
50
51 switch (type)
52 {
53 case mtWAV:
54 {
55 char rate[10];
56 i=20;
57 m->modname[0]=0;
58 sprintf(rate, "%d", (int)int32_little((*(uint32_t *)(buf+i+4))));
59 for (j=strlen(rate); j<5; j++)
60 strcat(m->modname, " ");
61 strcat(m->modname, rate);
62 if (*(uint16_t *)(buf+i+14)==uint16_little(8))
63 strcat(m->modname, "Hz, 8 bit, ");
64 else
65 strcat(m->modname, "Hz, 16 bit, ");
66 if (*(uint16_t *)(buf+i+2)==uint16_little(1))
67 strcat(m->modname, "mono");
68 else
69 strcat(m->modname, "stereo");
70 m->channels=uint16_little(*(uint16_t *)(buf+i+2));
71 if (*(uint32_t *)(buf+i+16)==uint32_little(61746164))
72 m->playtime=uint32_little(*(uint32_t *)(buf+i+20))/ uint32_little(*(uint32_t *)(buf+i+8));
73 memset(&m->composer, 0, sizeof(m->composer));
74 return 1;
75 }
76 }
77 return 0;
78 }
79
wavReadInfo(struct moduleinfostruct * m,struct ocpfilehandle_t * fp,const char * mem,size_t len)80 static int wavReadInfo(struct moduleinfostruct *m, struct ocpfilehandle_t *fp, const char *mem, size_t len)
81 {
82 return wavReadMemInfo (m, mem, len);
83 }
84
85 struct mdbreadinforegstruct wavReadInfoReg = {wavReadMemInfo, wavReadInfo, 0 MDBREADINFOREGSTRUCT_TAIL};
86