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 classDspThread.AlgorithmEnumclassDspThread.DspPerformCallbackThe DspPerformCallback is method called periodically at every DSP cycle.
-
Field Summary
Fields Modifier and Type Field and Description private DspThread.AlgorithmEnumalgorithmstatic intAUDIO_SOURCE_MICstatic intAUDIO_SOURCE_WAVprivate intaudioSource(package private) AudioStreamaudioStreamprivate intblockSize(package private) short[]buffer(package private) intBUFFER_SIZE_IN_BLOCKSprivate longcallbackTicksprivate intDEFAULT_BLOCK_SIZEprivate DspAlgorithmdspAlgorithmprivate longdspCallbackTimeprivate longdspPerformTimeprivate longelapsedTimeprivate java.io.InputStreaminputStream(package private) intjxprivate java.util.EnumMap<DspThread.AlgorithmEnum,DspAlgorithm>map_algorithmprivate intmaxDspCyclesprivate doubleparameter1(package private) double[]performBufferprivate intsampleRateprivate longsampleWriteTimeprivate longstartTimeprivate intstateprivate static intSTATE_PROCESSINGprivate static intSTATE_STOPPEDprivate static intSTATE_SUSPENDED(package private) intstressParameter(package private) AudioTracktrack
-
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 voidcreatePerformBuffer()Create a buffer to store audio samples.DspThread.AlgorithmEnumgetAlgorithm()java.lang.StringgetAlgorithmName()java.lang.StringgetAlgorithmNameById(DspThread.AlgorithmEnum id)doublegetBlockPeriod()intgetBlockSize()doublegetCallbackPeriodMeanTime()longgetCallbackTicks()doublegetDspCallbackMeanTime()doublegetDspPerformMeanTime()doublegetElapsedTime()longgetReadTicks()intgetSampleRate()doublegetSampleReadMeanTime()doublegetSampleWriteMeanTime()booleanisProcessing()booleanisStopped()booleanisSuspended()private voidreleaseIO()Stop and release audio input and output.voidresetDsp()Reset thread statisticsvoidresumeDsp()Resume audio processing.voidrun()This is called when the thread starts.private voidscheduleDspCallback()Schedule the DSP callback.voidsetAlgorithm(DspThread.AlgorithmEnum alg)Configure the algorithm used to transform the stream given a sample rate and a block size.voidsetAudioSource(int source)Set the audio source.voidsetBlockSize(int bSize)Set the DSP block size.voidsetInputStream(java.io.InputStream stream)Set the input stream.voidsetMaxDspCycles(int max)Set the maximum number of DSP cycles this thread is allowed to run.voidsetParams(double param1)Set generic DSP parameters.voidsetStressParameter(int param)Set the stress parameter used when running stress test algorithms.private voidsetupAudioStream()Initiate audio stream either from MIC or WAV file.private voidsetupAudioTrack()Instantiate and configure the player.voidstopDspThread()Stop the thread.voidsuspendDsp()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:
runin interfacejava.lang.Runnable- Overrides:
runin 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.
-
-