Commit f4464a6d authored by Oliver Adams's avatar Oliver Adams

More javadoccing, changed the scope of some exceptions, added some Toasts

parent 4fb97f3a
......@@ -33,24 +33,35 @@ public class Mapper {
private Long originalEndOfSegment;
private Long respeakingStartOfSegment = 0L;
private Long respeakingEndOfSegment;
/** The mapping file */
private File mappingFile;
/**
* Constructor
*
* @param uuid The UUID of the respeaking.
*/
public Mapper(UUID uuid) {
this.segments = new Segments();
this.mappingFile = new File(Recording.getRecordingsPath(), uuid + ".map");
}
// TODO Does this need to store, also?
public void stop() {
try {
segments.write(mappingFile);
} catch (IOException e) {
// Couldn't write mapping. Oh well!
}
/**
* Stops and writes the segments to file.
*
* @throws IOException If the segments couldn't be written.
*/
public void stop() throws IOException {
segments.write(mappingFile);
}
/**
* Gets the first sample of the original segment.
*
* @return The start of the original segment; or 0L if there is none.
*/
public Long getOriginalStartSample() {
if (originalStartOfSegment != null) {
return originalStartOfSegment;
......@@ -58,7 +69,12 @@ public class Mapper {
return 0L;
}
}
/**
* Marks the start of an original segment.
*
* @param original The source of the original segments.
*/
public void markOriginal(Sampler original) {
// If we have already specified an end of the segment then we're
// starting a new one. Otherwise just continue with the old
......@@ -67,15 +83,28 @@ public class Mapper {
originalStartOfSegment = original.getCurrentSample();
}
}
/**
* Marks the end of an original segment and the start of a respeaking segment.
*
* @param original The source of the original segments.
* @param respoken The source of the respoken segments.
*/
public void markRespeaking(Sampler original, Sampler respoken) {
originalEndOfSegment = original.getCurrentSample();
respeakingStartOfSegment = respoken.getCurrentSample();
}
/** Returns true if a segment gets stored; false otherwise. A segment may
* not be stored if there hasn't been an end to the current original
* segment. */
/**
* Stores a segment determined by the samplers current locations.
*
* A segment may not be stored if there hasn't been an end to the current
* original segment.
*
* @param original The source of the original segments.
* @param respoken The source of the respoken segments.
* @return Returns true if a segment gets stored; false otherwise.
*/
public boolean store(Sampler original, Sampler respoken) {
//If we're not respeaking and still playing an original segment, do
//nothing
......
......@@ -32,8 +32,11 @@ import java.util.Set;
public class Microphone {
/**
* Constructor
*
* @param sampleRate The sample rate at which the audio should be
* recorded
* @throws MicException If the microphone couldn't be set up.
*/
public Microphone(long sampleRate) throws MicException {
physicalMicrophone = getListener(
......@@ -82,18 +85,25 @@ public class Microphone {
return false;
}
}
/**
* Releases the physical microphone.
*/
public void release() {
physicalMicrophone.release();
}
/** Accessors for sample rate, audio format channel configuration */
public int getSampleRate() { return physicalMicrophone.getSampleRate(); }
public int getAudioFormat() { return physicalMicrophone.getAudioFormat(); }
public int getChannelConfiguration() {
return physicalMicrophone.getChannelConfiguration();
}
/** Start listening. */
/**
* Start listening.
*
* @param callback The callback to hand audio buffers to.
*/
public void listen(final MicrophoneListener callback) {
// If there is already a thread listening then kill it and ensure it's
// dead before creating a new thread.
......@@ -112,7 +122,11 @@ public class Microphone {
t.start();
}
/** Stop listening to the microphone. */
/**
* Stop listening to the microphone.
*
* @throws MicException If there is a problem stopping the microphone.
*/
public void stop() throws MicException {
physicalMicrophone.stop();
if (physicalMicrophone.getState() != AudioRecord.RECORDSTATE_STOPPED) {
......@@ -124,6 +138,11 @@ public class Microphone {
* The exception class used when initialization or stopping fails.
*/
public static class MicException extends Exception {
/**
* Constructor
*
* @param message The exception message.
*/
public MicException(String message) {
super(message);
}
......
......@@ -114,10 +114,16 @@ public class PhoneRespeaker implements
/**
* Stops/finishes the phone respeaking process.
*/
public void stop() {
public void stop(){
stopMic();
player.release();
mapper.stop();
try {
mapper.stop();
} catch (IOException e) {
//If the mapping couldn't be written to file, the recording would
//not have been able to either, which would have resulted in an
//error. This block is unreachable.
}
file.close();
}
......
......@@ -90,10 +90,16 @@ public class ThumbRespeaker {
*
* @throws MicException If there is an issue stopping the microphone.
*/
public void stop() throws MicException {
public void stop() throws MicException, IOException {
recorder.stop();
player.pause();
mapper.stop();
//try {
mapper.stop();
//} catch (IOException e) {
//If the mapping couldn't be written to file, the recording would
//not have been able to either, which would have resulted in an
//error. This block is unreachable.
//}
}
public void setFinishedPlaying(boolean finishedPlaying) {
......
......@@ -14,6 +14,7 @@ import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
import java.io.IOException;
import java.util.UUID;
import org.lp20.aikuma.R;
......@@ -76,8 +77,11 @@ public class ThumbRespeakActivity extends AikumaActivity {
try {
respeaker.stop();
} catch (MicException e) {
//Maybe make a recording metadata file that refers to the error so
//that the audio can be salvaged.
Toast.makeText(this, "There has been an error stopping the microphone.",
Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(this, "There has been an error writing the mapping between original and respeaking to file",
Toast.LENGTH_LONG).show();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment