Example #1
0
        private static short[] getRecordedAudio(Microphone microphone)
        {
            short[] array = new short[0];
            int     num   = 8000;

            while (microphone.hasMoreData())
            {
                try
                {
                    Data data = microphone.getData();
                    if (data is DoubleData)
                    {
                        num = ((DoubleData)data).getSampleRate();
                        double[] values = ((DoubleData)data).getValues();
                        short[]  array2 = Arrays.copyOf(array, array.Length + values.Length);
                        for (int i = 0; i < values.Length; i++)
                        {
                            array2[array.Length + i] = (short)ByteCodeHelper.d2i(values[i]);
                        }
                        array = array2;
                    }
                }
                catch (System.Exception ex)
                {
                    Throwable.instancehelper_printStackTrace(ex);
                }
                continue;
            }
            if (num > 8000)
            {
                [email protected](new StringBuilder().append("Downsampling from ").append(num).append(" to 8000.").toString());
                array = Downsampler.downsample(array, num / 1000, 16);
            }
            return(array);
        }
        public virtual short[] stop()
        {
            object obj;

            System.Threading.Monitor.Enter(obj = this.@lock);
            short[]     array3;
            IOException ex2;

            try
            {
                if (this.recorder != null)
                {
                    ByteArrayOutputStream byteArrayOutputStream = this.recorder.stopRecording();
                    this.microphone.close();
                    this.recorder = null;
                    byte[] array = byteArrayOutputStream.toByteArray();
                    ByteArrayInputStream audioStream = new ByteArrayInputStream(array);
                    try
                    {
                        short[] array2 = RawReader.readAudioData(audioStream, this.inFormat);
                        if (this.downsample)
                        {
                            array2 = Downsampler.downsample(array2, ByteCodeHelper.f2i(this.inFormat.getSampleRate() / 1000f), ByteCodeHelper.f2i(this.outFormat.getSampleRate() / 1000f));
                        }
                        array3 = array2;
                    }
                    catch (IOException ex)
                    {
                        ex2 = ex;
                        goto IL_CA;
                    }
                    short[] result = array3;
                    System.Threading.Monitor.Exit(obj);
                    return(result);
                }
                short[] array4 = new short[0];
                System.Threading.Monitor.Exit(obj);
                array3 = array4;
            }
            catch
            {
                System.Threading.Monitor.Exit(obj);
                throw;
            }
            return(array3);

IL_CA:
            IOException ex3 = ex2;

            short[] result2;
            try
            {
                IOException ex4 = ex3;
                Throwable.instancehelper_printStackTrace(ex4);
                result2 = new short[0];
            }
            finally
            {
                System.Threading.Monitor.Exit(obj);
            }
            return(result2);
        }