net.livesite.jsound
Class JSoundApplet

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by net.livesite.jsound.JSoundApplet
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class JSoundApplet
extends Applet

Sound recording, playback, and posting using javax.sound.sampled interfaces. We intentionally do NOT use Thread.join() calls on the Record, Playback, and Posting threads. Although, this is the desired behavior from the outside, it enables a complete lock of the application when either of these threads lock. Instead, we provide status methods intended to be used from the outside to interrogate when the line is available (ie the Play thread has really stopped playing.)

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.applet.Applet
Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JSoundApplet()
          Called by the Applet Container.
 
Method Summary
 String canRecordAt(String paramRate, String paramBits, String paramChannels, String paramBigEndian)
           
 void commitRecordings()
          Commit all the recordings when they have all finished saving.
 void destroy()
          Called by the Applet Container.
 boolean doDuplex()
          Interrogate the soundcard for duplex capability.
 Object getRecording(String name)
          A recording for the specified buffer
 boolean hasPrivledges()
          Is this applet running with the appropriate (accepted) privledges?
 boolean hasRecording(String name)
          A recording for the specified buffer exists.
 boolean hasSoundRecPriv()
          This is used by javascript to test the sound recording priviledge is setup properly.
 void init()
          Called when the browser first starts the applet.
 boolean isActive()
          Are we actively processing data?
 boolean isReady()
          This applet has been initialized correctly and is ready.
 boolean isRecording()
          isRecording - Report whether or not we are currently recording.
 void postRecording(String name)
          Post the recording bits to the server
 void printStatus()
          Print the status of the system to the console.
 void reset()
          Return the applet to the same state it was when it was initialized.
 boolean startPlaying(String name)
          Start playing previously recorded audio from memory.
 boolean startRecording(String name)
          Start recording audio into temporary memory.
 void stopPlaying()
          Stop playing audio.
 void stopRecording()
          Stop recording audio.
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JSoundApplet

public JSoundApplet()
Called by the Applet Container. Constructs this class.

Method Detail

init

public void init()
Called when the browser first starts the applet. Get parameters set in the OBJECT declaration.

Overrides:
init in class Applet

destroy

public void destroy()
Called by the Applet Container.

Overrides:
destroy in class Applet

isReady

public boolean isReady()
This applet has been initialized correctly and is ready.

Returns:
boolean

isActive

public boolean isActive()
Are we actively processing data?

Overrides:
isActive in class Applet
Returns:
boolean

hasSoundRecPriv

public boolean hasSoundRecPriv()
This is used by javascript to test the sound recording priviledge is setup properly.

Returns:
boolean

hasRecording

public boolean hasRecording(String name)
A recording for the specified buffer exists.

Parameters:
name - String of the buffer (if null, the default buffer is checked.

getRecording

public Object getRecording(String name)
A recording for the specified buffer

Parameters:
name - String of the buffer (if null, the default buffer is checked.

printStatus

public void printStatus()
Print the status of the system to the console.


isRecording

public boolean isRecording()
isRecording - Report whether or not we are currently recording.

Returns:
boolean currently recording

startRecording

public boolean startRecording(String name)
Start recording audio into temporary memory. This is done in a separate thread so that the calling script can access other methods. It does not make sense to have two threads capturing data at the same time. For we assume the operator is only using one microphone. We will store the recorded audio in memory indexed by the unique name provided. If no name is provided, we will use a single default buffer.

Parameters:
name - String distinct name of the recording
Returns:
boolean successfully started

stopRecording

public void stopRecording()
Stop recording audio.


startPlaying

public boolean startPlaying(String name)
Start playing previously recorded audio from memory. Use the recording indexed by the unique name provided. If no name is provided, we will use a single default buffer. This is done in a separate thread so that the calling script can access other methods. It does not make sense to have two threads playing data at the same time. For we assume the operator is only set of speakers.

Parameters:
name - String distinct name of the recording
Returns:
boolean successfully started playing

stopPlaying

public void stopPlaying()
Stop playing audio.


postRecording

public void postRecording(String name)
Post the recording bits to the server

Parameters:
name - String buffer to post

commitRecordings

public void commitRecordings()
Commit all the recordings when they have all finished saving. It calls the passed in URL to 'commit'. the key here is that posting of recordings is async and when you are done with a lesson then you should commit the changes, there is no way to commit the changes without waiting for each posting thread to complete. that is what this method does.


doDuplex

public boolean doDuplex()
                 throws InterruptedException
Interrogate the soundcard for duplex capability. Duplex means you can record and playback at the same time. This method will take at least Ten seconds. 1) Record a 5 second clip 2) Start playing the 5 second clip 3) Start recording another clip 4) If an execption is thrown, we cannot go duplex.

Returns:
boolean duplex is supported
Throws:
InterruptedException

reset

public void reset()
           throws InterruptedException
Return the applet to the same state it was when it was initialized.

Throws:
InterruptedException

hasPrivledges

public boolean hasPrivledges()
Is this applet running with the appropriate (accepted) privledges?

Returns:
boolean

canRecordAt

public String canRecordAt(String paramRate,
                          String paramBits,
                          String paramChannels,
                          String paramBigEndian)
                   throws Exception
Throws:
Exception