~ubuntu-branches/debian/sid/kodi/sid

« back to all changes in this revision

Viewing changes to lib/vgmstream/src/meta/ps2_mib.c

  • Committer: Package Import Robot
  • Author(s): Balint Reczey
  • Date: 2015-08-18 14:16:59 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20150818141659-4lgq2pksj7918osz
Tags: 15.1+dfsg1-1
* New upstream release 15.0
  See http://www.kodi.tv/kodi-15-0-isengard-one-release-to-rule-them-all/
* Depend on libav.*-dev provided by src:ffmpeg
* Recommend udisks2 instead of udisks.
  Udisks has been removed from unstable but support for udisks2 is not
  implemented yet.
* Ship patch helping Jessie backports
* Refresh patches
* Eliminate __DATE__ macros from source to make build more reproducible
* Build-depend on libsdl2.*-dev instead of libsdl.*-dev
* Build-depend on libgif-dev
* Drop obsoleted fix of installed header's include paths
* Refresh include file list included by kodi-addons-dev
* Build depend on libcec (>= 3)
* Build-depend on groovy2 instead of groovy
* Sort build dependencies
* Fix packaging repository URL
* Remove removed files from debian/copyright
* Fix filenames with spaces in debian/copyright
* Ship TexturePacker in kodi-addons-dev in /usr/lib/kodi
* Build depend on libcec-platform-dev
* Stop using embedded gnulib modules in rsxs screensaver (Closes: #795813)
* Add missing copyright paragraphs to d/copyright
* Stop marking files as excluded which are removed from upstream tarball
  already
* Bump standards version to 3.9.6
* New upstream release 15.1
  See http://kodi.tv/kodi-15-1-isengard-maintenance-release/
* Move TexturePacker to kodi-bin
* Stop building TexturePacker statically

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "meta.h"
2
 
#include "../util.h"
3
 
 
4
 
/* MIB
5
 
 
6
 
   PS2 MIB format is a headerless format.
7
 
   The interleave value can be found by checking the body of the data.
8
 
   
9
 
   The interleave start allways at offset 0 with a int value (which can have
10
 
   many values : 0x0000, 0x0002, 0x0006 etc...) follow by 12 empty (zero) values.
11
 
 
12
 
   The interleave value is the offset where you found the same 16 bytes.
13
 
 
14
 
   The n� of channels can be found by checking each time you found this 16 bytes.
15
 
 
16
 
   The interleave value can be very "large" (up to 0x20000 found so far) and is allways
17
 
   a 0x10 multiply value.
18
 
   
19
 
   The loop values can be found by checking the 'tags' offset (found @ 0x02 each 0x10 bytes).
20
 
   06 = start of the loop point (can be found for each channel)
21
 
   03 - end of the loop point (can be found for each channel)
22
 
 
23
 
   The .MIH header contains all informations about frequency, numbers of channels, interleave
24
 
   but has, afaik, no loop values.
25
 
 
26
 
   known extensions : MIB (MIH for the header) MIC (concatenation of MIB+MIH)
27
 
                                          Nota : the MIC stuff is not supported here as there is
28
 
                                                         another MIC format which can be found in Koei Games.
29
 
 
30
 
   2008-05-14 - Fastelbja : First version ...
31
 
   2008-05-20 - Fastelbja : Fix loop value when loopEnd==0
32
 
*/
33
 
 
34
 
VGMSTREAM * init_vgmstream_ps2_mib(STREAMFILE *streamFile) {
35
 
    
36
 
        VGMSTREAM * vgmstream = NULL;
37
 
    STREAMFILE * streamFileMIH = NULL;
38
 
    char filename[260];
39
 
    
40
 
        uint8_t mibBuffer[0x10];
41
 
        uint8_t testBuffer[0x10];
42
 
 
43
 
        size_t  fileLength;
44
 
        
45
 
        off_t   loopStart = 0;
46
 
        off_t   loopEnd = 0;
47
 
        off_t   interleave = 0;
48
 
        off_t   readOffset = 0;
49
 
 
50
 
        char   filenameMIH[260];
51
 
 
52
 
        uint8_t gotMIH=0;
53
 
 
54
 
        int i, channel_count=1;
55
 
 
56
 
    /* check extension, case insensitive */
57
 
    streamFile->get_name(streamFile,filename,sizeof(filename));
58
 
    if (strcasecmp("mib",filename_extension(filename)) && 
59
 
                strcasecmp("mi4",filename_extension(filename))) goto fail;
60
 
 
61
 
        /* check for .MIH file */
62
 
        strcpy(filenameMIH,filename);
63
 
        strcpy(filenameMIH+strlen(filenameMIH)-3,"MIH");
64
 
 
65
 
        streamFileMIH = streamFile->open(streamFile,filenameMIH,STREAMFILE_DEFAULT_BUFFER_SIZE);
66
 
        if (streamFileMIH) gotMIH = 1;
67
 
 
68
 
    /* Search for interleave value & loop points */
69
 
        /* Get the first 16 values */
70
 
        fileLength = get_streamfile_size(streamFile);
71
 
        
72
 
        readOffset+=(off_t)read_streamfile(mibBuffer,0,0x10,streamFile); 
73
 
 
74
 
        do {
75
 
                readOffset+=(off_t)read_streamfile(testBuffer,readOffset,0x10,streamFile); 
76
 
                
77
 
                if(!memcmp(testBuffer,mibBuffer,0x10)) {
78
 
                        if(interleave==0) interleave=readOffset-0x10;
79
 
 
80
 
                        // be sure to point to an interleave value
81
 
                        if(((readOffset-0x10)==channel_count*interleave)) {
82
 
                                channel_count++;
83
 
                        }
84
 
                }
85
 
 
86
 
                // Loop Start ...
87
 
                if(testBuffer[0x01]==0x06) {
88
 
                        if(loopStart==0) loopStart = readOffset-0x10;
89
 
                }
90
 
 
91
 
                // Loop End ...
92
 
                if(testBuffer[0x01]==0x03) {
93
 
                        if(loopEnd==0) loopEnd = readOffset-0x10;
94
 
                }
95
 
 
96
 
        } while (streamFile->get_offset(streamFile)<(int32_t)fileLength);
97
 
 
98
 
        if(gotMIH) 
99
 
                channel_count=read_32bitLE(0x08,streamFileMIH);
100
 
 
101
 
    /* build the VGMSTREAM */
102
 
    vgmstream = allocate_vgmstream(channel_count,((loopStart!=0) && (loopEnd!=0)));
103
 
    if (!vgmstream) goto fail;
104
 
 
105
 
        if(interleave==0) interleave=0x10;
106
 
 
107
 
    /* fill in the vital statistics */
108
 
        if(gotMIH) {
109
 
                // Read stuff from the MIH file 
110
 
                vgmstream->channels = read_32bitLE(0x08,streamFileMIH);
111
 
                vgmstream->sample_rate = read_32bitLE(0x0C,streamFileMIH);
112
 
                vgmstream->interleave_block_size = read_32bitLE(0x10,streamFileMIH);
113
 
                vgmstream->num_samples=((read_32bitLE(0x10,streamFileMIH)*
114
 
                                                                (read_32bitLE(0x14,streamFileMIH)-1)*2)+
115
 
                                                                ((read_32bitLE(0x04,streamFileMIH)>>8)*2))/16*28/2;
116
 
        } else {
117
 
                vgmstream->channels = channel_count;
118
 
                vgmstream->interleave_block_size = interleave;
119
 
 
120
 
                if(!strcasecmp("mib",filename_extension(filename)))
121
 
                        vgmstream->sample_rate = 44100;
122
 
 
123
 
                if(!strcasecmp("mi4",filename_extension(filename)))
124
 
                        vgmstream->sample_rate = 48000;
125
 
 
126
 
                vgmstream->num_samples = (int32_t)(fileLength/16/channel_count*28);
127
 
        }
128
 
 
129
 
        if(loopStart!=0) {
130
 
                if(vgmstream->channels==1) {
131
 
                        vgmstream->loop_start_sample = loopStart/16*18;
132
 
                        vgmstream->loop_end_sample = loopEnd/16*28;
133
 
                } else {
134
 
                        vgmstream->loop_start_sample = ((loopStart/(interleave*channel_count))*interleave)/16*14*(2/channel_count);
135
 
                        vgmstream->loop_start_sample += (loopStart%(interleave*channel_count))/16*14*(2/channel_count);
136
 
                        vgmstream->loop_end_sample = ((loopEnd/(interleave*channel_count))*interleave)/16*28*(2/channel_count);
137
 
                        vgmstream->loop_end_sample += (loopEnd%(interleave*channel_count))/16*14*(2/channel_count);
138
 
                }
139
 
        }
140
 
 
141
 
        vgmstream->coding_type = coding_PSX;
142
 
    vgmstream->layout_type = layout_interleave;
143
 
    
144
 
        vgmstream->meta_type = meta_PS2_MIB;
145
 
    
146
 
        if (gotMIH) {
147
 
                vgmstream->meta_type = meta_PS2_MIB_MIH;
148
 
                close_streamfile(streamFileMIH); streamFileMIH=NULL;
149
 
        }
150
 
 
151
 
    /* open the file for reading by each channel */
152
 
    {
153
 
        for (i=0;i<channel_count;i++) {
154
 
            vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,0x8000);
155
 
 
156
 
            if (!vgmstream->ch[i].streamfile) goto fail;
157
 
 
158
 
            vgmstream->ch[i].channel_start_offset=
159
 
                vgmstream->ch[i].offset=i*vgmstream->interleave_block_size;
160
 
        }
161
 
    }
162
 
 
163
 
    return vgmstream;
164
 
 
165
 
    /* clean up anything we may have opened */
166
 
fail:
167
 
    if (streamFileMIH) close_streamfile(streamFileMIH);
168
 
    if (vgmstream) close_vgmstream(vgmstream);
169
 
    return NULL;
170
 
}