DspThread
JavaScript is disabled on your browser.

br.usp.ime.dspbenchmarking.threads

Class DspThread

  • java.lang.Object
    • java.lang.Thread
      • br.usp.ime.dspbenchmarking.threads.DspThread
  • All Implemented Interfaces:
    java.lang.Runnable


    public class DspThread
    extends java.lang.Thread
    The thread that controls and performs DSP. It is responsible for: - I/O instantiation and release. - DSP parameters control. - Processing audio blocks. The thread is started in STATE_SUSPENDED state and resumeDsp() has to be called to start processing. The method suspendDsp() may be called to stop processing (and release I/O stuff). To kill the thread, use stopDspThread().
    • Field Detail

      • blockSize

        private int blockSize
      • parameter1

        private double parameter1
      • maxDspCycles

        private int maxDspCycles
      • audioSource

        private int audioSource
      • inputStream

        private java.io.InputStream inputStream
      • track

        AudioTrack track
      • buffer

        short[] buffer
      • jx

        int jx
      • performBuffer

        double[] performBuffer
      • sampleWriteTime

        private long sampleWriteTime
      • dspPerformTime

        private long dspPerformTime
      • dspCallbackTime

        private long dspCallbackTime
      • callbackTicks

        private long callbackTicks
      • elapsedTime

        private long elapsedTime
      • startTime

        private long startTime
      • stressParameter

        int stressParameter
      • state

        private int state
    • Constructor Detail

      • DspThread

        public DspThread()
        Creates a DSP Thread that runs for a maximum amount of cycles and a filterSize for stress testing.
    • Method Detail

      • setupAudioStream

        private void setupAudioStream()
        Initiate audio stream either from MIC or WAV file.
      • scheduleDspCallback

        private void scheduleDspCallback()
        Schedule the DSP callback.
      • resetDsp

        public void resetDsp()
        Reset thread statistics
      • setupAudioTrack

        private void setupAudioTrack()
        Instantiate and configure the player.
      • setInputStream

        public void setInputStream(java.io.InputStream stream)
        Set the input stream.
        Parameters:
        stream -
      • setAudioSource

        public void setAudioSource(int source)
        Set the audio source.
        Parameters:
        source -
      • setMaxDspCycles

        public void setMaxDspCycles(int max)
        Set the maximum number of DSP cycles this thread is allowed to run. After that, the thread becomes suspended.
        Parameters:
        max -
      • setAlgorithm

        public void setAlgorithm(DspThread.AlgorithmEnum alg)
        Configure the algorithm used to transform the stream given a sample rate and a block size. The algorithm order must be the same as the one in 'res/values/strings.xml': 0. Loopback. 1. Reverb. 2. FftAlgorithm. 3. PhaseVocoder. 4. StressAlgorithm. 5. Additive Synthesis. 8. FFTW monothread. 9. FFTW multithread.
        Parameters:
        alg - The number of the algorithm.
      • getAlgorithmName

        public java.lang.String getAlgorithmName()
        Returns:
        The name of the current algorithm.
      • setStressParameter

        public void setStressParameter(int param)
        Set the stress parameter used when running stress test algorithms. Will also set the parameter in the algorithm in case it is of the correct type.
        Parameters:
        param -
      • setBlockSize

        public void setBlockSize(int bSize)
        Set the DSP block size.
        Parameters:
        bSize -
      • setParams

        public void setParams(double param1)
        Set generic DSP parameters. These parameters are set either by the user or by automated tests and can be used by DSP algorithms as parameters such as filter size, gain, feedback param, etc. For now, there's just one param (which comes from a slider in 'res/layout/dsp.xml' view), but more can be added.
        Parameters:
        param1 -
      • getSampleReadMeanTime

        public double getSampleReadMeanTime()
        Returns:
        The mean time of sample reads from input.
      • getSampleWriteMeanTime

        public double getSampleWriteMeanTime()
        Returns:
        The mean time of sample write to output.
      • getDspPerformMeanTime

        public double getDspPerformMeanTime()
        Returns:
        The mean DSP perform callback mean time.
      • getDspCallbackMeanTime

        public double getDspCallbackMeanTime()
        Returns:
        The DSP callback mean time.
      • getSampleRate

        public int getSampleRate()
        Returns:
        The DSP sample rate.
      • getBlockSize

        public int getBlockSize()
        Returns:
        The DSP block size.
      • getCallbackPeriodMeanTime

        public double getCallbackPeriodMeanTime()
        Returns:
        The callback period mean time.
      • getReadTicks

        public long getReadTicks()
        Returns:
        The amount of blocks read from input.
      • getCallbackTicks

        public long getCallbackTicks()
        Returns:
        The amount of times the DSP callback was executed.
      • getBlockPeriod

        public double getBlockPeriod()
        Returns:
        The block period in milliseconds.
      • getElapsedTime

        public double getElapsedTime()
        Returns:
        The elapsed time since DSP was first started.
      • run

        public void run()
        This is called when the thread starts. Runs until stopDspThread() is called.
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
      • createPerformBuffer

        private void createPerformBuffer()
        Create a buffer to store audio samples.
      • releaseIO

        private void releaseIO()
        Stop and release audio input and output.
      • stopDspThread

        public void stopDspThread()
        Stop the thread.
      • suspendDsp

        public void suspendDsp()
        Suspend DSP: - stop audio input. - stop audio output.
      • resumeDsp

        public void resumeDsp()
        Resume audio processing.
      • isProcessing

        public boolean isProcessing()
        Returns:
        Whether audio processing is enabled.
      • isSuspended

        public boolean isSuspended()
        Returns:
        Whether DSP is suspended.
      • isStopped

        public boolean isStopped()
        Returns:
        Whether DPS is stopped.