package collegesoft.audio.play;import java.io.*;import java.util.*;import sun.audio.*;import collegesoft.util.*;import collegesoft.audio.*;public class AudioPlayer extends InputStream implements Runnable{ public static final short MIN_WORD=-32768; public static final short MAX_WORD=32767; public static final short gsm_FAC[]={18431,20479,22527,24575,26623,28671,30719,32767}; public static final short gsm_QLB[]={3277,11469,21299,32767}; private static final int MAX_FRAME_READ=100; public static final short FRAME_SIZE=33; private static final int chunk_size=3300; private short dp0[]=new short[280]; private short u[]=new short[8];; private short LARpp[][]=new short[2][8]; private short j; private short nrp=40; private short v[]=new short[9]; private short msr; private InputStream player_input;/private Vector listeners=new Vector(); private OutputStream po; private InputStream pi;private boolean pause=true;private static boolean playing=false;private static AudioStream audiostream=null;//int len=165;boolean readOver=true;int c=0;int[] b={-40,32,-94,-31,90,80,0,73,36,-110,73,36};long test;byte[] data=new byte[1200];//boolean readdataOver=false;boolean decoded=false;int decodelen=0;byte ttt[]=new byte[33];public AudioPlayer(){//for(int i=0;i/*int i=0x2e736e64; byte byte0=32; byte byte1=-1; int j=1; char c='\u1F40'; int k=1; byte byte2=24;data[0]=(byte)(i>>>24&0xff); data[1]=(byte)(i>>>16&0xff); data[2]=(byte)(i>>>8&0xff); data[3]=(byte)(i&0xff);//au file's location data[4]=(byte)(byte0>>>24&0xff); data[5]=(byte)(byte0>>>16&0xff); data[6]=(byte)(byte0>>>8&0xff); data[7]=(byte)(byte0&0xff);//au file's samples data[8]=(byte)(byte1>>>24&0xff); data[9]=(byte)(byte1>>>16&0xff); data[10]=(byte)(byte1>>>8&0xff); data[11]=(byte)(byte1&0xff);//au file's format data[12]=(byte)(j>>>24&0xff); data[13]=(byte)(j>>>16&0xff); data[14]=(byte)(j>>>8&0xff); data[15]=(byte)(j&0xff);//au file's rate data[16]=(byte)(c>>>24&0xff); data[17]=(byte)(c>>>16&0xff); data[18]=(byte)(c>>>8&0xff); data[19]=(byte)(c&0xff);//au file's channels data[20]=(byte)(k>>>24&0xff); data[21]=(byte)(k>>>16&0xff); data[22]=(byte)(k>>>8&0xff); data[23]=(byte)(k&0xff);//au file's info for(int l=byte2;l}public int read()throws IOException{ throw new IOException("Unsupported version of read() who did that ?"); }public int read1()throws IOException{int rt=-1;while(true){if(!readOver){rt=player_input.read();c++;readOver=(c==len);return rt;}else{if(c==len){rt=player_input.read();if(rt==-1)throw new IOException("READ_STREAM_OVER");if(rt>1)throw new IOException("READ_STREAM_ERROR");c=0;readOver=(rt==0);}else{c++;return rt(c-1);}}}}public int read1(byte abyte0[], int i, int j)throws IOException{ if(j int k=read1(); if(k==-1)return -1; abyte0[i]=(byte)k; int i1=1; try{ while(i1 int l=read1(); if(l==-1)break; if(abyte0!=null)abyte0[i+i1]=(byte)l; i1++; } }catch(IOException _ex){} return i1;} public int read(byte abyte0[], int i1, int j1)throws IOException{//if(!decoded)System.arraycopy(data,32,abyte0,0,400);//else System.arraycopy(data,432,abyte0,0,400);decoded=false;while(!decoded){get_frame(ttt,0);process_decode(1,ttt,null);}decoded=false;System.arraycopy(data,32,abyte0,0,400);//System.out.println("read Data i1(start)="+i1+",j1(length)="+j1+","+(System.currentTimeMillis()-test));//k+","+l);//test=System.currentTimeMillis();//for(int i=i1;i //System.arraycopy(data, 32, abyte0, i1, j1); return j1; }public int rt(int i){int x=i%33;if(xelse return b[5+((x-12)%7)];}///public void addAudioPlayListener(AudioPlayListener lter){listeners.addElement(lter);}synchronized void notifyListener(int type){AudioPlayEvent evt=new AudioPlayEvent(type);for(Enumeration enu=listeners.elements();enu.hasMoreElements();)((AudioPlayListener)enu.nextElement()).onAudioPlayEvent(evt);}public static void writeAudataerTo(OutputStream out)throws IOException{ int i=0x2e736e64; byte byte0=32; byte byte1=-1; int j=1; char c='\u1F40'; int k=1; byte byte2=24;//au file's id out.write(i>>>24&0xff); out.write(i>>>16&0xff); out.write(i>>>8&0xff); out.write(i&0xff);//au file's location out.write(byte0>>>24&0xff); out.write(byte0>>>16&0xff); out.write(byte0>>>8&0xff); out.write(byte0&0xff);//au file's samples out.write(byte1>>>24&0xff); out.write(byte1>>>16&0xff); out.write(byte1>>>8&0xff); out.write(byte1&0xff);//au file's format out.write(j>>>24&0xff); out.write(j>>>16&0xff); out.write(j>>>8&0xff); out.write(j&0xff);//au file's rate out.write(c>>>24&0xff); out.write(c>>>16&0xff); out.write(c>>>8&0xff); out.write(c&0xff);//au file's channels out.write(k>>>24&0xff); out.write(k>>>16&0xff); out.write(k>>>8&0xff); out.write(k&0xff);//au file's info for(int l=byte2;l} public void run(){try{System.out.println("playing.---....");process_frame(po);System.out.println("play over.---....");notifyListener(AudioPlayEvent.PLAY_OVER);playing=false;}catch(IOException e){if("READ_STREAM_ERROR".equalsIgnoreCase(e.getMessage())){notifyListener(AudioPlayEvent.PLAY_ERR);}else if("READ_STREAM_OVER".equalsIgnoreCase(e.getMessage())){notifyListener(AudioPlayEvent.PLAY_OVER);}else notifyListener(AudioPlayEvent.PLAY_ERR);playing=false;System.out.println("io_"+e.toString());}}public void suspend_play(){pause=true;}public void resume_play(){if(!pause)return;pause=false;} public void stop_play(){try{if(po!=null){po.close();po=null;}if(pi!=null){pi.close();pi=null;}}catch(Exception e){} sun.audio.AudioPlayer.player.stop(audiostream); playing=false; } public void start_play(InputStream inp){this.player_input=inp;try{if(po!=null){po.close();po=null;}}catch(Exception e){}try{if(pi!=null){pi.close();pi=null;}}catch(Exception e){}try{audiostream.close();audiostream=null;}catch(Exception ee){}try{po=new PipeOutputStream();pi=new PipeInputStream((PipeOutputStream)po,8192);writeAudataerTo(po);//audiostream=new AudioStream(pi);//sun.audio.AudioPlayer.player.stop(audiostream);//sun.audio.AudioPlayer.player.start(audiostream);sun.audio.AudioPlayer.player.stop(this);sun.audio.AudioPlayer.player.start(this);playing=true;//new Thread(this).start();}catch(Exception e){} }/// public void process_frame(OutputStream outputstream) throws IOException{ byte abyte0[]=new byte[165]; boolean flag=false; int k=0; for(int l=0;k!=-1;l=0){ for(int i=0;i k=get_frame(abyte0,l); if(k!=-1)l+=k; } if(k!=-1)process_decode(5,abyte0,outputstream);else{if(k==-1&&l int i1=l/33; process_decode(i1,abyte0,outputstream);} } } } private int get_frame(byte abyte0[],int i) throws IOException{ int k=33; int l=0; int i1; for(i1=read1(abyte0,i+l,k);i1>0&&i1 l+=i1; k-=i1; } if(i1 else return i1+l; } private void process_decode(int i,byte abyte0[],OutputStream outputstream) throws IOException{ byte abyte1[]=new byte[33]; int l=0; for(int k=0;k System.arraycopy(abyte0,l,abyte1,0,33); l+=33; int ai[]=gsm_decode_java(abyte1); ulaw_output(outputstream,ai);