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().
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static class
DspThread.AlgorithmEnum
class
DspThread.DspPerformCallback
The DspPerformCallback is method called periodically at every DSP cycle.
-
Field Summary
Fields Modifier and Type Field and Description private DspThread.AlgorithmEnum
algorithm
static int
AUDIO_SOURCE_MIC
static int
AUDIO_SOURCE_WAV
private int
audioSource
(package private) AudioStream
audioStream
private int
blockSize
(package private) short[]
buffer
(package private) int
BUFFER_SIZE_IN_BLOCKS
private long
callbackTicks
private int
DEFAULT_BLOCK_SIZE
private DspAlgorithm
dspAlgorithm
private long
dspCallbackTime
private long
dspPerformTime
private long
elapsedTime
private java.io.InputStream
inputStream
(package private) int
jx
private java.util.EnumMap<DspThread.AlgorithmEnum,DspAlgorithm>
map_algorithm
private int
maxDspCycles
private double
parameter1
(package private) double[]
performBuffer
private int
sampleRate
private long
sampleWriteTime
private long
startTime
private int
state
private static int
STATE_PROCESSING
private static int
STATE_STOPPED
private static int
STATE_SUSPENDED
(package private) int
stressParameter
(package private) AudioTrack
track
-
Constructor Summary
Constructors Constructor and Description DspThread()
Creates a DSP Thread that runs for a maximum amount of cycles and a filterSize for stress testing.
-
Method Summary
Methods Modifier and Type Method and Description private void
createPerformBuffer()
Create a buffer to store audio samples.DspThread.AlgorithmEnum
getAlgorithm()
java.lang.String
getAlgorithmName()
java.lang.String
getAlgorithmNameById(DspThread.AlgorithmEnum id)
double
getBlockPeriod()
int
getBlockSize()
double
getCallbackPeriodMeanTime()
long
getCallbackTicks()
double
getDspCallbackMeanTime()
double
getDspPerformMeanTime()
double
getElapsedTime()
long
getReadTicks()
int
getSampleRate()
double
getSampleReadMeanTime()
double
getSampleWriteMeanTime()
boolean
isProcessing()
boolean
isStopped()
boolean
isSuspended()
private void
releaseIO()
Stop and release audio input and output.void
resetDsp()
Reset thread statisticsvoid
resumeDsp()
Resume audio processing.void
run()
This is called when the thread starts.private void
scheduleDspCallback()
Schedule the DSP callback.void
setAlgorithm(DspThread.AlgorithmEnum alg)
Configure the algorithm used to transform the stream given a sample rate and a block size.void
setAudioSource(int source)
Set the audio source.void
setBlockSize(int bSize)
Set the DSP block size.void
setInputStream(java.io.InputStream stream)
Set the input stream.void
setMaxDspCycles(int max)
Set the maximum number of DSP cycles this thread is allowed to run.void
setParams(double param1)
Set generic DSP parameters.void
setStressParameter(int param)
Set the stress parameter used when running stress test algorithms.private void
setupAudioStream()
Initiate audio stream either from MIC or WAV file.private void
setupAudioTrack()
Instantiate and configure the player.void
stopDspThread()
Stop the thread.void
suspendDsp()
Suspend DSP: - stop audio input.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
sampleRate
private final int sampleRate
- See Also:
- Constant Field Values
-
blockSize
private int blockSize
-
dspAlgorithm
private DspAlgorithm dspAlgorithm
-
algorithm
private DspThread.AlgorithmEnum algorithm
-
parameter1
private double parameter1
-
maxDspCycles
private int maxDspCycles
-
DEFAULT_BLOCK_SIZE
private final int DEFAULT_BLOCK_SIZE
- See Also:
- Constant Field Values
-
AUDIO_SOURCE_MIC
public static final int AUDIO_SOURCE_MIC
- See Also:
- Constant Field Values
-
AUDIO_SOURCE_WAV
public static final int AUDIO_SOURCE_WAV
- See Also:
- Constant Field Values
-
audioSource
private int audioSource
-
inputStream
private java.io.InputStream inputStream
-
track
AudioTrack track
-
buffer
short[] buffer
-
BUFFER_SIZE_IN_BLOCKS
final int BUFFER_SIZE_IN_BLOCKS
- See Also:
- Constant Field Values
-
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
-
audioStream
AudioStream audioStream
-
stressParameter
int stressParameter
-
STATE_STOPPED
private static final int STATE_STOPPED
- See Also:
- Constant Field Values
-
STATE_PROCESSING
private static final int STATE_PROCESSING
- See Also:
- Constant Field Values
-
STATE_SUSPENDED
private static final int STATE_SUSPENDED
- See Also:
- Constant Field Values
-
state
private int state
-
map_algorithm
private java.util.EnumMap<DspThread.AlgorithmEnum,DspAlgorithm> map_algorithm
-
-
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.
-
getAlgorithm
public DspThread.AlgorithmEnum getAlgorithm()
- Returns:
- The current algorithm.
-
getAlgorithmNameById
public java.lang.String getAlgorithmNameById(DspThread.AlgorithmEnum id)
-
run
public void run()
This is called when the thread starts. Runs until stopDspThread() is called.- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.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.
-
-