1 7 8 package org.openlaszlo.iv.flash.api.sound; 9 10 import org.openlaszlo.iv.flash.parser.*; 11 import org.openlaszlo.iv.flash.util.*; 12 import org.openlaszlo.iv.flash.url.*; 13 import org.openlaszlo.iv.flash.api.*; 14 15 import java.io.*; 16 17 23 24 public class MP3Sound extends Sound 25 { 26 public int delaySeek; 27 public DataMarker data; 28 29 30 31 public static MP3Sound newMP3Sound( IVUrl url ) throws IVException, IOException 32 { 33 return newMP3Sound( Util.readUrl( url ) ); 34 } 35 36 37 38 public static MP3Sound newMP3Sound( FlashBuffer fob ) throws IVException, IOException 39 { 40 byte [] buffer; 41 42 44 MP3Helper mp3 = new MP3Helper( fob ); 45 46 49 FlashBuffer fb = new FlashBuffer( fob.getSize() ); 50 51 while ( ( buffer = mp3.nextFrame() ) != null ) 52 { 53 fb.writeArray( buffer, 0, buffer.length ); 54 } 55 56 MP3Sound sound = new MP3Sound(); 57 58 sound.compressFormat = COMPRESS_MP3; 59 60 62 switch ( mp3.getFrequency() ) 63 { 64 case 11025: sound.rate = RATE_11; break; 65 case 22050: sound.rate = RATE_22; break; 66 case 44100: sound.rate = RATE_44; break; 67 } 68 69 71 sound.isSample16bit = true; 72 73 75 sound.isStereo = mp3.getStereo(); 76 77 79 sound.sampleCount = mp3.getSamples(); 80 81 83 sound.delaySeek = 0; 84 85 sound.data = new DataMarker( fb.getBuf(), 0, fb.getSize() ); 88 89 return sound; 90 } 91 92 public int getSize() { 93 return data.buffer.length; 94 } 95 96 97 98 public void write( FlashOutput fob ) 99 { 100 fob.writeTag( getTag(), 2 + 1 + 4 + 2 + data.length() ); 101 fob.writeDefID( this ); 102 fob.initBits(); 103 fob.writeBits( compressFormat, 4 ); 104 fob.writeBits( rate, 2 ); 105 fob.writeBool( isSample16bit ); 106 fob.writeBool( isStereo ); 107 fob.flushBits(); 108 fob.writeDWord( sampleCount ); 109 fob.writeWord( delaySeek ); data.write(fob); 111 } 112 113 114 115 protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) 116 { 117 super.copyInto( item, copier ); 118 119 ( ( MP3Sound ) item ).delaySeek = delaySeek; 120 ( ( MP3Sound ) item ).data = ( DataMarker ) data.getCopy(); 121 122 return item; 123 } 124 125 126 127 public FlashItem getCopy( ScriptCopier copier ) 128 { 129 return copyInto( new MP3Sound(), copier ); 130 } 131 132 133 134 public int getDelaySeek() { return delaySeek; } 135 136 137 138 public void setDelaySeek( int val ) { delaySeek = val; } 139 } 140 | Popular Tags |