| 1 | package org.farng.mp3.id3; |
| 2 | |
| 3 | import org.farng.mp3.InvalidTagException; |
| 4 | import org.farng.mp3.object.AbstractMP3Object; |
| 5 | import org.farng.mp3.object.ObjectGroupRepeated; |
| 6 | import org.farng.mp3.object.ObjectNumberFixedLength; |
| 7 | import org.farng.mp3.object.ObjectNumberHashMap; |
| 8 | import org.farng.mp3.object.ObjectStringNullTerminated; |
| 9 | |
| 10 | import java.io.IOException; |
| 11 | import java.io.RandomAccessFile; |
| 12 | |
| 13 | /** |
| 14 | * <h3>4.12. Equalisation (2)</h3> |
| 15 | * <p/> |
| 16 | * <p> This is another subjective, alignment frame. It allows the user to<br> |
| 17 | * <p/> |
| 18 | * predefine an equalisation curve within the audio file. There may be<br> more than one |
| 19 | * "EQU2" frame in each tag, but only one with the same<br> identification string.</p> |
| 20 | * <p/> |
| 21 | * <p> <Header of 'Equalisation (2)', ID: "EQU2"><br> |
| 22 | * <p/> |
| 23 | * Interpolation method $xx<br> |
| 24 | * Identification <text string> $00</p> |
| 25 | * <p/> |
| 26 | * <p> The 'interpolation method' describes which method is preferred when<br> |
| 27 | * <p/> |
| 28 | * an interpolation between the adjustment point that follows. The<br> following methods are |
| 29 | * currently defined:</p> |
| 30 | * <p/> |
| 31 | * <p> $00 Band<br> No |
| 32 | * interpolation is made. A jump from one adjustment level to<br> |
| 33 | * <p/> |
| 34 | * another occurs in the middle between two adjustment |
| 35 | * points.<br> $01 Linear<br> |
| 36 | * Interpolation between adjustment points is linear.</p> |
| 37 | * <p/> |
| 38 | * <p> The 'identification' string is used to identify the situation and/or<br> |
| 39 | * <p/> |
| 40 | * device where this adjustment should apply. The following is then<br> repeated for every |
| 41 | * adjustment point</p> |
| 42 | * <p/> |
| 43 | * <p> Frequency $xx xx<br> |
| 44 | * Volume adjustment $xx xx</p> |
| 45 | * <p/> |
| 46 | * <p> The frequency is stored in units of 1/2 Hz, giving it a range from 0<br> to 32767 |
| 47 | * Hz.</p> |
| 48 | * <p/> |
| 49 | * <p> The volume adjustment is encoded as a fixed point decibel value, 16<br> bit signed |
| 50 | * integer representing (adjustment*512), giving +/- 64 dB<br> with a precision of 0.001953125 dB. E.g. +2 |
| 51 | * dB is stored as $04 00<br> |
| 52 | * <p/> |
| 53 | * and -2 dB is $FC 00.</p> |
| 54 | * <p/> |
| 55 | * <p> Adjustment points should be ordered by frequency and one frequency<br> should only be |
| 56 | * described once in the frame.<br> </p> |
| 57 | * |
| 58 | * @author Eric Farng |
| 59 | * @version $Revision: 1.5 $ |
| 60 | */ |
| 61 | public class FrameBodyEQU2 extends AbstractID3v2FrameBody { |
| 62 | |
| 63 | /** |
| 64 | * Creates a new FrameBodyEQU2 object. |
| 65 | */ |
| 66 | public FrameBodyEQU2() { |
| 67 | super(); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Creates a new FrameBodyEQU2 object. |
| 72 | */ |
| 73 | public FrameBodyEQU2(final FrameBodyEQU2 body) { |
| 74 | super(body); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Creates a new FrameBodyEQU2 object. |
| 79 | */ |
| 80 | public FrameBodyEQU2(final byte interpolationMethod, |
| 81 | final String owner, |
| 82 | final short frequency, |
| 83 | final short volumeAdjustment) { |
| 84 | setObject("Interpolation Method", new Byte(interpolationMethod)); |
| 85 | setObject("Owner", owner); |
| 86 | this.addGroup(frequency, volumeAdjustment); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Creates a new FrameBodyEQU2 object. |
| 91 | */ |
| 92 | public FrameBodyEQU2(final RandomAccessFile file) throws IOException, InvalidTagException { |
| 93 | this.read(file); |
| 94 | } |
| 95 | |
| 96 | public String getIdentifier() { |
| 97 | return "EQU2" + ((char) 0) + getOwner(); |
| 98 | } |
| 99 | |
| 100 | public String getOwner() { |
| 101 | return (String) getObject("Owner"); |
| 102 | } |
| 103 | |
| 104 | public void getOwner(final String description) { |
| 105 | setObject("Owner", description); |
| 106 | } |
| 107 | |
| 108 | public void addGroup(final short frequency, final short volumeAdjustment) { |
| 109 | final ObjectGroupRepeated group = (ObjectGroupRepeated) this.getObject("Data"); |
| 110 | final AbstractMP3Object freq = new ObjectNumberFixedLength("Frequency", 2); |
| 111 | final AbstractMP3Object volume = new ObjectNumberFixedLength("Volume Adjustment", 2); |
| 112 | group.addObject(freq); |
| 113 | group.addObject(volume); |
| 114 | setObject("Data", group); |
| 115 | } |
| 116 | |
| 117 | protected void setupObjectList() { |
| 118 | appendToObjectList(new ObjectNumberHashMap("Interpolation Method", 1)); |
| 119 | appendToObjectList(new ObjectStringNullTerminated("Owner")); |
| 120 | final ObjectGroupRepeated group = new ObjectGroupRepeated("Data"); |
| 121 | group.addProperty(new ObjectNumberFixedLength("Frequency", 2)); |
| 122 | group.addProperty(new ObjectNumberFixedLength("Volume Adjustment", 2)); |
| 123 | appendToObjectList(group); |
| 124 | } |
| 125 | } |