Ejemplo n.º 1
0
        public static short bytesToShort(AudioFormat format, byte[] byteArray)
        {
            int num = 0;

            AudioFormat.Encoding encoding = format.getEncoding();
            int frameSize = format.getFrameSize();

            if (encoding == AudioFormat.Encoding.PCM_SIGNED)
            {
                num = (int)Utils.toShort(byteArray, format.isBigEndian());
                if (frameSize == 1)
                {
                    num = (int)((short)(num << 8));
                }
            }
            else if (encoding == AudioFormat.Encoding.PCM_UNSIGNED)
            {
                int num2 = Utils.toUnsignedShort(byteArray, format.isBigEndian());
                if (frameSize == 1)
                {
                    num2 <<= 8;
                }
                num = (int)((short)(num2 - 32768));
            }
            else if (encoding == AudioFormat.Encoding.ULAW)
            {
                num = (int)Utils.ulawTable[(int)(byteArray[0] + 128)];
            }
            else
            {
                [email protected](new StringBuilder().append("Unknown encoding: ").append(encoding).toString());
            }
            return((short)num);
        }
Ejemplo n.º 2
0
 public RawWriter(OutputStream outputStream, AudioFormat audioFormat)
 {
     AudioFormat.Encoding encoding = audioFormat.getEncoding();
     this.outputStream   = outputStream;
     this.bytesPerSample = audioFormat.getSampleSizeInBits() / 8;
     if (encoding == AudioFormat.Encoding.PCM_SIGNED)
     {
         this.signedData = true;
     }
     else if (encoding == AudioFormat.Encoding.PCM_UNSIGNED)
     {
         this.signedData = false;
     }
     else
     {
         java.lang.System.err.println(new StringBuilder().append("Unsupported audio encoding: ").append(encoding).toString());
         java.lang.System.exit(-1);
     }
 }
        public virtual void setInputStream(AudioInputStream inputStream, string streamName)
        {
            this.dataStream       = inputStream;
            this.streamEndReached = false;
            this.utteranceEndSent = false;
            this.utteranceStarted = false;
            AudioFormat format = inputStream.getFormat();

            this.sampleRate = ByteCodeHelper.f2i(format.getSampleRate());
            this.bigEndian  = format.isBigEndian();
            string text = format.toString();

            this.logger.finer(new StringBuilder().append("input format is ").append(text).toString());
            bool sampleSizeInBits = format.getSampleSizeInBits() != 0;
            int  num = 8;

            if (num != -1 && (sampleSizeInBits ? 1 : 0) % num != 0)
            {
                string text2 = "StreamDataSource: bits per sample must be a multiple of 8.";

                throw new Error(text2);
            }
            this.bytesPerValue = format.getSampleSizeInBits() / 8;
            AudioFormat.Encoding encoding = format.getEncoding();
            if (encoding.equals(AudioFormat.Encoding.PCM_SIGNED))
            {
                this.signedData = true;
            }
            else
            {
                if (!encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED))
                {
                    string text3 = "used file encoding is not supported";

                    throw new RuntimeException(text3);
                }
                this.signedData = false;
            }
            this.totalValuesRead = 0L;
        }
Ejemplo n.º 4
0
        public static short[] readAudioData(InputStream audioStream, AudioFormat audioFormat)
        {
            int num = 1;

            AudioFormat.Encoding encoding = audioFormat.getEncoding();
            int num2 = audioFormat.getSampleSizeInBits() / 8;

            if (encoding == AudioFormat.Encoding.PCM_SIGNED)
            {
                num = 1;
            }
            else if (encoding == AudioFormat.Encoding.PCM_UNSIGNED)
            {
                num = 0;
            }
            else
            {
                java.lang.System.err.println(new StringBuilder().append("Unsupported audio encoding: ").append(encoding).toString());
                java.lang.System.exit(-1);
            }
            int num3 = audioFormat.isBigEndian() ? 1 : 0;

            byte[]    array     = new byte[num2];
            ArrayList arrayList = new ArrayList();
            int       num4      = 0;

            while (num4 == 0)
            {
                int i;
                int num5 = i = audioStream.read(array, 0, num2);
                while (i < num2)
                {
                    if (num5 == -1)
                    {
                        num4 = 1;
                        break;
                    }
                    num5 = audioStream.read(array, i, num2 - i);
                    i   += num5;
                }
                if (num4 == 0)
                {
                    int num6;
                    if (num3 != 0)
                    {
                        num6 = (int)array[0];
                        if (num == 0)
                        {
                            num6 &= 255;
                        }
                        for (int j = 1; j < num2; j++)
                        {
                            int num7 = (int)array[j];
                            num6 = (num6 << 8) + num7;
                        }
                    }
                    else
                    {
                        num6 = (int)array[num2 - 1];
                        if (num == 0)
                        {
                            num6 &= 255;
                        }
                        for (int j = num2 - 2; j >= 0; j--)
                        {
                            int num7 = (int)array[j];
                            num6 = (num6 << 8) + num7;
                        }
                    }
                    if (num == 0)
                    {
                        num6 -= 1 << num2 * 8 - 1;
                    }
                    arrayList.add(Short.valueOf((short)num6));
                }
            }
            short[] array2 = new short[arrayList.size()];
            for (int j = 0; j < array2.Length; j++)
            {
                array2[j] = ((Short)arrayList.get(j)).shortValue();
            }
            return(array2);
        }
Ejemplo n.º 5
0
 /// <summary>Constructs an <code>AudioFormat</code> with the given parameters.</summary>
 /// <remarks>
 /// Constructs an <code>AudioFormat</code> with the given parameters.
 /// The encoding specifies the convention used to represent the data.
 /// The other parameters are further explained in the
 /// <see cref="AudioFormat">class description</see>
 /// .
 /// </remarks>
 /// <param name="encoding">the audio encoding technique</param>
 /// <param name="sampleRate">the number of samples per second</param>
 /// <param name="sampleSizeInBits">the number of bits in each sample</param>
 /// <param name="channels">the number of channels (1 for mono, 2 for stereo, and so on)
 /// 	</param>
 /// <param name="frameSize">the number of bytes in each frame</param>
 /// <param name="frameRate">the number of frames per second</param>
 /// <param name="bigEndian">
 /// indicates whether the data for a single sample
 /// is stored in big-endian byte order (<code>false</code>
 /// means little-endian)
 /// </param>
 public AudioFormat(AudioFormat.Encoding encoding, float sampleRate, int 
     sampleSizeInBits, int channels, int frameSize, float frameRate, bool bigEndian)
 {
     // INSTANCE VARIABLES
     this.encoding = encoding;
     this.sampleRate = sampleRate;
     this.sampleSizeInBits = sampleSizeInBits;
     this.channels = channels;
     this.frameSize = frameSize;
     this.frameRate = frameRate;
     this.bigEndian = bigEndian;
     this.propertiesField = null;
 }