ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getid3_voc Class Reference

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g // More...

+ Inheritance diagram for getid3_voc:
+ Collaboration diagram for getid3_voc:

Public Member Functions

 getid3_voc (&$fd, &$ThisFileInfo)
 
 VOCcompressionTypeLookup ($index)
 
 VOCwFormatLookup ($index)
 
 VOCwFormatActualBitsPerSampleLookup ($index)
 
 Analyze ()
 
 VOCcompressionTypeLookup ($index)
 
 VOCwFormatLookup ($index)
 
 VOCwFormatActualBitsPerSampleLookup ($index)
 
- Public Member Functions inherited from getid3_handler
 __construct (getID3 $getid3, $call_module=null)
 
 Analyze ()
 
 AnalyzeString ($string)
 
 setStringMode ($string)
 
 saveAttachment ($name, $offset, $length, $image_mime=null)
 

Additional Inherited Members

- Protected Member Functions inherited from getid3_handler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
 notice ($text)
 
- Protected Attributes inherited from getid3_handler
 $getid3
 
 $data_string_flag = false
 
 $data_string = ''
 
 $data_string_position = 0
 
 $data_string_length = 0
 

Detailed Description

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //

Definition at line 17 of file module.audio.voc.php.

Member Function Documentation

◆ Analyze()

getid3_voc::Analyze ( )

Definition at line 21 of file module.audio.voc.php.

References $info, getid3_lib\CastAsInt(), getid3_handler\feof(), getid3_handler\fread(), getid3_handler\fseek(), getid3_handler\ftell(), getid3_lib\LittleEndian2Int(), getid3_lib\PrintHexBytes(), getid3_lib\safe_inc(), getid3_lib\trunc(), VOCcompressionTypeLookup(), VOCwFormatActualBitsPerSampleLookup(), and VOCwFormatLookup().

21  {
22  $info = &$this->getid3->info;
23 
24  $OriginalAVdataOffset = $info['avdataoffset'];
25  $this->fseek($info['avdataoffset']);
26  $VOCheader = $this->fread(26);
27 
28  $magic = 'Creative Voice File';
29  if (substr($VOCheader, 0, 19) != $magic) {
30  $info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($VOCheader, 0, 19)).'"';
31  return false;
32  }
33 
34  // shortcuts
35  $thisfile_audio = &$info['audio'];
36  $info['voc'] = array();
37  $thisfile_voc = &$info['voc'];
38 
39  $info['fileformat'] = 'voc';
40  $thisfile_audio['dataformat'] = 'voc';
41  $thisfile_audio['bitrate_mode'] = 'cbr';
42  $thisfile_audio['lossless'] = true;
43  $thisfile_audio['channels'] = 1; // might be overriden below
44  $thisfile_audio['bits_per_sample'] = 8; // might be overriden below
45 
46  // byte # Description
47  // ------ ------------------------------------------
48  // 00-12 'Creative Voice File'
49  // 13 1A (eof to abort printing of file)
50  // 14-15 Offset of first datablock in .voc file (std 1A 00 in Intel Notation)
51  // 16-17 Version number (minor,major) (VOC-HDR puts 0A 01)
52  // 18-19 2's Comp of Ver. # + 1234h (VOC-HDR puts 29 11)
53 
54  $thisfile_voc['header']['datablock_offset'] = getid3_lib::LittleEndian2Int(substr($VOCheader, 20, 2));
55  $thisfile_voc['header']['minor_version'] = getid3_lib::LittleEndian2Int(substr($VOCheader, 22, 1));
56  $thisfile_voc['header']['major_version'] = getid3_lib::LittleEndian2Int(substr($VOCheader, 23, 1));
57 
58  do {
59 
60  $BlockOffset = $this->ftell();
61  $BlockData = $this->fread(4);
62  $BlockType = ord($BlockData{0});
63  $BlockSize = getid3_lib::LittleEndian2Int(substr($BlockData, 1, 3));
64  $ThisBlock = array();
65 
66  getid3_lib::safe_inc($thisfile_voc['blocktypes'][$BlockType], 1);
67  switch ($BlockType) {
68  case 0: // Terminator
69  // do nothing, we'll break out of the loop down below
70  break;
71 
72  case 1: // Sound data
73  $BlockData .= $this->fread(2);
74  if ($info['avdataoffset'] <= $OriginalAVdataOffset) {
75  $info['avdataoffset'] = $this->ftell();
76  }
77  $this->fseek($BlockSize - 2, SEEK_CUR);
78 
79  $ThisBlock['sample_rate_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 1));
80  $ThisBlock['compression_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, 5, 1));
81 
82  $ThisBlock['compression_name'] = $this->VOCcompressionTypeLookup($ThisBlock['compression_type']);
83  if ($ThisBlock['compression_type'] <= 3) {
84  $thisfile_voc['compressed_bits_per_sample'] = getid3_lib::CastAsInt(str_replace('-bit', '', $ThisBlock['compression_name']));
85  }
86 
87  // Less accurate sample_rate calculation than the Extended block (#8) data (but better than nothing if Extended Block is not available)
88  if (empty($thisfile_audio['sample_rate'])) {
89  // SR byte = 256 - (1000000 / sample_rate)
90  $thisfile_audio['sample_rate'] = getid3_lib::trunc((1000000 / (256 - $ThisBlock['sample_rate_id'])) / $thisfile_audio['channels']);
91  }
92  break;
93 
94  case 2: // Sound continue
95  case 3: // Silence
96  case 4: // Marker
97  case 6: // Repeat
98  case 7: // End repeat
99  // nothing useful, just skip
100  $this->fseek($BlockSize, SEEK_CUR);
101  break;
102 
103  case 8: // Extended
104  $BlockData .= $this->fread(4);
105 
106  //00-01 Time Constant:
107  // Mono: 65536 - (256000000 / sample_rate)
108  // Stereo: 65536 - (256000000 / (sample_rate * 2))
109  $ThisBlock['time_constant'] = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 2));
110  $ThisBlock['pack_method'] = getid3_lib::LittleEndian2Int(substr($BlockData, 6, 1));
111  $ThisBlock['stereo'] = (bool) getid3_lib::LittleEndian2Int(substr($BlockData, 7, 1));
112 
113  $thisfile_audio['channels'] = ($ThisBlock['stereo'] ? 2 : 1);
114  $thisfile_audio['sample_rate'] = getid3_lib::trunc((256000000 / (65536 - $ThisBlock['time_constant'])) / $thisfile_audio['channels']);
115  break;
116 
117  case 9: // data block that supersedes blocks 1 and 8. Used for stereo, 16 bit
118  $BlockData .= $this->fread(12);
119  if ($info['avdataoffset'] <= $OriginalAVdataOffset) {
120  $info['avdataoffset'] = $this->ftell();
121  }
122  $this->fseek($BlockSize - 12, SEEK_CUR);
123 
124  $ThisBlock['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 4));
125  $ThisBlock['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($BlockData, 8, 1));
126  $ThisBlock['channels'] = getid3_lib::LittleEndian2Int(substr($BlockData, 9, 1));
127  $ThisBlock['wFormat'] = getid3_lib::LittleEndian2Int(substr($BlockData, 10, 2));
128 
129  $ThisBlock['compression_name'] = $this->VOCwFormatLookup($ThisBlock['wFormat']);
130  if ($this->VOCwFormatActualBitsPerSampleLookup($ThisBlock['wFormat'])) {
131  $thisfile_voc['compressed_bits_per_sample'] = $this->VOCwFormatActualBitsPerSampleLookup($ThisBlock['wFormat']);
132  }
133 
134  $thisfile_audio['sample_rate'] = $ThisBlock['sample_rate'];
135  $thisfile_audio['bits_per_sample'] = $ThisBlock['bits_per_sample'];
136  $thisfile_audio['channels'] = $ThisBlock['channels'];
137  break;
138 
139  default:
140  $info['warning'][] = 'Unhandled block type "'.$BlockType.'" at offset '.$BlockOffset;
141  $this->fseek($BlockSize, SEEK_CUR);
142  break;
143  }
144 
145  if (!empty($ThisBlock)) {
146  $ThisBlock['block_offset'] = $BlockOffset;
147  $ThisBlock['block_size'] = $BlockSize;
148  $ThisBlock['block_type_id'] = $BlockType;
149  $thisfile_voc['blocks'][] = $ThisBlock;
150  }
151 
152  } while (!feof($this->getid3->fp) && ($BlockType != 0));
153 
154  // Terminator block doesn't have size field, so seek back 3 spaces
155  $this->fseek(-3, SEEK_CUR);
156 
157  ksort($thisfile_voc['blocktypes']);
158 
159  if (!empty($thisfile_voc['compressed_bits_per_sample'])) {
160  $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / ($thisfile_voc['compressed_bits_per_sample'] * $thisfile_audio['channels'] * $thisfile_audio['sample_rate']);
161  $thisfile_audio['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
162  }
163 
164  return true;
165  }
static safe_inc(&$variable, $increment=1)
Definition: getid3.lib.php:56
LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:266
VOCcompressionTypeLookup($index)
$info
Definition: example_052.php:80
VOCwFormatActualBitsPerSampleLookup($index)
VOCwFormatLookup($index)
trunc($floatnumber)
Definition: getid3.lib.php:43
fread($bytes)
Definition: getid3.php:1685
CastAsInt($floatnum)
Definition: getid3.lib.php:60
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true)
Definition: getid3.lib.php:17
+ Here is the call graph for this function:

◆ getid3_voc()

getid3_voc::getid3_voc ( $fd,
$ThisFileInfo 
)

Definition at line 20 of file module.audio.voc.php.

References getid3_lib\CastAsInt(), getid3_handler\feof(), getid3_handler\fread(), getid3_handler\fseek(), getid3_handler\ftell(), getid3_lib\LittleEndian2Int(), getid3_lib\trunc(), VOCcompressionTypeLookup(), VOCwFormatActualBitsPerSampleLookup(), and VOCwFormatLookup().

20  {
21 
22  $OriginalAVdataOffset = $ThisFileInfo['avdataoffset'];
23  fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
24  $VOCheader = fread($fd, 26);
25 
26  if (substr($VOCheader, 0, 19) != 'Creative Voice File') {
27  $ThisFileInfo['error'][] = 'Expecting "Creative Voice File" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($VOCheader, 0, 19).'"';
28  return false;
29  }
30 
31  // shortcuts
32  $thisfile_audio = &$ThisFileInfo['audio'];
33  $ThisFileInfo['voc'] = array();
34  $thisfile_voc = &$ThisFileInfo['voc'];
35 
36  $ThisFileInfo['fileformat'] = 'voc';
37  $thisfile_audio['dataformat'] = 'voc';
38  $thisfile_audio['bitrate_mode'] = 'cbr';
39  $thisfile_audio['lossless'] = true;
40  $thisfile_audio['channels'] = 1; // might be overriden below
41  $thisfile_audio['bits_per_sample'] = 8; // might be overriden below
42 
43  // byte # Description
44  // ------ ------------------------------------------
45  // 00-12 'Creative Voice File'
46  // 13 1A (eof to abort printing of file)
47  // 14-15 Offset of first datablock in .voc file (std 1A 00 in Intel Notation)
48  // 16-17 Version number (minor,major) (VOC-HDR puts 0A 01)
49  // 18-19 2's Comp of Ver. # + 1234h (VOC-HDR puts 29 11)
50 
51  $thisfile_voc['header']['datablock_offset'] = getid3_lib::LittleEndian2Int(substr($VOCheader, 20, 2));
52  $thisfile_voc['header']['minor_version'] = getid3_lib::LittleEndian2Int(substr($VOCheader, 22, 1));
53  $thisfile_voc['header']['major_version'] = getid3_lib::LittleEndian2Int(substr($VOCheader, 23, 1));
54 
55  do {
56 
57  $BlockOffset = ftell($fd);
58  $BlockData = fread($fd, 4);
59  $BlockType = ord($BlockData{0});
60  $BlockSize = getid3_lib::LittleEndian2Int(substr($BlockData, 1, 3));
61  $ThisBlock = array();
62 
63  @$thisfile_voc['blocktypes'][$BlockType]++;
64  switch ($BlockType) {
65  case 0: // Terminator
66  // do nothing, we'll break out of the loop down below
67  break;
68 
69  case 1: // Sound data
70  $BlockData .= fread($fd, 2);
71  if ($ThisFileInfo['avdataoffset'] <= $OriginalAVdataOffset) {
72  $ThisFileInfo['avdataoffset'] = ftell($fd);
73  }
74  fseek($fd, $BlockSize - 2, SEEK_CUR);
75 
76  $ThisBlock['sample_rate_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 1));
77  $ThisBlock['compression_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, 5, 1));
78 
79  $ThisBlock['compression_name'] = $this->VOCcompressionTypeLookup($ThisBlock['compression_type']);
80  if ($ThisBlock['compression_type'] <= 3) {
81  $thisfile_voc['compressed_bits_per_sample'] = getid3_lib::CastAsInt(str_replace('-bit', '', $ThisBlock['compression_name']));
82  }
83 
84  // Less accurate sample_rate calculation than the Extended block (#8) data (but better than nothing if Extended Block is not available)
85  if (empty($thisfile_audio['sample_rate'])) {
86  // SR byte = 256 - (1000000 / sample_rate)
87  $thisfile_audio['sample_rate'] = getid3_lib::trunc((1000000 / (256 - $ThisBlock['sample_rate_id'])) / $thisfile_audio['channels']);
88  }
89  break;
90 
91  case 2: // Sound continue
92  case 3: // Silence
93  case 4: // Marker
94  case 6: // Repeat
95  case 7: // End repeat
96  // nothing useful, just skip
97  fseek($fd, $BlockSize, SEEK_CUR);
98  break;
99 
100  case 8: // Extended
101  $BlockData .= fread($fd, 4);
102 
103  //00-01 Time Constant:
104  // Mono: 65536 - (256000000 / sample_rate)
105  // Stereo: 65536 - (256000000 / (sample_rate * 2))
106  $ThisBlock['time_constant'] = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 2));
107  $ThisBlock['pack_method'] = getid3_lib::LittleEndian2Int(substr($BlockData, 6, 1));
108  $ThisBlock['stereo'] = (bool) getid3_lib::LittleEndian2Int(substr($BlockData, 7, 1));
109 
110  $thisfile_audio['channels'] = ($ThisBlock['stereo'] ? 2 : 1);
111  $thisfile_audio['sample_rate'] = getid3_lib::trunc((256000000 / (65536 - $ThisBlock['time_constant'])) / $thisfile_audio['channels']);
112  break;
113 
114  case 9: // data block that supersedes blocks 1 and 8. Used for stereo, 16 bit
115  $BlockData .= fread($fd, 12);
116  if ($ThisFileInfo['avdataoffset'] <= $OriginalAVdataOffset) {
117  $ThisFileInfo['avdataoffset'] = ftell($fd);
118  }
119  fseek($fd, $BlockSize - 12, SEEK_CUR);
120 
121  $ThisBlock['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 4));
122  $ThisBlock['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($BlockData, 8, 1));
123  $ThisBlock['channels'] = getid3_lib::LittleEndian2Int(substr($BlockData, 9, 1));
124  $ThisBlock['wFormat'] = getid3_lib::LittleEndian2Int(substr($BlockData, 10, 2));
125 
126  $ThisBlock['compression_name'] = $this->VOCwFormatLookup($ThisBlock['wFormat']);
127  if ($this->VOCwFormatActualBitsPerSampleLookup($ThisBlock['wFormat'])) {
128  $thisfile_voc['compressed_bits_per_sample'] = $this->VOCwFormatActualBitsPerSampleLookup($ThisBlock['wFormat']);
129  }
130 
131  $thisfile_audio['sample_rate'] = $ThisBlock['sample_rate'];
132  $thisfile_audio['bits_per_sample'] = $ThisBlock['bits_per_sample'];
133  $thisfile_audio['channels'] = $ThisBlock['channels'];
134  break;
135 
136  default:
137  $ThisFileInfo['warning'][] = 'Unhandled block type "'.$BlockType.'" at offset '.$BlockOffset;
138  fseek($fd, $BlockSize, SEEK_CUR);
139  break;
140  }
141 
142  if (!empty($ThisBlock)) {
143  $ThisBlock['block_offset'] = $BlockOffset;
144  $ThisBlock['block_size'] = $BlockSize;
145  $ThisBlock['block_type_id'] = $BlockType;
146  $thisfile_voc['blocks'][] = $ThisBlock;
147  }
148 
149  } while (!feof($fd) && ($BlockType != 0));
150 
151  // Terminator block doesn't have size field, so seek back 3 spaces
152  fseek($fd, -3, SEEK_CUR);
153 
154  ksort($thisfile_voc['blocktypes']);
155 
156  if (!empty($thisfile_voc['compressed_bits_per_sample'])) {
157  $ThisFileInfo['playtime_seconds'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / ($thisfile_voc['compressed_bits_per_sample'] * $thisfile_audio['channels'] * $thisfile_audio['sample_rate']);
158  $thisfile_audio['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds'];
159  }
160 
161  return true;
162  }
LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:266
VOCcompressionTypeLookup($index)
VOCwFormatActualBitsPerSampleLookup($index)
VOCwFormatLookup($index)
trunc($floatnumber)
Definition: getid3.lib.php:43
fread($bytes)
Definition: getid3.php:1685
CastAsInt($floatnum)
Definition: getid3.lib.php:60
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
+ Here is the call graph for this function:

◆ VOCcompressionTypeLookup() [1/2]

getid3_voc::VOCcompressionTypeLookup (   $index)

Definition at line 164 of file module.audio.voc.php.

Referenced by Analyze(), and getid3_voc().

164  {
165  static $VOCcompressionTypeLookup = array(
166  0 => '8-bit',
167  1 => '4-bit',
168  2 => '2.6-bit',
169  3 => '2-bit'
170  );
171  return (isset($VOCcompressionTypeLookup[$index]) ? $VOCcompressionTypeLookup[$index] : 'Multi DAC ('.($index - 3).') channels');
172  }
+ Here is the caller graph for this function:

◆ VOCcompressionTypeLookup() [2/2]

getid3_voc::VOCcompressionTypeLookup (   $index)

Definition at line 167 of file module.audio.voc.php.

167  {
168  static $VOCcompressionTypeLookup = array(
169  0 => '8-bit',
170  1 => '4-bit',
171  2 => '2.6-bit',
172  3 => '2-bit'
173  );
174  return (isset($VOCcompressionTypeLookup[$index]) ? $VOCcompressionTypeLookup[$index] : 'Multi DAC ('.($index - 3).') channels');
175  }

◆ VOCwFormatActualBitsPerSampleLookup() [1/2]

getid3_voc::VOCwFormatActualBitsPerSampleLookup (   $index)

Definition at line 188 of file module.audio.voc.php.

Referenced by Analyze(), and getid3_voc().

188  {
189  static $VOCwFormatLookup = array(
190  0x0000 => 8,
191  0x0001 => 4,
192  0x0002 => 3,
193  0x0003 => 2,
194  0x0004 => 16,
195  0x0006 => 8,
196  0x0007 => 8,
197  0x2000 => 4
198  );
199  return (isset($VOCwFormatLookup[$index]) ? $VOCwFormatLookup[$index] : false);
200  }
+ Here is the caller graph for this function:

◆ VOCwFormatActualBitsPerSampleLookup() [2/2]

getid3_voc::VOCwFormatActualBitsPerSampleLookup (   $index)

Definition at line 191 of file module.audio.voc.php.

191  {
192  static $VOCwFormatLookup = array(
193  0x0000 => 8,
194  0x0001 => 4,
195  0x0002 => 3,
196  0x0003 => 2,
197  0x0004 => 16,
198  0x0006 => 8,
199  0x0007 => 8,
200  0x2000 => 4
201  );
202  return (isset($VOCwFormatLookup[$index]) ? $VOCwFormatLookup[$index] : false);
203  }

◆ VOCwFormatLookup() [1/2]

getid3_voc::VOCwFormatLookup (   $index)

Definition at line 174 of file module.audio.voc.php.

Referenced by Analyze(), and getid3_voc().

174  {
175  static $VOCwFormatLookup = array(
176  0x0000 => '8-bit unsigned PCM',
177  0x0001 => 'Creative 8-bit to 4-bit ADPCM',
178  0x0002 => 'Creative 8-bit to 3-bit ADPCM',
179  0x0003 => 'Creative 8-bit to 2-bit ADPCM',
180  0x0004 => '16-bit signed PCM',
181  0x0006 => 'CCITT a-Law',
182  0x0007 => 'CCITT u-Law',
183  0x2000 => 'Creative 16-bit to 4-bit ADPCM'
184  );
185  return (isset($VOCwFormatLookup[$index]) ? $VOCwFormatLookup[$index] : false);
186  }
+ Here is the caller graph for this function:

◆ VOCwFormatLookup() [2/2]

getid3_voc::VOCwFormatLookup (   $index)

Definition at line 177 of file module.audio.voc.php.

177  {
178  static $VOCwFormatLookup = array(
179  0x0000 => '8-bit unsigned PCM',
180  0x0001 => 'Creative 8-bit to 4-bit ADPCM',
181  0x0002 => 'Creative 8-bit to 3-bit ADPCM',
182  0x0003 => 'Creative 8-bit to 2-bit ADPCM',
183  0x0004 => '16-bit signed PCM',
184  0x0006 => 'CCITT a-Law',
185  0x0007 => 'CCITT u-Law',
186  0x2000 => 'Creative 16-bit to 4-bit ADPCM'
187  );
188  return (isset($VOCwFormatLookup[$index]) ? $VOCwFormatLookup[$index] : false);
189  }

The documentation for this class was generated from the following file: