⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 synthesisfilter.java

📁 java实现的多媒体播放器,可以在手机上运行
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/**
 *-----------------------------------------------------------------------
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as published
 *   by the Free Software Foundation; either version 2 of the License,or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Library General Public License for more details.
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not,write to the Free Software
 *   Foundation,Inc.,675 Mass Ave,Cambridge,MA 02139,USA.
 *----------------------------------------------------------------------
 */
package javazoom.jlme.decoder;



final class SynthesisFilter {
	

  private final static float MY_PI = (float)3.14159265358979323846;
  private final static float cos1_64 = (float)0.500603;
  private final static float cos3_64 = (float)0.50547093;
  private final static float cos5_64 = (float)0.5154473;
  private final static float cos7_64 = (float)0.5310426;
  private final static float cos9_64 = (float)0.5531039;
  private final static float cos11_64 =(float)0.582935;
  private final static float cos13_64 =(float)0.6225041;
  private final static float cos15_64 =(float)0.6748083;
  private final static float cos17_64 =(float)0.7445363;
  private final static float cos19_64 =(float)0.8393496;
  private final static float cos21_64 =(float)0.9725682;
  private final static float cos23_64 =(float)1.1694399;
  private final static float cos25_64 =(float)1.4841646;
  private final static float cos27_64 =(float)2.057781;
  private final static float cos29_64 =(float)3.4076085;
  private final static float cos31_64 =(float)10.190008;
  private final static float cos1_32 =(float)0.5024193; 
  private final static float cos3_32 = (float)0.5224986;
  private final static float cos5_32 = (float)0.56694406;
  private final static float cos7_32 =(float)0.6468218; 
  private final static float cos9_32 =(float)0.7881546; 
  private final static float cos11_32 =(float)1.0606776;
  private final static float cos13_32 =(float)1.7224472;
  private final static float cos15_32 =(float)5.1011486;
  private final static float cos1_16 =(float)0.5097956;
  private final static float cos3_16 =(float)0.6013449;
  private final static float cos5_16 =(float)0.8999762;
  private final static float cos7_16 =(float)2.5629156;
  private final static float cos1_8 =(float)0.5411961; 
  private final static float cos3_8 =(float)1.306563;
  private final static float cos1_4 =(float)0.70710677; 

  private static float d16[] [] = null;
  private float[] v1;
  private float[] v2;
  private float[] actual_v;
  private int actual_write_pos;
  private float[] samples;
  private int channel;
  private static float scalefactor;

 public SynthesisFilter(int channelnumber,float factor) {

    if (d16 == null)
      loadD16();
    v1 = new float[512];
    v2 = new float[512];
    channel = channelnumber;
    scalefactor = factor;
    reset();
  }

  /**
   *  Converts a 1D array into a number of smaller arrays. This is used to achieve offset + constant indexing into an array. Each sub-array represents a block of values of the original array.
   *@param  array      The array to split up into blocks.
   *@param  blockSize  The size of the blocks to split the array into. This must be an exact divisor of the length of the array,or some data will be lost from the main array.
   *@return            An array of arrays in which each element in the returned array will be of length <code>blockSize</code>.
   */
  private final void loadD16() {
    float d[] = null;
    try {
      d = D16.dat;
    }
    catch (Exception e) {
      System.out.println("couldn't load the array for the SynthesisFilter ");
      System.exit(1);
    }
    finally {
      try {
      }
      catch (Exception e) { }
    }
    int size = d.length / 16;
    d16 = new float[size] [];
    for (int i = 0; i < size; i++) {
      d16[i] = subArray(d,i * 16,16);
    }
  }

  /**
   *  Returns a subarray of an existing array.
   *@param  array  The array to retrieve a subarra from.
   *@param  offs   The offset in the array that corresponds to the first index of the subarray.
   *@param  len    The number of indeces in the subarray.
   *@return        The subarray,which may be of length 0.
   */
  private final static float[] subArray(float[] array,int offs,int len) {
    if (offs + len > array.length) {
      len = array.length - offs;
    }
    if (len < 0) {
      len = 0;
    }
    float[] subarray = new float[len];
    System.arraycopy(array,offs,subarray,0,len);
    return subarray;
  }

  /** Reset the synthesis filter. */
  public final void reset() {
	for (int ii=0; ii<v1.length;ii++) {
		v1[ii]=0;
	} 
	for (int ii=0; ii<v2.length;ii++) {
		v2[ii]=0;
	} 
    actual_v = v1;
    actual_write_pos = 15;
  }


  public final void calculateSamples(float[] s,SampleBuffer buffer) {
    samples = s;
    compute_new_v();
    compute_pcm_samples(buffer);
    actual_write_pos = (actual_write_pos + 1) & 0xf;
    actual_v = (actual_v == v1) ? v2 : v1;
  }

    /* taken out of compute_new_v */

  static float new_v0,new_v1,new_v2,new_v3,new_v4,new_v5,new_v6,new_v7,new_v8,new_v9,new_v10,new_v11,new_v12,new_v13,new_v14,new_v15,new_v16,new_v17,new_v18,new_v19,new_v20,
      new_v21,new_v22,new_v23,new_v24,new_v25,new_v26,new_v27,new_v28,new_v29,new_v30,new_v31,p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,pp0,pp1,pp2,pp3,pp4,
      pp5,pp6,pp7,pp8,pp9,pp10,pp11,pp12,pp13,pp14,pp15;
  static int loc1,loc2,loc3,loc4,loc5,loc6,loc7,loc8,loc9,loc10,loc11,loc12,loc13,loc14,loc15,loc16,loc17,loc18,loc19,loc20,loc21,loc22,loc23,loc24,loc25,loc26,
      loc27,loc28,loc29,loc30,loc31,loc32;
  static float smp1,smp2,smp3,smp4,smp5,smp6,smp7,smp8,smp9,smp10,smp11,smp12,smp13,smp14,smp15,smp16,smp17,smp18,smp19,smp20,smp21,smp22,smp23,smp24,smp25,smp26,
      smp27,smp28,smp29,smp30,smp31,smp32;

  /** Compute new values via a fast cosine transform. */
  private final void compute_new_v() {
    smp1 = samples[0];
    smp2 = samples[1];
    smp3 = samples[2];
    smp4 = samples[3];
    smp5 = samples[4];
    smp6 = samples[5];
    smp7 = samples[6];
    smp8 = samples[7];
    smp9 = samples[8];
    smp10 = samples[9];
    smp11 = samples[10];
    smp12 = samples[11];
    smp13 = samples[12];
    smp14 = samples[13];
    smp15 = samples[14];
    smp16 = samples[15];
    smp17 = samples[16];
    smp18 = samples[17];
    smp19 = samples[18];
    smp20 = samples[19];
    smp21 = samples[20];
    smp22 = samples[21];
    smp23 = samples[22];
    smp24 = samples[23];
    smp25 = samples[24];
    smp26 = samples[25];
    smp27 = samples[26];
    smp28 = samples[27];
    smp29 = samples[28];
    smp30 = samples[29];
    smp31 = samples[30];
    smp32 = samples[31];
    p0 = smp1 + smp32;
    p1 = smp2 + smp31;
    p2 = smp3 + smp30;
    p3 = smp4 + smp29;
    p4 = smp5 + smp28;
    p5 = smp6 + smp27;
    p6 = smp7 + smp26;
    p7 = smp8 + smp25;
    p8 = smp9 + smp24;
    p9 = smp10 + smp23;
    p10 = smp11 + smp22;
    p11 = smp12 + smp21;
    p12 = smp13 + smp20;
    p13 = smp14 + smp19;
    p14 = smp15 + smp18;
    p15 = smp16 + smp17;
    pp0 = p0 + p15;
    pp1 = p1 + p14;
    pp2 = p2 + p13;
    pp3 = p3 + p12;
    pp4 = p4 + p11;
    pp5 = p5 + p10;
    pp6 = p6 + p9;
    pp7 = p7 + p8;
    pp8 = (p0 - p15) * cos1_32;
    pp9 = (p1 - p14) * cos3_32;
    pp10 = (p2 - p13) * cos5_32;
    pp11 = (p3 - p12) * cos7_32;
    pp12 = (p4 - p11) * cos9_32;
    pp13 = (p5 - p10) * cos11_32;
    pp14 = (p6 - p9) * cos13_32;
    pp15 = (p7 - p8) * cos15_32;
    p0 = pp0 + pp7;
    p1 = pp1 + pp6;
    p2 = pp2 + pp5;
    p3 = pp3 + pp4;
    p4 = (pp0 - pp7) * cos1_16;
    p5 = (pp1 - pp6) * cos3_16;
    p6 = (pp2 - pp5) * cos5_16;
    p7 = (pp3 - pp4) * cos7_16;
    p8 = pp8 + pp15;
    p9 = pp9 + pp14;
    p10 = pp10 + pp13;
    p11 = pp11 + pp12;
    p12 = (pp8 - pp15) * cos1_16;
    p13 = (pp9 - pp14) * cos3_16;
    p14 = (pp10 - pp13) * cos5_16;
    p15 = (pp11 - pp12) * cos7_16;
    pp0 = p0 + p3;
    pp1 = p1 + p2;
    pp2 = (p0 - p3) * cos1_8;
    pp3 = (p1 - p2) * cos3_8;
    pp4 = p4 + p7;
    pp5 = p5 + p6;
    pp6 = (p4 - p7) * cos1_8;
    pp7 = (p5 - p6) * cos3_8;
    pp8 = p8 + p11;
    pp9 = p9 + p10;
    pp10 = (p8 - p11) * cos1_8;
    pp11 = (p9 - p10) * cos3_8;
    pp12 = p12 + p15;
    pp13 = p13 + p14;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -