From 9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e Mon Sep 17 00:00:00 2001 From: Michiel Van Der Kolk Date: Mon, 11 Jul 2005 15:42:37 +0000 Subject: Songdb java version, source. only 1.5 compatible git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7101 a1c6a512-1295-4272-9138-f99709370657 --- songdbj/de/jarnbjo/vorbis/AudioPacket.java | 328 +++++++++++++++++++++++++++++ 1 file changed, 328 insertions(+) create mode 100644 songdbj/de/jarnbjo/vorbis/AudioPacket.java (limited to 'songdbj/de/jarnbjo/vorbis/AudioPacket.java') diff --git a/songdbj/de/jarnbjo/vorbis/AudioPacket.java b/songdbj/de/jarnbjo/vorbis/AudioPacket.java new file mode 100644 index 0000000000..90a54073c1 --- /dev/null +++ b/songdbj/de/jarnbjo/vorbis/AudioPacket.java @@ -0,0 +1,328 @@ +/* + * $ProjectName$ + * $ProjectRevision$ + * ----------------------------------------------------------- + * $Id$ + * ----------------------------------------------------------- + * + * $Author$ + * + * Description: + * + * Copyright 2002-2003 Tor-Einar Jarnbjo + * ----------------------------------------------------------- + * + * Change History + * ----------------------------------------------------------- + * $Log$ + * Revision 1.1 2005/07/11 15:42:36 hcl + * Songdb java version, source. only 1.5 compatible + * + * Revision 1.2 2004/09/21 06:39:06 shred + * Importe reorganisiert, damit Eclipse Ruhe gibt. ;-) + * + * Revision 1.1.1.1 2004/04/04 22:09:12 shred + * First Import + * + * Revision 1.2 2003/03/16 01:11:12 jarnbjo + * no message + * + * + */ + +package de.jarnbjo.vorbis; + +import java.io.IOException; + +import de.jarnbjo.util.io.BitInputStream; + +class AudioPacket { + + private int modeNumber; + private Mode mode; + private Mapping mapping; + private int n; // block size + private boolean blockFlag, previousWindowFlag, nextWindowFlag; + + private int windowCenter, leftWindowStart, leftWindowEnd, leftN, rightWindowStart, rightWindowEnd, rightN; + private float[] window; + private float[][] pcm; + private int[][] pcmInt; + + private Floor[] channelFloors; + private boolean[] noResidues; + + private final static float[][] windows=new float[8][]; + + protected AudioPacket(final VorbisStream vorbis, final BitInputStream source) throws VorbisFormatException, IOException { + + final SetupHeader sHeader=vorbis.getSetupHeader(); + final IdentificationHeader iHeader=vorbis.getIdentificationHeader(); + final Mode[] modes=sHeader.getModes(); + final Mapping[] mappings=sHeader.getMappings(); + final Residue[] residues=sHeader.getResidues(); + final int channels=iHeader.getChannels(); + + if(source.getInt(1)!=0) { + throw new VorbisFormatException("Packet type mismatch when trying to create an audio packet."); + } + + modeNumber=source.getInt(Util.ilog(modes.length-1)); + + try { + mode=modes[modeNumber]; + } + catch(ArrayIndexOutOfBoundsException e) { + throw new VorbisFormatException("Reference to invalid mode in audio packet."); + } + + mapping=mappings[mode.getMapping()]; + + final int[] magnitudes=mapping.getMagnitudes(); + final int[] angles=mapping.getAngles(); + + blockFlag=mode.getBlockFlag(); + + final int blockSize0=iHeader.getBlockSize0(); + final int blockSize1=iHeader.getBlockSize1(); + + n=blockFlag?blockSize1:blockSize0; + + if(blockFlag) { + previousWindowFlag=source.getBit(); + nextWindowFlag=source.getBit(); + } + + windowCenter=n/2; + + if(blockFlag && !previousWindowFlag) { + leftWindowStart=n/4-blockSize0/4; + leftWindowEnd=n/4+blockSize0/4; + leftN=blockSize0/2; + } + else { + leftWindowStart=0; + leftWindowEnd=n/2; + leftN=windowCenter; + } + + if(blockFlag && !nextWindowFlag) { + rightWindowStart=n*3/4-blockSize0/4; + rightWindowEnd=n*3/4+blockSize0/4; + rightN=blockSize0/2; + } + else { + rightWindowStart=windowCenter; + rightWindowEnd=n; + rightN=n/2; + } + + window=getComputedWindow();//new double[n]; + + channelFloors=new Floor[channels]; + noResidues=new boolean[channels]; + + pcm=new float[channels][n]; + pcmInt=new int[channels][n]; + + boolean allFloorsEmpty=true; + + for(int i=0; i=0; i--) { + double newA=0, newM=0; + final float[] magnitudeVector=pcm[magnitudes[i]]; + final float[] angleVector=pcm[angles[i]]; + for(int j=0; j0) { + //magnitudeVector[j]=m; + angleVector[j]=m>0?m-a:m+a; + } + else { + magnitudeVector[j]=m>0?m+a:m-a; + angleVector[j]=m; + } + } + } + + for(int i=0; i32767) val=32767; + if(val<-32768) val=-32768; + target[j1++]=val; + } + } + + // use System.arraycopy to copy the middle part (if any) + // of the window + if(leftWindowEnd+132767) val=32767; + if(val<-32768) val=-32768; + buffer[ix+(i*2)+1]=(byte)(val&0xff); + buffer[ix+(i*2)]=(byte)((val>>8)&0xff); + ix+=channels*2; + } + + ix=(leftWindowEnd-leftWindowStart)*channels*2; + for(int j=leftWindowEnd; j32767) val=32767; + if(val<-32768) val=-32768; + buffer[ix+(i*2)+1]=(byte)(val&0xff); + buffer[ix+(i*2)]=(byte)((val>>8)&0xff); + ix+=channels*2; + } + } + } + + protected float[] getWindow() { + return window; + } + + protected int getLeftWindowStart() { + return leftWindowStart; + } + + protected int getLeftWindowEnd() { + return leftWindowEnd; + } + + protected int getRightWindowStart() { + return rightWindowStart; + } + + protected int getRightWindowEnd() { + return rightWindowEnd; + } + + public int[][] getPcm() { + return pcmInt; + } + + public float[][] getFreqencyDomain() { + return pcm; + } +} -- cgit v1.2.3