Package com.meapsoft

Examples of com.meapsoft.FeatChunk


    double highBoundMult = highBound * 2;

    Vector featChunks = new Vector(featFile.chunks);

    //find chunks that fall in divisions or multiples of mode.
    FeatChunk tempFeatChunk;
    double tempFeatLen;
    Vector modeChunks = new Vector();
    Vector multModeChunks = new Vector();
    Vector divModeChunks = new Vector();
    Vector div2ModeChunks = new Vector();

   
    for (int i=0; i < featChunks.size(); i++)
    {
      tempFeatChunk = (FeatChunk)featChunks.get(i);
      tempFeatLen = Math.floor(tempFeatChunk.length * samplingRate);

      if (lowBoundDiv2 < tempFeatLen && tempFeatLen < highBoundDiv2)
      {
        div2ModeChunks.add(featChunks.get(i));
        //System.out.println(" found a div2 in chunk" + i);
      }
      else if (lowBoundDiv < tempFeatLen && tempFeatLen < highBoundDiv)
      {
        divModeChunks.add(featChunks.get(i));
        //System.out.println(" found a div in chunk" + i);
      }
      else if (lowBoundMult < tempFeatLen && tempFeatLen < highBoundMult)
      {
        multModeChunks.add(featChunks.get(i));
        //System.out.println(" found a mult in chunk" + i);
      }
      else if (lowBound < tempFeatLen && tempFeatLen < highBound)
      {
        modeChunks.add(featChunks.get(i));
        //System.out.println(" found a mode in chunk" + i);
      }
    }
   
   
    Vector outChunks = new Vector();
   
   
    Random rand = new Random();
    int index;
    for (int i=0; i < newPieceLength; i++)
    {
      index  = rand.nextInt(16);
      if (0 <= index && index < 4)
      {
        if (div2ModeChunks.size() > 0)
        {
          outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
          outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
          outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
          outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
          outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
          outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
          outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
          outChunks.add(div2ModeChunks.get(rand.nextInt(div2ModeChunks.size())));
          //System.out.println("Wrote 8 mode / 4 chunks");

        }
      }
      else if (4 <= index && index < 6)
      {
        if (divModeChunks.size() > 0)
        {
          outChunks.add(divModeChunks.get(rand.nextInt(divModeChunks.size())));
          outChunks.add(divModeChunks.get(rand.nextInt(divModeChunks.size())));
          outChunks.add(divModeChunks.get(rand.nextInt(divModeChunks.size())));
          outChunks.add(divModeChunks.get(rand.nextInt(divModeChunks.size())));
          //System.out.println("Wrote 4 mode / 2 chunks");
        }
      }
      else if (6 <= index && index < 14)
      {
        if (modeChunks.size() > 0)
        {
          outChunks.add(modeChunks.get(rand.nextInt(modeChunks.size())));
          outChunks.add(modeChunks.get(rand.nextInt(modeChunks.size())));
          //System.out.println("Wrote 2 mode chunks");
        }
      }
      else if (14 <= index )
      {
        if (multModeChunks.size() > 0)
        {
          outChunks.add(multModeChunks.get(rand.nextInt(multModeChunks.size())));
          //System.out.println("Wrote 1 mode * 2 chunk");
        }
      }
     
            progress.setValue(progress.getValue()+1)
    }
   
 
        double currTime = 0;
        while(outChunks.size() > 0)
        {
            FeatChunk match = (FeatChunk)outChunks.remove(0);
           
            // turn match chunk into an EDL chunk
            EDLChunk nc = new EDLChunk(match, currTime);

            if(debug)
            {
        NumberFormat fmt = NumberFormat.getInstance();
        fmt.setMaximumFractionDigits(3);
                nc.comment = "    # feats = ";
                double[] feat = match.getFeatures();
                for(int x = 0; x < feat.length-1; x++)
                    nc.comment += fmt.format(feat[x]) + ", ";
                nc.comment += fmt.format(feat[feat.length-1]);
            }

View Full Code Here


            }
        }
        else
            maxdim = ((FeatChunk)featFile.chunks.get(0)).numFeatures();
       
        FeatChunk targetChunk = new FeatChunk("",0,0);
        for(int i = 0; i <= maxdim; i++)
            //targetChunk.addFeature(0);
            targetChunk.addFeature(Integer.MIN_VALUE);
       
        dist.setTarget(targetChunk);
       
        // maintain a set of chunks sorted using dist from targetChunk
        Heap chunks = null;
        if(reverseSort)
            chunks = new MaxHeap(dist);
        else
            chunks = new MinHeap(dist);
        chunks.addAll(featFile.chunks);
       
        NumberFormat fmt = NumberFormat.getInstance();
        fmt.setMaximumFractionDigits(3);
       
        double currTime = 0;
        while(chunks.size() > 0)
        {
            FeatChunk match = (FeatChunk)chunks.remove(0);

            // turn match chunk into an EDL chunk
            EDLChunk nc = new EDLChunk(match, currTime);

            if(debug)
            {
                nc.comment = "    # feats = ";
                double[] feat = match.getFeatures(featdim);
                for(int x = 0; x < feat.length-1; x++)
                    nc.comment += fmt.format(feat[x]) + ", ";
                nc.comment += fmt.format(feat[feat.length-1]);
            }
View Full Code Here

    // System.out.println("localStartBeat: " + localStartBeat);

    for (int measure = 0; measure < totalChunks / beatsPerMeasure; measure++)
    {
      FeatChunk chunks[] = new FeatChunk[beatsPerMeasure];
      // int numBeatsFound = 0;

      for (int i = 0; i < beatsPerMeasure; i++)
        chunks[i] = (FeatChunk) c.next();
View Full Code Here

    for (int i = 0; i < numChunks; i++)
    {
      for (int j = 0; j < featureSize; j++)
      {
        FeatChunk fC = (FeatChunk) events.get(i);

        if (fC.startTime < firstEventTime)
          firstEventTime = fC.startTime;

        if (fC.startTime > lastEventTime)
View Full Code Here

    updating = true;

    double zoomMulti = (zoomLevel * 4.0) / 4.0;
    int w = (int) (this.getWidth() * zoomMulti) - 1;
    FeatChunk fCTD = (FeatChunk) events.get(firstChunkToDraw);
    double localFirstEventTime = fCTD.startTime;

    AudioReader reader = null;

    // don't need hirez data for display...
    AudioFormat format = new AudioFormat(8000, 16, 1, MEAPUtil.signed,
        MEAPUtil.bigEndian);

    try
    {
      //reader = new AudioReader(fCTD.srcFile, format);
            reader = AudioReaderFactory.getAudioReader(fCTD.srcFile, format);
    }
    catch (IOException e1)
    {
      e1.printStackTrace();
      return;
    }
    catch (UnsupportedAudioFileException e1)
    {
      e1.printStackTrace();
      return;
    }

    int frameSize = format.getFrameSize();
    double frameRate = (double) format.getFrameRate();

    long fileFrameLength = reader.getFrameLength();
    double fileTimeLength = ((double) fileFrameLength / frameRate);//  / frameSize;

    int framesPerPixel = (int) Math.ceil((double) fileFrameLength
        / (double) w);
    double timePerPixel = ((double) framesPerPixel / frameRate);// / frameSize;

    firstEventTime = localFirstEventTime;
    timeRange = fileTimeLength - localFirstEventTime;

    //System.out.println("spectrum seyz: timeRange: " + timeRange + " fileTL: " + fileTimeLength +
    //    " firstET: " + firstEventTime);
   
    //System.out.println("spectrum seyz: frameSize: " + frameSize + " frameRate: " + frameRate +
      //  " fileFrameLength: " + fileFrameLength + " fileTimeLength: " + fileTimeLength +
      //  " framesPerPixel: " + framesPerPixel + " timePerPixel: " + timePerPixel + " w: " + w);
   
    FeatFile fF = new FeatFile("small_chunks_temp.feat");

    double currTime = localFirstEventTime;
    String srcFileName = fCTD.srcFile;

    for (int x = 0; x < w; x++)
    {
      FeatChunk fC = new FeatChunk(srcFileName, currTime, timePerPixel, null);
      fF.chunks.add(fC);
      currTime += timePerPixel;
    }

    try
    {
      fF.writeFile();
    }
    catch (IOException e1)
    {
      e1.printStackTrace();
    }

    Vector extractors = new Vector();
    extractors.add(new AvgMelSpec());

    FeatFile spectrumFeats = new FeatFile("temp.feat");

    FeatExtractor fE = new FeatExtractor(fF, spectrumFeats, extractors);

    fE.setProgress(progress);

    try
    {
      fE.setup();
      fE.processFeatFiles();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }

    int elementsPerFeature[] = { 0 };

    elementsPerFeature = spectrumFeats.getFeatureLengths();
    featureSize = elementsPerFeature[0];

    featureNumber = 0;

    shortEvents = spectrumFeats.chunks;
    numShortChunks = shortEvents.size();

    for (int i = 0; i < numShortChunks; i++)
    {
      for (int j = 0; j < featureSize; j++)
      {
        FeatChunk fC = (FeatChunk) shortEvents.get(i);
        int[] dim = { featureNumber + j };
        double feature = fC.getFeatures(dim)[0];

        if (feature < lowestValue)
          lowestValue = feature;

        if (feature > highestValue)
View Full Code Here

      //  " xScaler: " + xScaler + " yIncr: " + yIncr);

    int x = 0;
    for (int i = firstChunkToDraw; i < numShortChunks && x < getWidth(); i++)
    {
      FeatChunk fC = (FeatChunk) shortEvents.get(i);
      x = (int) ((fC.startTime - localFirstEventTime) * xScaler);
      int width = (int) (fC.length * xScaler) + 1;

      //System.out.println("spectrum: x: " + x);
      // adjust to zero
      double dataPoints[] = fC.getFeatures();// featureData[i];
      // System.out.println("dataPoints.length: " + dataPoints.length);

      for (int j = 1; j < featureSize + 1; j++)
      {
        double dataPoint = dataPoints[j - 1] - lowestValue;
View Full Code Here

    // iterate through all the chunks that the segmenter found
    while (c.hasNext())
    {
      // your current features chunk
      FeatChunk ch = (FeatChunk) c.next();

      double[] feats = ch.getFeatures();

      // System.out.println("feature[0]: " + feats[0]);
      // System.out.println("insideThreshold: " + insideThreshold + "
      // thresholdBottom: " + thresholdBottom +
      // " thresholdTop: " + thresholdTop);
View Full Code Here

        // beatsPerCodeword chunk into one a superchunk.
        Vector newChunks = new Vector();
        for(int x = 0; x < trainFile.chunks.size()-beatsPerCodeword+1;
            x += beatsPerCodeword)
        {
            FeatChunk newChunk =
                (FeatChunk)((FeatChunk)trainFile.chunks.get(x)).clone();

            double length = 0;
            for(int y = 1; y < beatsPerCodeword; y++)
            {
                FeatChunk f = (FeatChunk)trainFile.chunks.get(x+y);
               
                newChunk.addFeature(f.getFeatures());
                newChunk.length += f.length;
            }
           
            newChunks.add(newChunk);
        }

        trainFile.chunks = newChunks;

        progress.setMaximum(trainFile.chunks.size());

    if(featsToQuantize != null)
        {
            if(!featsToQuantize.haveReadFile)
                featsToQuantize.readFile();


            // What if features don't match
            if(!featsToQuantize.isCompatibleWith(trainFile))
                throw new ParserException(trainFile.filename,
                                      "Features do not match those in "
                                          + featsToQuantize.filename);
           
            featsToQuantize = (FeatFile)featsToQuantize.clone();
            featsToQuantize.normalizeFeatures();
            featsToQuantize.applyFeatureWeights();

            // To change the number of beats per state all we have to do
            // is modify the chunks in featFile by joining every
            // beatsPerCodeword chunk into one a superchunk.
            newChunks = new Vector();
            for(int x = 0;
                x < featsToQuantize.chunks.size()-beatsPerCodeword+1;
                x += beatsPerCodeword)
            {
                FeatChunk newChunk =
                    (FeatChunk)((FeatChunk)featsToQuantize.chunks.get(x)).clone();
               
                double length = 0;
                for(int y = 1; y < beatsPerCodeword; y++)
                {
                    FeatChunk f = (FeatChunk)featsToQuantize.chunks.get(x+y);
                   
                    newChunk.addFeature(f.getFeatures());
                    newChunk.length += f.length;
                }
               
                newChunks.add(newChunk);
            }
View Full Code Here

        // initial codebook:
        templateChunks = new Vector(cbSize);
       
        // create a placeholder template chunk
        FeatChunk template0 = new FeatChunk("templateChunk0", 0, 0);
        template0.setFeatures(DSP.mean(DSP.transpose(features)));
        templateChunks.add(template0);

        // distortions of between each codeword and each chunk
        double[][] distortion = new double[cbSize][ndat];
        for(int x = 0; x < distortion.length; x++)
            Arrays.fill(distortion[x], Double.MAX_VALUE);
        // indicies into cbMeans for each chunk
        int[] idx = new int[ndat];

        // how much should the means be nudged when splitting
        double delta = 1e-3;

        // start from one codeword and go from there
        for(int nValidCW = 2; nValidCW <= cbSize;
            nValidCW = Math.min(2*nValidCW, cbSize))
        {
            if(debug)
                System.out.println("Splitting into "+nValidCW+" codewords.");

            // split codewords
            for(int c = 0; c < nValidCW; c += 2)
            {
                FeatChunk ch = (FeatChunk)templateChunks.get(c);
                ch.setFeatures(DSP.minus(ch.getFeatures(), delta));
                templateChunks.set(c, ch);

                FeatChunk newch = new FeatChunk("templateChunk"+c, 0, 0);
                newch.setFeatures(DSP.plus(ch.getFeatures(), delta));
                templateChunks.add(c+1, newch);
            }

            double currTotalDist = 0;
            double prevTotalDist = Double.MAX_VALUE;
            do
            {
                prevTotalDist = currTotalDist;
                currTotalDist = 0;
                for(int c = 0; c < nValidCW; c++)
                {
                    FeatChunk cw = (FeatChunk)templateChunks.get(c);
                    for(int n = 0; n < ndat; n++)
                    {
                        FeatChunk ch = (FeatChunk)trainFile.chunks.get(n);
                        distortion[c][n] = dist.distance(cw, ch);
                        currTotalDist += distortion[c][n];
                    }
                }

                // quantize
                for(int n = 0; n < ndat; n++)
                    idx[n] = DSP.argmin(DSP.getColumn(distortion, n));

                // update means
                double[] newCW = new double[ndim];
                for(int c = 0; c < nValidCW; c++)
                {
                    FeatChunk ch = (FeatChunk)templateChunks.get(c);
                    Arrays.fill(newCW, 0);
                    int nmatch = 0;
                    for(int n = 0; n < ndat; n++)
                    {
                        if(idx[n] == c)
                        {
                            nmatch++;
                          
                            for(int i = 0; i < ndim; i++)
                                newCW[i] += features[n][i];
                        }
                    }

                    if(nmatch != 0)
                        ch.setFeatures(DSP.rdivide(newCW, nmatch));
                }
                if(debug)
                    System.out.println("  distortion = "
                                       + Math.abs(currTotalDist-prevTotalDist));
            } while(Math.abs(currTotalDist - prevTotalDist) > 0.0);
View Full Code Here

    {
        double minDist = Double.MAX_VALUE;
        int match = -1;
        for(int c = 0; c < templateChunks.size(); c++)
        {
            FeatChunk chunk = (FeatChunk)templateChunks.get(c);

            double d = dist.distance(chunk, f);
           
            if(d < minDist)
            {
View Full Code Here

TOP

Related Classes of com.meapsoft.FeatChunk

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.