If you think the Android project voicesmith listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Voicesmith <http://voicesmith.jurihock.de/>
*//www.java2s.com
* Copyright (c) 2011-2014 Juergen Hock
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/package de.jurihock.voicesmith.threads;
import android.content.Context;
import de.jurihock.voicesmith.AAF;
import de.jurihock.voicesmith.DAFX;
import de.jurihock.voicesmith.Disposable;
import de.jurihock.voicesmith.Utils;
import de.jurihock.voicesmith.io.AudioDevice;
publicabstractclass AudioThread implements Runnable, Disposable
{
protectedfinal Context context;
protectedfinal AudioDevice input, output;
private Thread thread = null;
public AudioThread(Context context, AudioDevice input, AudioDevice output)
{
this.context = context;
this.input = input;
this.output = output;
}
publicvoid configure(String value)
{
// ReentrantLock lock = new ReentrantLock(true);
// lock.lock();
// try { ... } finally { lock.unlock(); }
}
publicvoid dispose()
{
stop();
new Utils(context).log("Disposing an audio thread.");
}
publicboolean isRunning()
{
return (thread != null)
&& (thread.getState() != Thread.State.TERMINATED);
}
publicvoid start()
{
if (isRunning()) return;
thread = new Thread(this);
thread.start();
}
publicvoid stop()
{
if (!isRunning()) return;
thread.interrupt();
try
{
thread.join();
}
catch (InterruptedException exception)
{
new Utils(context).log(exception);
}
finally
{
thread = null;
}
}
publicvoid run()
{
android.os.Process.setThreadPriority(
android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
output.start();
input.start();
doProcessing();
input.stop();
output.stop();
}
protectedabstractvoid doProcessing();
publicstatic AudioThread create(Context context, AudioDevice input, AudioDevice output, DAFX dafx)
{
switch (dafx)
{
case Robotize:
returnnew RobotizeThread(context, input, output);
case Transpose:
returnnew TransposeThread(context, input, output);
case Detune:
returnnew DetuneThread(context, input, output);
case Hoarseness:
returnnew HoarsenessThread(context, input, output);
default:
thrownew IllegalArgumentException("Illegal DAFX argument!");
}
}
publicstatic AudioThread create(Context context, AudioDevice input, AudioDevice output, AAF aaf)
{
switch (aaf)
{
case FAF:
returnnew TransposeThread(context, input, output);
case DAF:
returnnew DelayThread(context, input, output);
case UnprocessedFeedback:
returnnew LowDelayThread(context, input, output);
default:
thrownew IllegalArgumentException("Illegal AAF argument!");
}
}
}