summaryrefslogtreecommitdiff
path: root/songdbj/de/jarnbjo/vorbis/Mapping0.java
blob: e8fde4686ff0fe8363b556a31dc38901b222fee3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * $ProjectName$
 * $ProjectRevision$
 * -----------------------------------------------------------
 * $Id$
 * -----------------------------------------------------------
 *
 * $Author$
 *
 * Description:
 *
 * Copyright 2002-2003 Tor-Einar Jarnbjo
 * -----------------------------------------------------------
 *
 * Change History
 * -----------------------------------------------------------
 * $Log$
 * Revision 1.1  2005/07/11 15:42:36  hcl
 * Songdb java version, source. only 1.5 compatible
 *
 * Revision 1.1.1.1  2004/04/04 22:09:12  shred
 * First Import
 *
 * Revision 1.2  2003/03/16 01:11:12  jarnbjo
 * no message
 *
 *
 */
 
package de.jarnbjo.vorbis;

import java.io.IOException;

import de.jarnbjo.util.io.BitInputStream;

class Mapping0 extends Mapping {

   private int[] magnitudes, angles, mux, submapFloors, submapResidues;

   protected Mapping0(VorbisStream vorbis, BitInputStream source, SetupHeader header) throws VorbisFormatException, IOException {

      int submaps=1;

      if(source.getBit()) {
         submaps=source.getInt(4)+1;
      }

      //System.out.println("submaps: "+submaps);

      int channels=vorbis.getIdentificationHeader().getChannels();
      int ilogChannels=Util.ilog(channels-1);

      //System.out.println("ilogChannels: "+ilogChannels);

      if(source.getBit()) {
         int couplingSteps=source.getInt(8)+1;
         magnitudes=new int[couplingSteps];
         angles=new int[couplingSteps];

         for(int i=0; i<couplingSteps; i++) {
            magnitudes[i]=source.getInt(ilogChannels);
            angles[i]=source.getInt(ilogChannels);
            if(magnitudes[i]==angles[i] || magnitudes[i]>=channels || angles[i]>=channels) {
               System.err.println(magnitudes[i]);
               System.err.println(angles[i]);
               throw new VorbisFormatException("The channel magnitude and/or angle mismatch.");
            }
         }
      }
      else {
         magnitudes=new int[0];
         angles=new int[0];
      }

      if(source.getInt(2)!=0) {
         throw new VorbisFormatException("A reserved mapping field has an invalid value.");
      }

      mux=new int[channels];
      if(submaps>1) {
         for(int i=0; i<channels; i++) {
            mux[i]=source.getInt(4);
            if(mux[i]>submaps) {
               throw new VorbisFormatException("A mapping mux value is higher than the number of submaps");
            }
         }
      }
      else {
         for(int i=0; i<channels; i++) {
            mux[i]=0;
         }
      }

      submapFloors=new int[submaps];
      submapResidues=new int[submaps];

      int floorCount=header.getFloors().length;
      int residueCount=header.getResidues().length;

      for(int i=0; i<submaps; i++) {
         source.getInt(8); // discard time placeholder
         submapFloors[i]=source.getInt(8);
         submapResidues[i]=source.getInt(8);

         if(submapFloors[i]>floorCount) {
            throw new VorbisFormatException("A mapping floor value is higher than the number of floors.");
         }

         if(submapResidues[i]>residueCount) {
            throw new VorbisFormatException("A mapping residue value is higher than the number of residues.");
         }
      }
   }

   protected int getType() {
      return 0;
   }

   protected int[] getAngles() {
      return angles;
   }

   protected int[] getMagnitudes() {
      return magnitudes;
   }

   protected int[] getMux() {
      return mux;
   }

   protected int[] getSubmapFloors() {
      return submapFloors;
   }

   protected int[] getSubmapResidues() {
      return submapResidues;
   }

   protected int getCouplingSteps() {
      return angles.length;
   }

   protected int getSubmaps() {
      return submapFloors.length;
   }
}