Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/06/2010, 21:20
joseluisbz
 
Fecha de Ingreso: febrero-2007
Ubicación: Barranquilla, Colombia
Mensajes: 181
Antigüedad: 17 años, 2 meses
Puntos: 3
Convertir Vector Byte de BigEndian a LittleEndian

Cordial Saludo:

Espero que por favor me indiquen que opinan de este código que he realizado.

Esto es un pequeño bosquejo de que tipo son los datos... no es un código lineal

Código Java:
Ver original
  1. AudioFormat FormatoAudio;
Código Java:
Ver original
  1. DataLine.Info info = new DataLine.Info(TargetDataLine.class, FormatoAudio);
  2. final TargetDataLine LineaDatoDestino = (TargetDataLine)AudioSystem.getLine(info);
  3. LineaDatoDestino.open(FormatoAudio);
  4. LineaDatoDestino.start();
Código Java:
Ver original
  1. int TallaBuffer = int)FormatoAudio.getSampleRate()*FormatoAudio.getFrameSize();
  2. byte ArregloByte[] = new byte[TallaBuffer];

Antes de entrar en el tema:
Código Java:
Ver original
  1. FlujoSalida = new ByteArrayOutputStream();
  2.                     capturando = true;
  3.                     try {
  4.                         while (capturando) {
  5.                             int Leidos = LineaDatoDestino.read(ArregloByte, 0, ArregloByte.length);
  6.                             if (Leidos > 0) {
  7.                                 CopiadorTexto(ArregloByte);
  8.                                 if(jcbEscuchar.isSelected()){
  9.                                     Repetir(ArregloByte,Leidos);
  10.                                 }
  11.                                 FlujoSalida.write(ArregloByte, 0, Leidos);
  12.                             }
  13.                         }

ArregloByte es un arreglo de tipo byte que se define anteriormente...
Sabemos que el audio se puede almacenar en cuatro, tres, dos y un byte...aunque realmente he intentado con formatos de cuatro y tres bytes y no me funcionan (ese es otro tema)... sin embargo el motivo es capturar almacenar la informacion de audio sin importar el número de bytes (de 1 a 4) y si es almacenado de manera BigEndian o LittleEndian...
Cuando capturo el dato en un entero, quiero aumentar el volumen (Multiplicando por 2) o disminuirlo (Dividiendo x 2)..y posteriormente almacenarlo en el mismo arreglo..



Código Java:
Ver original
  1. private void Repetir(byte[] ArregloByte, final int Leidos){
  2. final byte VectorDatoByte[] = ArregloByte.clone();
  3.  
  4. int talla = FormatoAudio.getSampleSizeInBits();
  5. boolean SignificacionInicial = FormatoAudio.isBigEndian();
  6. int NumeroByte = 0;
  7. switch (talla) {
  8.     case 32: NumeroByte = 4; break;
  9.     case 24: NumeroByte = 3; break;
  10.     case 16: NumeroByte = 2; break;
  11.     case 8: NumeroByte = 1; break;
  12. }
  13. int Entero = 0;
  14. byte byte0;
  15. byte byte1;
  16. byte byte2;
  17. byte byte3;
  18. for (int ND = 0;ND<VectorDatoByte.length/NumeroByte; ND++){
  19.   byte0 = (ND*NumeroByte+0)< VectorDatoByte.length?VectorDatoByte[ND*NumeroByte+0]:0;
  20.   byte1 = (ND*NumeroByte+1)< VectorDatoByte.length?VectorDatoByte[ND*NumeroByte+1]:0;
  21.   byte2 = (ND*NumeroByte+2)< VectorDatoByte.length?VectorDatoByte[ND*NumeroByte+2]:0;
  22.   byte3 = (ND*NumeroByte+3)< VectorDatoByte.length?VectorDatoByte[ND*NumeroByte+3]:0;
  23.   if (NumeroByte==4){
  24.       if(SignificacionInicial){
  25.           Entero = (int)(((byte3 & 0xFF) << 24)|((byte2 & 0xFF) << 16)|((byte1 & 0xFF) << 8)|((byte0 & 0xFF) << 0));
  26.       }else{
  27.           Entero = (int)(((byte0 & 0xFF) << 24)|((byte1 & 0xFF) << 16)|((byte2 & 0xFF) << 8)|((byte3 & 0xFF) << 0));
  28.       }
  29.   }
  30.   if (NumeroByte==3){
  31.       if(SignificacionInicial){
  32.           Entero = (int)(((byte2 & 0xFF) << 16)|((byte1 & 0xFF) << 8)|((byte0 & 0xFF) << 0));
  33.       }else{
  34.           Entero = (int)(((byte0 & 0xFF) << 16)|((byte1 & 0xFF) << 8)|((byte2 & 0xFF) << 0));
  35.       }
  36.   }
  37.   if (NumeroByte==2){
  38.       if(SignificacionInicial){
  39.           Entero = (int)(((byte1 & 0xFF) << 8)|((byte0 & 0xFF) << 0));
  40.       }else{
  41.           Entero = (int)(((byte0 & 0xFF) << 8)|((byte1 & 0xFF) << 0));
  42.       }
  43.   }
  44.   if (NumeroByte==1){
  45.       Entero = (int)(((byte0 & 0xFF)<< 0));
  46.   }
  47.  
  48.   if (Magnitud <1) {  //Divide x 2
  49.       Entero = (int)(Entero >> 1);
  50.   }
  51.   if (Magnitud >1) {  //Multiplica x 2
  52.       Entero = (int)(Entero << 1);
  53.   }
  54.  
  55.   if (NumeroByte==4){
  56.       if(SignificacionInicial){
  57.           if (VectorDatoByte.length>(ND*NumeroByte+0)){VectorDatoByte[ND*NumeroByte+0] = (byte)((Entero >> 0) & 0xFF);}
  58.           if (VectorDatoByte.length>(ND*NumeroByte+1)){VectorDatoByte[ND*NumeroByte+1] = (byte)((Entero >> 8) & 0xFF);}
  59.           if (VectorDatoByte.length>(ND*NumeroByte+2)){VectorDatoByte[ND*NumeroByte+2] = (byte)((Entero >> 16) & 0xFF);}
  60.           if (VectorDatoByte.length>(ND*NumeroByte+3)){VectorDatoByte[ND*NumeroByte+3] = (byte)((Entero >> 24) & 0xFF);}
  61.       }else{
  62.           if (VectorDatoByte.length>(ND*NumeroByte+3)){VectorDatoByte[ND*NumeroByte+3] = (byte)((Entero >> 0) & 0xFF);}
  63.           if (VectorDatoByte.length>(ND*NumeroByte+2)){VectorDatoByte[ND*NumeroByte+2] = (byte)((Entero >> 8) & 0xFF);}
  64.           if (VectorDatoByte.length>(ND*NumeroByte+1)){VectorDatoByte[ND*NumeroByte+1] = (byte)((Entero >> 16) & 0xFF);}
  65.           if (VectorDatoByte.length>(ND*NumeroByte+0)){VectorDatoByte[ND*NumeroByte+0] = (byte)((Entero >> 24) & 0xFF);}
  66.       }
  67.   }
  68.   if (NumeroByte==3){
  69.       if(SignificacionInicial){
  70.           if (VectorDatoByte.length>(ND*NumeroByte+0)){VectorDatoByte[ND*NumeroByte+0] = (byte)((Entero >> 0) & 0xFF);}
  71.           if (VectorDatoByte.length>(ND*NumeroByte+1)){VectorDatoByte[ND*NumeroByte+1] = (byte)((Entero >> 8) & 0xFF);}
  72.           if (VectorDatoByte.length>(ND*NumeroByte+2)){VectorDatoByte[ND*NumeroByte+2] = (byte)((Entero >> 16) & 0xFF);}
  73.       }else{
  74.           if (VectorDatoByte.length>(ND*NumeroByte+2)){VectorDatoByte[ND*NumeroByte+2] = (byte)((Entero >> 0) & 0xFF);}
  75.           if (VectorDatoByte.length>(ND*NumeroByte+1)){VectorDatoByte[ND*NumeroByte+1] = (byte)((Entero >> 8) & 0xFF);}
  76.           if (VectorDatoByte.length>(ND*NumeroByte+0)){VectorDatoByte[ND*NumeroByte+0] = (byte)((Entero >> 16) & 0xFF);}
  77.       }
  78.   }
  79.   if (NumeroByte==2){
  80.       if(SignificacionInicial){
  81.           if (VectorDatoByte.length>(ND*NumeroByte+0)){VectorDatoByte[ND*NumeroByte+0] = (byte)((Entero >> 0) & 0xFF);}
  82.           if (VectorDatoByte.length>(ND*NumeroByte+1)){VectorDatoByte[ND*NumeroByte+1] = (byte)((Entero >> 8) & 0xFF);}
  83.       }else{
  84.           if (VectorDatoByte.length>(ND*NumeroByte+1)){VectorDatoByte[ND*NumeroByte+1] = (byte)((Entero >> 0) & 0xFF);}
  85.           if (VectorDatoByte.length>(ND*NumeroByte+0)){VectorDatoByte[ND*NumeroByte+0] = (byte)((Entero >> 8) & 0xFF);}
  86.       }
  87.   }
  88.   if (NumeroByte==1){
  89.       if ((VectorDatoByte.length>ND*NumeroByte+0)){VectorDatoByte[ND*NumeroByte+0] = (byte)((Entero >> 0) & 0xFF);}
  90.   }
  91. }  //Fin Ciclo For

quiero saber si mi código está bien... y si está bien porque al disminuir el volumen (Dividir x2) hay mucho ruido...

Saludos y gracias de antemano...
__________________
Jose Luis Bernal Zambrano
Please response to:
[email protected]