lame 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/.gitignore +20 -0
  2. data/.rspec +3 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +13 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +181 -0
  8. data/Rakefile +6 -0
  9. data/docs/id3v2.4.0-structure.txt +731 -0
  10. data/docs/lame-3.99.5.h +1323 -0
  11. data/lame.gemspec +28 -0
  12. data/lib/lame.rb +31 -0
  13. data/lib/lame/buffer.rb +21 -0
  14. data/lib/lame/configuration.rb +228 -0
  15. data/lib/lame/decoder.rb +38 -0
  16. data/lib/lame/decoding/decoded_frame.rb +25 -0
  17. data/lib/lame/decoding/id3_tag_parser.rb +53 -0
  18. data/lib/lame/decoding/mp3_data_header_parser.rb +64 -0
  19. data/lib/lame/decoding/mpeg_audio_frame_finder.rb +46 -0
  20. data/lib/lame/decoding/mpeg_audio_frame_matcher.rb +98 -0
  21. data/lib/lame/decoding/single_frame_decoder.rb +51 -0
  22. data/lib/lame/decoding/stream_decoder.rb +37 -0
  23. data/lib/lame/delegation.rb +68 -0
  24. data/lib/lame/encoder.rb +73 -0
  25. data/lib/lame/encoding/encode_short_buffer.rb +26 -0
  26. data/lib/lame/encoding/flusher.rb +22 -0
  27. data/lib/lame/encoding/id3.rb +46 -0
  28. data/lib/lame/encoding/vbr_info.rb +22 -0
  29. data/lib/lame/error.rb +13 -0
  30. data/lib/lame/ffi.rb +20 -0
  31. data/lib/lame/ffi/decode_flags.rb +19 -0
  32. data/lib/lame/ffi/enums.rb +75 -0
  33. data/lib/lame/ffi/functions.rb +272 -0
  34. data/lib/lame/ffi/global_flags.rb +20 -0
  35. data/lib/lame/ffi/mp3_data.rb +37 -0
  36. data/lib/lame/ffi/version.rb +17 -0
  37. data/lib/lame/version.rb +3 -0
  38. data/spec/buffer_spec.rb +26 -0
  39. data/spec/configuration_spec.rb +391 -0
  40. data/spec/decoder_spec.rb +120 -0
  41. data/spec/decoding/decoded_frame_spec.rb +44 -0
  42. data/spec/decoding/id3_tag_parser_spec.rb +54 -0
  43. data/spec/decoding/mp3_data_header_parser_spec.rb +95 -0
  44. data/spec/decoding/mpeg_audio_frame_finder_spec.rb +50 -0
  45. data/spec/decoding/mpeg_audio_frame_matcher_spec.rb +179 -0
  46. data/spec/decoding/single_frame_decoder_spec.rb +104 -0
  47. data/spec/decoding/stream_decoder_spec.rb +43 -0
  48. data/spec/delegation_spec.rb +146 -0
  49. data/spec/encoder_spec.rb +279 -0
  50. data/spec/encoding/encode_short_buffer_spec.rb +72 -0
  51. data/spec/encoding/flusher_spec.rb +47 -0
  52. data/spec/encoding/id3_spec.rb +106 -0
  53. data/spec/encoding/vbr_info_spec.rb +47 -0
  54. data/spec/ffi/decode_flags_spec.rb +16 -0
  55. data/spec/ffi/encoding_spec.rb +223 -0
  56. data/spec/ffi/global_flags_spec.rb +542 -0
  57. data/spec/ffi/id3tag_spec.rb +135 -0
  58. data/spec/ffi/mp3_data_spec.rb +26 -0
  59. data/spec/files/dies-irae.wav +0 -0
  60. data/spec/integration/decoding_spec.rb +179 -0
  61. data/spec/integration/encoding_spec.rb +126 -0
  62. data/spec/integration/id3_tags_spec.rb +96 -0
  63. data/spec/spec_helper.rb +175 -0
  64. metadata +254 -0
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ lame-3.99.5
20
+ spec/files/*.mp3
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format progress
3
+ --tag ~@slow
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@lame --create
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.8.7
6
+ - rbx-18mode
7
+ - rbx-19mode
8
+ - ruby-head
9
+ - jruby-19mode
10
+ - jruby-18mode
11
+ - jruby-head
12
+ before_install:
13
+ - sudo apt-get install -qq libmp3lame-dev
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lame.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Roel van Dijk
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,181 @@
1
+ # LAME
2
+
3
+ [![Build Status](https://travis-ci.org/rdvdijk/lame.png?branch=master)](https://travis-ci.org/rdvdijk/lame)
4
+ [![Code Climate](https://codeclimate.com/github/rdvdijk/lame.png)](https://codeclimate.com/github/rdvdijk/lame)
5
+ [![Coverage Status](https://coveralls.io/repos/rdvdijk/lame/badge.png?branch=master)](https://coveralls.io/r/rdvdijk/lame)
6
+
7
+ FFI powered library for the [LAME MP3 encoder](http://lame.sourceforge.net/).
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'lame'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install lame
22
+
23
+ ## Usage
24
+
25
+ Create a default `LAME::Encoder` with default settings:
26
+
27
+ ```ruby
28
+ encoder = LAME::Encoder.new
29
+ ```
30
+
31
+ Then configure some settings:
32
+
33
+ ```ruby
34
+ encoder.configure do |config|
35
+ config.quality = 4
36
+ config.bitrate = 192
37
+ end
38
+ ```
39
+
40
+ See all configuration options in the Configuration section below.
41
+
42
+ Then encode some audio data. Both `left` and `right` are arrays of `short`
43
+ values (ranging from −32,768 to +32,767). The `mp3_data` variable is a
44
+ binary string of MP3 encoded audio. This can be appended to a file or
45
+ streamed to a server.
46
+
47
+ ```ruby
48
+ encoder.encode_short(left, right) do |mp3_data|
49
+ # do something with encoded mp3 data..
50
+ end
51
+ ```
52
+
53
+ See all encoding methods in the Encoding section below.
54
+
55
+ ### Configuration
56
+
57
+ (work in progress)
58
+
59
+ ```ruby
60
+ # These are the defaults:
61
+ encoder.configure do |config|
62
+ config.number_of_samples = 4294967295
63
+ config.input_samplerate = 44100
64
+ config.number_of_channels = 2
65
+ config.scale = 0.95
66
+ config.scale_left = 1.0
67
+ config.scale_left = 1.0
68
+ config.output_samplerate = 44100
69
+ config.analysis = false
70
+ config.decode_only = false
71
+ config.quality = 3
72
+ config.mode = :join_stereo
73
+ config.force_mid_side = false
74
+ config.free_format = false
75
+ config.replay_gain = false
76
+ config.decode_on_the_fly = false
77
+ config.bitrate = 128
78
+ config.preset = :EXTREME # no LAME default
79
+ config.copyright = false
80
+ config.original = true
81
+ config.error_protection = false
82
+ config.extension = false
83
+ config.strict_iso = true # no LAME default
84
+ config.allow_different_block_types = false
85
+ config.temporal_masking = true
86
+ config.inter_channel_ratio = 0.0002
87
+ config.disable_short_blocks = false
88
+ config.force_short_blocks = false
89
+ config.emphasis = false
90
+
91
+ # auto-detected by default
92
+ config.asm_optimization.mmx = true
93
+ config.asm_optimization.amd3now = true
94
+ config.asm_optimization.sse = true
95
+
96
+ # these values can't be "unset" once set to true
97
+ config.id3.v2 = false
98
+ config.id3.v1_only = false
99
+ config.id3.v2_only = false
100
+ config.id3.v1_space = false
101
+ config.id3.v2_padding = false
102
+ config.id3.v2_padding_size = 128
103
+
104
+ config.quantization.reservoir = true
105
+ config.quantization.comp = 9
106
+ config.quantization.comp_short = 9
107
+ config.quantization.experimental_x = 9
108
+ config.quantization.experimental_y = 0
109
+ config.quantization.experimental_z = 0
110
+ config.quantization.naoki = true
111
+ config.quantization.msfix = 1.95
112
+
113
+ config.vbr.write_tag = true
114
+ config.vbr.mode = :vbr_off
115
+ config.vbr.q = 4
116
+ config.vbr.quality = 4.0
117
+ config.vbr.mean_bitrate = 128
118
+ config.vbr.min_bitrate = 0
119
+ config.vbr.max_bitrate = 0
120
+ config.vbr.enforce_min_bitrate = false
121
+
122
+ config.filtering.low_pass_frequency = 17000
123
+ config.filtering.low_pass_width = -1
124
+ config.filtering.high_pass_frequency = 0
125
+ config.filtering.high_pass_width = -1
126
+
127
+ config.psycho_acoustics.ath_only = false
128
+ config.psycho_acoustics.ath_short = false
129
+ config.psycho_acoustics.ath = true
130
+ config.psycho_acoustics.ath_type = 4
131
+ config.psycho_acoustics.ath_lower = 3.0
132
+ config.psycho_acoustics.athaa_type = -1
133
+ config.psycho_acoustics.athaa_sensitivity = 0.0
134
+ end
135
+ ```
136
+
137
+ ### Encoding
138
+
139
+ TODO
140
+
141
+ ### Decoding
142
+
143
+ Check this link for a 'simple' example. Note that we need to deal with the
144
+ ID3 tags ourselves before decoding MP3 frames.
145
+
146
+ http://sourceforge.net/mailarchive/message.php?msg_id=26907120
147
+
148
+ Analysis of `lame_decode_initfile` in `get_audio.c`:
149
+
150
+ 1. `hip_decode_init`
151
+ 2. Read ID3 tags, starting with "ID3"
152
+ 3. The length of the ID3 tag are at the start (right after "ID3")
153
+ 4. Optionally read the contents of the ID3 tag, or just skip it
154
+ 5. Check if there is a "AID" header, and skip it
155
+ 6. Read up until the first "mp123 syncword"
156
+
157
+ ### Development
158
+
159
+ #### ID3v2 tags
160
+
161
+ To use ID3v2 tags in files, see this post on the `lame-dev` mailing list:
162
+
163
+ http://sourceforge.net/mailarchive/message.php?msg_id=18557283
164
+
165
+ So:
166
+
167
+ 1. Disable automatic id3tag writing
168
+ 2. Write id3v2 tag at start of file (keep track of position)
169
+ 3. Write audio to file
170
+ 4. Write id3v1 tag at end of file
171
+ 5. Write vbr 'lametag' at start of audio (using position)
172
+
173
+ See the example code in `spec/integration/encoding_spec.rb` for an example.
174
+
175
+ ## Contributing
176
+
177
+ 1. Fork it
178
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
179
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
180
+ 4. Push to the branch (`git push origin my-new-feature`)
181
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,731 @@
1
+ Informal standard M. Nilsson
2
+ Document: id3v2.4.0-structure.txt 1st November 2000
3
+
4
+
5
+ ID3 tag version 2.4.0 - Main Structure
6
+
7
+ Status of this document
8
+
9
+ This document is an informal standard and replaces the ID3v2.3.0
10
+ standard [ID3v2]. A formal standard will use another revision number
11
+ even if the content is identical to document. The contents in this
12
+ document may change for clarifications but never for added or altered
13
+ functionallity.
14
+
15
+ Distribution of this document is unlimited.
16
+
17
+
18
+ Abstract
19
+
20
+ This document describes the main structure of ID3v2.4.0, which is a
21
+ revised version of the ID3v2 informal standard [ID3v2] version
22
+ 2.3.0. The ID3v2 offers a flexible way of storing audio meta
23
+ information within the audio file itself. The information may be
24
+ technical information, such as equalisation curves, as well as
25
+ title, performer, copyright etc.
26
+
27
+ ID3v2.4.0 is meant to be as close as possible to ID3v2.3.0 in order
28
+ to allow for implementations to be revised as easily as possible.
29
+
30
+
31
+ 1. Table of contents
32
+
33
+ Status of this document
34
+ Abstract
35
+ 1. Table of contents
36
+ 2. Conventions in this document
37
+ 2. Standard overview
38
+ 3. ID3v2 overview
39
+ 3.1. ID3v2 header
40
+ 3.2. ID3v2 extended header
41
+ 3.3. Padding
42
+ 3.4. ID3v2 footer
43
+ 4. ID3v2 frames overview
44
+ 4.1. Frame header flags
45
+ 4.1.1. Frame status flags
46
+ 4.1.2. Frame format flags
47
+ 5. Tag location
48
+ 6. Unsynchronisation
49
+ 6.1. The unsynchronisation scheme
50
+ 6.2. Synchsafe integers
51
+ 7. Copyright
52
+ 8. References
53
+ 9. Author's Address
54
+
55
+
56
+ 2. Conventions in this document
57
+
58
+ Text within "" is a text string exactly as it appears in a tag.
59
+ Numbers preceded with $ are hexadecimal and numbers preceded with %
60
+ are binary. $xx is used to indicate a byte with unknown content. %x
61
+ is used to indicate a bit with unknown content. The most significant
62
+ bit (MSB) of a byte is called 'bit 7' and the least significant bit
63
+ (LSB) is called 'bit 0'.
64
+
65
+ A tag is the whole tag described in this document. A frame is a block
66
+ of information in the tag. The tag consists of a header, frames and
67
+ optional padding. A field is a piece of information; one value, a
68
+ string etc. A numeric string is a string that consists of the
69
+ characters "0123456789" only.
70
+
71
+ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
72
+ "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
73
+ document are to be interpreted as described in RFC 2119 [KEYWORDS].
74
+
75
+
76
+ 3. ID3v2 overview
77
+
78
+ ID3v2 is a general tagging format for audio, which makes it possible
79
+ to store meta data about the audio inside the audio file itself. The
80
+ ID3 tag described in this document is mainly targeted at files
81
+ encoded with MPEG-1/2 layer I, MPEG-1/2 layer II, MPEG-1/2 layer III
82
+ and MPEG-2.5, but may work with other types of encoded audio or as a
83
+ stand alone format for audio meta data.
84
+
85
+ ID3v2 is designed to be as flexible and expandable as possible to
86
+ meet new meta information needs that might arise. To achieve that
87
+ ID3v2 is constructed as a container for several information blocks,
88
+ called frames, whose format need not be known to the software that
89
+ encounters them. At the start of every frame is an unique and
90
+ predefined identifier, a size descriptor that allows software to skip
91
+ unknown frames and a flags field. The flags describes encoding
92
+ details and if the frame should remain in the tag, should it be
93
+ unknown to the software, if the file is altered.
94
+
95
+ The bitorder in ID3v2 is most significant bit first (MSB). The
96
+ byteorder in multibyte numbers is most significant byte first (e.g.
97
+ $12345678 would be encoded $12 34 56 78), also known as big endian
98
+ and network byte order.
99
+
100
+ Overall tag structure:
101
+
102
+ +-----------------------------+
103
+ | Header (10 bytes) |
104
+ +-----------------------------+
105
+ | Extended Header |
106
+ | (variable length, OPTIONAL) |
107
+ +-----------------------------+
108
+ | Frames (variable length) |
109
+ +-----------------------------+
110
+ | Padding |
111
+ | (variable length, OPTIONAL) |
112
+ +-----------------------------+
113
+ | Footer (10 bytes, OPTIONAL) |
114
+ +-----------------------------+
115
+
116
+ In general, padding and footer are mutually exclusive. See details in
117
+ sections 3.3, 3.4 and 5.
118
+
119
+
120
+ 3.1. ID3v2 header
121
+
122
+ The first part of the ID3v2 tag is the 10 byte tag header, laid out
123
+ as follows:
124
+
125
+ ID3v2/file identifier "ID3"
126
+ ID3v2 version $04 00
127
+ ID3v2 flags %abcd0000
128
+ ID3v2 size 4 * %0xxxxxxx
129
+
130
+ The first three bytes of the tag are always "ID3", to indicate that
131
+ this is an ID3v2 tag, directly followed by the two version bytes. The
132
+ first byte of ID3v2 version is its major version, while the second
133
+ byte is its revision number. In this case this is ID3v2.4.0. All
134
+ revisions are backwards compatible while major versions are not. If
135
+ software with ID3v2.4.0 and below support should encounter version
136
+ five or higher it should simply ignore the whole tag. Version or
137
+ revision will never be $FF.
138
+
139
+ The version is followed by the ID3v2 flags field, of which currently
140
+ four flags are used.
141
+
142
+
143
+ a - Unsynchronisation
144
+
145
+ Bit 7 in the 'ID3v2 flags' indicates whether or not
146
+ unsynchronisation is applied on all frames (see section 6.1 for
147
+ details); a set bit indicates usage.
148
+
149
+
150
+ b - Extended header
151
+
152
+ The second bit (bit 6) indicates whether or not the header is
153
+ followed by an extended header. The extended header is described in
154
+ section 3.2. A set bit indicates the presence of an extended
155
+ header.
156
+
157
+
158
+ c - Experimental indicator
159
+
160
+ The third bit (bit 5) is used as an 'experimental indicator'. This
161
+ flag SHALL always be set when the tag is in an experimental stage.
162
+
163
+
164
+ d - Footer present
165
+
166
+ Bit 4 indicates that a footer (section 3.4) is present at the very
167
+ end of the tag. A set bit indicates the presence of a footer.
168
+
169
+
170
+ All the other flags MUST be cleared. If one of these undefined flags
171
+ are set, the tag might not be readable for a parser that does not
172
+ know the flags function.
173
+
174
+ The ID3v2 tag size is stored as a 32 bit synchsafe integer (section
175
+ 6.2), making a total of 28 effective bits (representing up to 256MB).
176
+
177
+ The ID3v2 tag size is the sum of the byte length of the extended
178
+ header, the padding and the frames after unsynchronisation. If a
179
+ footer is present this equals to ('total size' - 20) bytes, otherwise
180
+ ('total size' - 10) bytes.
181
+
182
+ An ID3v2 tag can be detected with the following pattern:
183
+ $49 44 33 yy yy xx zz zz zz zz
184
+ Where yy is less than $FF, xx is the 'flags' byte and zz is less than
185
+ $80.
186
+
187
+
188
+ 3.2. Extended header
189
+
190
+ The extended header contains information that can provide further
191
+ insight in the structure of the tag, but is not vital to the correct
192
+ parsing of the tag information; hence the extended header is
193
+ optional.
194
+
195
+ Extended header size 4 * %0xxxxxxx
196
+ Number of flag bytes $01
197
+ Extended Flags $xx
198
+
199
+ Where the 'Extended header size' is the size of the whole extended
200
+ header, stored as a 32 bit synchsafe integer. An extended header can
201
+ thus never have a size of fewer than six bytes.
202
+
203
+ The extended flags field, with its size described by 'number of flag
204
+ bytes', is defined as:
205
+
206
+ %0bcd0000
207
+
208
+ Each flag that is set in the extended header has data attached, which
209
+ comes in the order in which the flags are encountered (i.e. the data
210
+ for flag 'b' comes before the data for flag 'c'). Unset flags cannot
211
+ have any attached data. All unknown flags MUST be unset and their
212
+ corresponding data removed when a tag is modified.
213
+
214
+ Every set flag's data starts with a length byte, which contains a
215
+ value between 0 and 128 ($00 - $7f), followed by data that has the
216
+ field length indicated by the length byte. If a flag has no attached
217
+ data, the value $00 is used as length byte.
218
+
219
+
220
+ b - Tag is an update
221
+
222
+ If this flag is set, the present tag is an update of a tag found
223
+ earlier in the present file or stream. If frames defined as unique
224
+ are found in the present tag, they are to override any
225
+ corresponding ones found in the earlier tag. This flag has no
226
+ corresponding data.
227
+
228
+ Flag data length $00
229
+
230
+ c - CRC data present
231
+
232
+ If this flag is set, a CRC-32 [ISO-3309] data is included in the
233
+ extended header. The CRC is calculated on all the data between the
234
+ header and footer as indicated by the header's tag length field,
235
+ minus the extended header. Note that this includes the padding (if
236
+ there is any), but excludes the footer. The CRC-32 is stored as an
237
+ 35 bit synchsafe integer, leaving the upper four bits always
238
+ zeroed.
239
+
240
+ Flag data length $05
241
+ Total frame CRC 5 * %0xxxxxxx
242
+
243
+ d - Tag restrictions
244
+
245
+ For some applications it might be desired to restrict a tag in more
246
+ ways than imposed by the ID3v2 specification. Note that the
247
+ presence of these restrictions does not affect how the tag is
248
+ decoded, merely how it was restricted before encoding. If this flag
249
+ is set the tag is restricted as follows:
250
+
251
+ Flag data length $01
252
+ Restrictions %ppqrrstt
253
+
254
+ p - Tag size restrictions
255
+
256
+ 00 No more than 128 frames and 1 MB total tag size.
257
+ 01 No more than 64 frames and 128 KB total tag size.
258
+ 10 No more than 32 frames and 40 KB total tag size.
259
+ 11 No more than 32 frames and 4 KB total tag size.
260
+
261
+ q - Text encoding restrictions
262
+
263
+ 0 No restrictions
264
+ 1 Strings are only encoded with ISO-8859-1 [ISO-8859-1] or
265
+ UTF-8 [UTF-8].
266
+
267
+ r - Text fields size restrictions
268
+
269
+ 00 No restrictions
270
+ 01 No string is longer than 1024 characters.
271
+ 10 No string is longer than 128 characters.
272
+ 11 No string is longer than 30 characters.
273
+
274
+ Note that nothing is said about how many bytes is used to
275
+ represent those characters, since it is encoding dependent. If a
276
+ text frame consists of more than one string, the sum of the
277
+ strungs is restricted as stated.
278
+
279
+ s - Image encoding restrictions
280
+
281
+ 0 No restrictions
282
+ 1 Images are encoded only with PNG [PNG] or JPEG [JFIF].
283
+
284
+ t - Image size restrictions
285
+
286
+ 00 No restrictions
287
+ 01 All images are 256x256 pixels or smaller.
288
+ 10 All images are 64x64 pixels or smaller.
289
+ 11 All images are exactly 64x64 pixels, unless required
290
+ otherwise.
291
+
292
+
293
+ 3.3. Padding
294
+
295
+ It is OPTIONAL to include padding after the final frame (at the end
296
+ of the ID3 tag), making the size of all the frames together smaller
297
+ than the size given in the tag header. A possible purpose of this
298
+ padding is to allow for adding a few additional frames or enlarge
299
+ existing frames within the tag without having to rewrite the entire
300
+ file. The value of the padding bytes must be $00. A tag MUST NOT have
301
+ any padding between the frames or between the tag header and the
302
+ frames. Furthermore it MUST NOT have any padding when a tag footer is
303
+ added to the tag.
304
+
305
+
306
+ 3.4. ID3v2 footer
307
+
308
+ To speed up the process of locating an ID3v2 tag when searching from
309
+ the end of a file, a footer can be added to the tag. It is REQUIRED
310
+ to add a footer to an appended tag, i.e. a tag located after all
311
+ audio data. The footer is a copy of the header, but with a different
312
+ identifier.
313
+
314
+ ID3v2 identifier "3DI"
315
+ ID3v2 version $04 00
316
+ ID3v2 flags %abcd0000
317
+ ID3v2 size 4 * %0xxxxxxx
318
+
319
+
320
+ 4. ID3v2 frame overview
321
+
322
+ All ID3v2 frames consists of one frame header followed by one or more
323
+ fields containing the actual information. The header is always 10
324
+ bytes and laid out as follows:
325
+
326
+ Frame ID $xx xx xx xx (four characters)
327
+ Size 4 * %0xxxxxxx
328
+ Flags $xx xx
329
+
330
+ The frame ID is made out of the characters capital A-Z and 0-9.
331
+ Identifiers beginning with "X", "Y" and "Z" are for experimental
332
+ frames and free for everyone to use, without the need to set the
333
+ experimental bit in the tag header. Bear in mind that someone else
334
+ might have used the same identifier as you. All other identifiers are
335
+ either used or reserved for future use.
336
+
337
+ The frame ID is followed by a size descriptor containing the size of
338
+ the data in the final frame, after encryption, compression and
339
+ unsynchronisation. The size is excluding the frame header ('total
340
+ frame size' - 10 bytes) and stored as a 32 bit synchsafe integer.
341
+
342
+ In the frame header the size descriptor is followed by two flag
343
+ bytes. These flags are described in section 4.1.
344
+
345
+ There is no fixed order of the frames' appearance in the tag,
346
+ although it is desired that the frames are arranged in order of
347
+ significance concerning the recognition of the file. An example of
348
+ such order: UFID, TIT2, MCDI, TRCK ...
349
+
350
+ A tag MUST contain at least one frame. A frame must be at least 1
351
+ byte big, excluding the header.
352
+
353
+ If nothing else is said, strings, including numeric strings and URLs
354
+ [URL], are represented as ISO-8859-1 [ISO-8859-1] characters in the
355
+ range $20 - $FF. Such strings are represented in frame descriptions
356
+ as <text string>, or <full text string> if newlines are allowed. If
357
+ nothing else is said newline character is forbidden. In ISO-8859-1 a
358
+ newline is represented, when allowed, with $0A only.
359
+
360
+ Frames that allow different types of text encoding contains a text
361
+ encoding description byte. Possible encodings:
362
+
363
+ $00 ISO-8859-1 [ISO-8859-1]. Terminated with $00.
364
+ $01 UTF-16 [UTF-16] encoded Unicode [UNICODE] with BOM. All
365
+ strings in the same frame SHALL have the same byteorder.
366
+ Terminated with $00 00.
367
+ $02 UTF-16BE [UTF-16] encoded Unicode [UNICODE] without BOM.
368
+ Terminated with $00 00.
369
+ $03 UTF-8 [UTF-8] encoded Unicode [UNICODE]. Terminated with $00.
370
+
371
+ Strings dependent on encoding are represented in frame descriptions
372
+ as <text string according to encoding>, or <full text string
373
+ according to encoding> if newlines are allowed. Any empty strings of
374
+ type $01 which are NULL-terminated may have the Unicode BOM followed
375
+ by a Unicode NULL ($FF FE 00 00 or $FE FF 00 00).
376
+
377
+ The timestamp fields are based on a subset of ISO 8601. When being as
378
+ precise as possible the format of a time string is
379
+ yyyy-MM-ddTHH:mm:ss (year, "-", month, "-", day, "T", hour (out of
380
+ 24), ":", minutes, ":", seconds), but the precision may be reduced by
381
+ removing as many time indicators as wanted. Hence valid timestamps
382
+ are
383
+ yyyy, yyyy-MM, yyyy-MM-dd, yyyy-MM-ddTHH, yyyy-MM-ddTHH:mm and
384
+ yyyy-MM-ddTHH:mm:ss. All time stamps are UTC. For durations, use
385
+ the slash character as described in 8601, and for multiple non-
386
+ contiguous dates, use multiple strings, if allowed by the frame
387
+ definition.
388
+
389
+ The three byte language field, present in several frames, is used to
390
+ describe the language of the frame's content, according to ISO-639-2
391
+ [ISO-639-2]. The language should be represented in lower case. If the
392
+ language is not known the string "XXX" should be used.
393
+
394
+ All URLs [URL] MAY be relative, e.g. "picture.png", "../doc.txt".
395
+
396
+ If a frame is longer than it should be, e.g. having more fields than
397
+ specified in this document, that indicates that additions to the
398
+ frame have been made in a later version of the ID3v2 standard. This
399
+ is reflected by the revision number in the header of the tag.
400
+
401
+
402
+ 4.1. Frame header flags
403
+
404
+ In the frame header the size descriptor is followed by two flag
405
+ bytes. All unused flags MUST be cleared. The first byte is for
406
+ 'status messages' and the second byte is a format description. If an
407
+ unknown flag is set in the first byte the frame MUST NOT be changed
408
+ without that bit cleared. If an unknown flag is set in the second
409
+ byte the frame is likely to not be readable. Some flags in the second
410
+ byte indicates that extra information is added to the header. These
411
+ fields of extra information is ordered as the flags that indicates
412
+ them. The flags field is defined as follows (l and o left out because
413
+ ther resemblence to one and zero):
414
+
415
+ %0abc0000 %0h00kmnp
416
+
417
+ Some frame format flags indicate that additional information fields
418
+ are added to the frame. This information is added after the frame
419
+ header and before the frame data in the same order as the flags that
420
+ indicates them. I.e. the four bytes of decompressed size will precede
421
+ the encryption method byte. These additions affects the 'frame size'
422
+ field, but are not subject to encryption or compression.
423
+
424
+ The default status flags setting for a frame is, unless stated
425
+ otherwise, 'preserved if tag is altered' and 'preserved if file is
426
+ altered', i.e. %00000000.
427
+
428
+
429
+ 4.1.1. Frame status flags
430
+
431
+ a - Tag alter preservation
432
+
433
+ This flag tells the tag parser what to do with this frame if it is
434
+ unknown and the tag is altered in any way. This applies to all
435
+ kinds of alterations, including adding more padding and reordering
436
+ the frames.
437
+
438
+ 0 Frame should be preserved.
439
+ 1 Frame should be discarded.
440
+
441
+
442
+ b - File alter preservation
443
+
444
+ This flag tells the tag parser what to do with this frame if it is
445
+ unknown and the file, excluding the tag, is altered. This does not
446
+ apply when the audio is completely replaced with other audio data.
447
+
448
+ 0 Frame should be preserved.
449
+ 1 Frame should be discarded.
450
+
451
+
452
+ c - Read only
453
+
454
+ This flag, if set, tells the software that the contents of this
455
+ frame are intended to be read only. Changing the contents might
456
+ break something, e.g. a signature. If the contents are changed,
457
+ without knowledge of why the frame was flagged read only and
458
+ without taking the proper means to compensate, e.g. recalculating
459
+ the signature, the bit MUST be cleared.
460
+
461
+
462
+ 4.1.2. Frame format flags
463
+
464
+ h - Grouping identity
465
+
466
+ This flag indicates whether or not this frame belongs in a group
467
+ with other frames. If set, a group identifier byte is added to the
468
+ frame. Every frame with the same group identifier belongs to the
469
+ same group.
470
+
471
+ 0 Frame does not contain group information
472
+ 1 Frame contains group information
473
+
474
+
475
+ k - Compression
476
+
477
+ This flag indicates whether or not the frame is compressed.
478
+ A 'Data Length Indicator' byte MUST be included in the frame.
479
+
480
+ 0 Frame is not compressed.
481
+ 1 Frame is compressed using zlib [zlib] deflate method.
482
+ If set, this requires the 'Data Length Indicator' bit
483
+ to be set as well.
484
+
485
+
486
+ m - Encryption
487
+
488
+ This flag indicates whether or not the frame is encrypted. If set,
489
+ one byte indicating with which method it was encrypted will be
490
+ added to the frame. See description of the ENCR frame for more
491
+ information about encryption method registration. Encryption
492
+ should be done after compression. Whether or not setting this flag
493
+ requires the presence of a 'Data Length Indicator' depends on the
494
+ specific algorithm used.
495
+
496
+ 0 Frame is not encrypted.
497
+ 1 Frame is encrypted.
498
+
499
+ n - Unsynchronisation
500
+
501
+ This flag indicates whether or not unsynchronisation was applied
502
+ to this frame. See section 6 for details on unsynchronisation.
503
+ If this flag is set all data from the end of this header to the
504
+ end of this frame has been unsynchronised. Although desirable, the
505
+ presence of a 'Data Length Indicator' is not made mandatory by
506
+ unsynchronisation.
507
+
508
+ 0 Frame has not been unsynchronised.
509
+ 1 Frame has been unsyrchronised.
510
+
511
+ p - Data length indicator
512
+
513
+ This flag indicates that a data length indicator has been added to
514
+ the frame. The data length indicator is the value one would write
515
+ as the 'Frame length' if all of the frame format flags were
516
+ zeroed, represented as a 32 bit synchsafe integer.
517
+
518
+ 0 There is no Data Length Indicator.
519
+ 1 A data length Indicator has been added to the frame.
520
+
521
+
522
+ 5. Tag location
523
+
524
+ The default location of an ID3v2 tag is prepended to the audio so
525
+ that players can benefit from the information when the data is
526
+ streamed. It is however possible to append the tag, or make a
527
+ prepend/append combination. When deciding upon where an unembedded
528
+ tag should be located, the following order of preference SHOULD be
529
+ considered.
530
+
531
+ 1. Prepend the tag.
532
+
533
+ 2. Prepend a tag with all vital information and add a second tag at
534
+ the end of the file, before tags from other tagging systems. The
535
+ first tag is required to have a SEEK frame.
536
+
537
+ 3. Add a tag at the end of the file, before tags from other tagging
538
+ systems.
539
+
540
+ In case 2 and 3 the tag can simply be appended if no other known tags
541
+ are present. The suggested method to find ID3v2 tags are:
542
+
543
+ 1. Look for a prepended tag using the pattern found in section 3.1.
544
+
545
+ 2. If a SEEK frame was found, use its values to guide further
546
+ searching.
547
+
548
+ 3. Look for a tag footer, scanning from the back of the file.
549
+
550
+ For every new tag that is found, the old tag should be discarded
551
+ unless the update flag in the extended header (section 3.2) is set.
552
+
553
+
554
+ 6. Unsynchronisation
555
+
556
+ The only purpose of unsynchronisation is to make the ID3v2 tag as
557
+ compatible as possible with existing software and hardware. There is
558
+ no use in 'unsynchronising' tags if the file is only to be processed
559
+ only by ID3v2 aware software and hardware. Unsynchronisation is only
560
+ useful with tags in MPEG 1/2 layer I, II and III, MPEG 2.5 and AAC
561
+ files.
562
+
563
+
564
+ 6.1. The unsynchronisation scheme
565
+
566
+ Whenever a false synchronisation is found within the tag, one zeroed
567
+ byte is inserted after the first false synchronisation byte. The
568
+ format of synchronisations that should be altered by ID3 encoders is
569
+ as follows:
570
+
571
+ %11111111 111xxxxx
572
+
573
+ and should be replaced with:
574
+
575
+ %11111111 00000000 111xxxxx
576
+
577
+ This has the side effect that all $FF 00 combinations have to be
578
+ altered, so they will not be affected by the decoding process.
579
+ Therefore all the $FF 00 combinations have to be replaced with the
580
+ $FF 00 00 combination during the unsynchronisation.
581
+
582
+ To indicate usage of the unsynchronisation, the unsynchronisation
583
+ flag in the frame header should be set. This bit MUST be set if the
584
+ frame was altered by the unsynchronisation and SHOULD NOT be set if
585
+ unaltered. If all frames in the tag are unsynchronised the
586
+ unsynchronisation flag in the tag header SHOULD be set. It MUST NOT
587
+ be set if the tag has a frame which is not unsynchronised.
588
+
589
+ Assume the first byte of the audio to be $FF. The special case when
590
+ the last byte of the last frame is $FF and no padding nor footer is
591
+ used will then introduce a false synchronisation. This can be solved
592
+ by adding a footer, adding padding or unsynchronising the frame and
593
+ add $00 to the end of the frame data, thus adding more byte to the
594
+ frame size than a normal unsynchronisation would. Although not
595
+ preferred, it is allowed to apply the last method on all frames
596
+ ending with $FF.
597
+
598
+ It is preferred that the tag is either completely unsynchronised or
599
+ not unsynchronised at all. A completely unsynchronised tag has no
600
+ false synchonisations in it, as defined above, and does not end with
601
+ $FF. A completely non-unsynchronised tag contains no unsynchronised
602
+ frames, and thus the unsynchronisation flag in the header is cleared.
603
+
604
+ Do bear in mind, that if compression or encryption is used, the
605
+ unsynchronisation scheme MUST be applied afterwards. When decoding an
606
+ unsynchronised frame, the unsynchronisation scheme MUST be reversed
607
+ first, encryption and decompression afterwards.
608
+
609
+
610
+ 6.2. Synchsafe integers
611
+
612
+ In some parts of the tag it is inconvenient to use the
613
+ unsychronisation scheme because the size of unsynchronised data is
614
+ not known in advance, which is particularly problematic with size
615
+ descriptors. The solution in ID3v2 is to use synchsafe integers, in
616
+ which there can never be any false synchs. Synchsafe integers are
617
+ integers that keep its highest bit (bit 7) zeroed, making seven bits
618
+ out of eight available. Thus a 32 bit synchsafe integer can store 28
619
+ bits of information.
620
+
621
+ Example:
622
+
623
+ 255 (%11111111) encoded as a 16 bit synchsafe integer is 383
624
+ (%00000001 01111111).
625
+
626
+
627
+ 7. Copyright
628
+
629
+ Copyright (C) Martin Nilsson 2000. All Rights Reserved.
630
+
631
+ This document and translations of it may be copied and furnished to
632
+ others, and derivative works that comment on or otherwise explain it
633
+ or assist in its implementation may be prepared, copied, published
634
+ and distributed, in whole or in part, without restriction of any
635
+ kind, provided that a reference to this document is included on all
636
+ such copies and derivative works. However, this document itself may
637
+ not be modified in any way and reissued as the original document.
638
+
639
+ The limited permissions granted above are perpetual and will not be
640
+ revoked.
641
+
642
+ This document and the information contained herein is provided on an
643
+ 'AS IS' basis and THE AUTHORS DISCLAIMS ALL WARRANTIES, EXPRESS OR
644
+ IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF
645
+ THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
646
+ WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
647
+
648
+
649
+ 8. References
650
+
651
+ [ID3v2] Martin Nilsson, 'ID3v2 informal standard'.
652
+
653
+ <url:http://www.id3.org/id3v2.3.0.txt>
654
+
655
+ [ISO-639-2] ISO/FDIS 639-2.
656
+ 'Codes for the representation of names of languages, Part 2: Alpha-3
657
+ code.' Technical committee / subcommittee: TC 37 / SC 2
658
+
659
+ [ISO-3309] ISO 3309
660
+ 'Information Processing Systems--Data Communication High-Level Data
661
+ Link Control Procedure--Frame Structure', IS 3309, October 1984, 3rd
662
+ Edition.
663
+
664
+ [ISO-8859-1] ISO/IEC DIS 8859-1.
665
+ '8-bit single-byte coded graphic character sets, Part 1: Latin
666
+ alphabet No. 1.' Technical committee / subcommittee: JTC 1 / SC 2
667
+
668
+ [JFIF] 'JPEG File Interchange Format, version 1.02'
669
+
670
+ <url:http://www.w3.org/Graphics/JPEG/jfif.txt>
671
+
672
+ [KEYWORDS] S. Bradner, 'Key words for use in RFCs to Indicate
673
+ Requirement Levels', RFC 2119, March 1997.
674
+
675
+ <url:ftp://ftp.isi.edu/in-notes/rfc2119.txt>
676
+
677
+ [MPEG] ISO/IEC 11172-3:1993.
678
+ 'Coding of moving pictures and associated audio for digital storage
679
+ media at up to about 1,5 Mbit/s, Part 3: Audio.'
680
+ Technical committee / subcommittee: JTC 1 / SC 29
681
+ and
682
+ ISO/IEC 13818-3:1995
683
+ 'Generic coding of moving pictures and associated audio information,
684
+ Part 3: Audio.'
685
+ Technical committee / subcommittee: JTC 1 / SC 29
686
+ and
687
+ ISO/IEC DIS 13818-3
688
+ 'Generic coding of moving pictures and associated audio information,
689
+ Part 3: Audio (Revision of ISO/IEC 13818-3:1995)'
690
+
691
+ [PNG] 'Portable Network Graphics, version 1.0'
692
+
693
+ <url:http://www.w3.org/TR/REC-png-multi.html>
694
+
695
+ [UNICODE] The Unicode Consortium,
696
+ 'The Unicode Standard Version 3.0', ISBN 0-201-61633-5.
697
+
698
+ <url:http://www.unicode.org/unicode/standard/versions/Unicode3.0.htm>
699
+
700
+ [URL] T. Berners-Lee, L. Masinter & M. McCahill, 'Uniform Resource
701
+ Locators (URL)', RFC 1738, December 1994.
702
+
703
+ <url:ftp://ftp.isi.edu/in-notes/rfc1738.txt>
704
+
705
+ [UTF-8] F. Yergeau, 'UTF-8, a transformation format of ISO 10646',
706
+ RFC 2279, January 1998.
707
+
708
+ <url:ftp://ftp.isi.edu/in-notes/rfc2279.txt>
709
+
710
+ [UTF-16] F. Yergeau, 'UTF-16, an encoding of ISO 10646', RFC 2781,
711
+ February 2000.
712
+
713
+ <url:ftp://ftp.isi.edu/in-notes/rfc2781.txt>
714
+
715
+ [ZLIB] P. Deutsch, Aladdin Enterprises & J-L. Gailly, 'ZLIB
716
+ Compressed Data Format Specification version 3.3', RFC 1950,
717
+ May 1996.
718
+
719
+ <url:ftp://ftp.isi.edu/in-notes/rfc1950.txt>
720
+
721
+
722
+ 9. Author's Address
723
+
724
+ Written by
725
+
726
+ Martin Nilsson
727
+ Rydsv�gen 246 C. 30
728
+ SE-584 34 Link�ping
729
+ Sweden
730
+
731
+ Email: nilsson at id3.org