ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
GetId3\Module\Audio\Voc Class Reference

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

+ Inheritance diagram for GetId3\Module\Audio\Voc:
+ Collaboration diagram for GetId3\Module\Audio\Voc:

Public Member Functions

 analyze ()
 
 VOCcompressionTypeLookup ($index)
 @staticvar array $VOCcompressionTypeLookup More...
 
 VOCwFormatLookup ($index)
 @staticvar array $VOCwFormatLookup More...
 
 VOCwFormatActualBitsPerSampleLookup ($index)
 @staticvar array $VOCwFormatLookup More...
 
- Public Member Functions inherited from GetId3\Handler\BaseHandler
 __construct (GetId3Core $getid3, $call_module=null)
 
 analyze ()
 Analyze from file pointer. More...
 
 AnalyzeString (&$string)
 Analyze from string instead. More...
 
 saveAttachment (&$ThisFileInfoIndex, $filename, $offset, $length)
 

Additional Inherited Members

- Protected Member Functions inherited from GetId3\Handler\BaseHandler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
- Protected Attributes inherited from GetId3\Handler\BaseHandler
 $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 //.

module for analyzing Creative VOC Audio files

Author
James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g http://www.getid3.org

Definition at line 29 of file Voc.php.

Member Function Documentation

◆ analyze()

GetId3\Module\Audio\Voc::analyze ( )
Returns
boolean

Reimplemented from GetId3\Handler\BaseHandler.

Definition at line 36 of file Voc.php.

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

References $info, GetId3\Lib\Helper\CastAsInt(), GetId3\Handler\BaseHandler\feof(), GetId3\Handler\BaseHandler\fread(), GetId3\Handler\BaseHandler\fseek(), GetId3\Handler\BaseHandler\ftell(), GetId3\Lib\Helper\LittleEndian2Int(), GetId3\Lib\Helper\PrintHexBytes(), GetId3\Lib\Helper\safe_inc(), GetId3\Lib\Helper\trunc(), GetId3\Module\Audio\Voc\VOCcompressionTypeLookup(), GetId3\Module\Audio\Voc\VOCwFormatActualBitsPerSampleLookup(), and GetId3\Module\Audio\Voc\VOCwFormatLookup().

+ Here is the call graph for this function:

◆ VOCcompressionTypeLookup()

GetId3\Module\Audio\Voc::VOCcompressionTypeLookup (   $index)

@staticvar array $VOCcompressionTypeLookup

Parameters
type$index
Returns
type

Definition at line 190 of file Voc.php.

191 {
192 static $VOCcompressionTypeLookup = array(
193 0 => '8-bit',
194 1 => '4-bit',
195 2 => '2.6-bit',
196 3 => '2-bit'
197 );
198
199 return (isset($VOCcompressionTypeLookup[$index]) ? $VOCcompressionTypeLookup[$index] : 'Multi DAC ('.($index - 3).') channels');
200 }

Referenced by GetId3\Module\Audio\Voc\analyze().

+ Here is the caller graph for this function:

◆ VOCwFormatActualBitsPerSampleLookup()

GetId3\Module\Audio\Voc::VOCwFormatActualBitsPerSampleLookup (   $index)

@staticvar array $VOCwFormatLookup

Parameters
type$index
Returns
type

Definition at line 230 of file Voc.php.

231 {
232 static $VOCwFormatLookup = array(
233 0x0000 => 8,
234 0x0001 => 4,
235 0x0002 => 3,
236 0x0003 => 2,
237 0x0004 => 16,
238 0x0006 => 8,
239 0x0007 => 8,
240 0x2000 => 4
241 );
242
243 return (isset($VOCwFormatLookup[$index]) ? $VOCwFormatLookup[$index] : false);
244 }

Referenced by GetId3\Module\Audio\Voc\analyze().

+ Here is the caller graph for this function:

◆ VOCwFormatLookup()

GetId3\Module\Audio\Voc::VOCwFormatLookup (   $index)

@staticvar array $VOCwFormatLookup

Parameters
type$index
Returns
type

Definition at line 208 of file Voc.php.

209 {
210 static $VOCwFormatLookup = array(
211 0x0000 => '8-bit unsigned PCM',
212 0x0001 => 'Creative 8-bit to 4-bit ADPCM',
213 0x0002 => 'Creative 8-bit to 3-bit ADPCM',
214 0x0003 => 'Creative 8-bit to 2-bit ADPCM',
215 0x0004 => '16-bit signed PCM',
216 0x0006 => 'CCITT a-Law',
217 0x0007 => 'CCITT u-Law',
218 0x2000 => 'Creative 16-bit to 4-bit ADPCM'
219 );
220
221 return (isset($VOCwFormatLookup[$index]) ? $VOCwFormatLookup[$index] : false);
222 }

Referenced by GetId3\Module\Audio\Voc\analyze().

+ Here is the caller graph for this function:

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