In comp.soft-sys.ptolemy, [EMAIL PROTECTED] (Hendrik Schoeneich) writes:
    Hi!
    
    I would like to capture and play sound simultaneously with Ptolemy II.
    In chapter 3.3.8 (Actor Libraries, Signal Processing, Audio) the
    documentation says: "... they (the AudioCapture and AudioPlayer
    actors) have the restriction that only one of each may be used in a
    model at a time." Now I am wondering if this is a restriction of
    Ptolemy II or of Java itself.
    
    Is there possibly a known way to solve this? 
    
    The waiting and hoping...
    
    Hendrik
--------

I'm not the original author of the code, and I'm not sure about this,
but I think that the problem was that we were getting messages about
how the device was already in use, and that changing the device
configuration parameters would cause Java to throw an exception.

I believe that this was a Java limitation at the time the Ptolemy II
classes were written.  

However, when I look at the Ptolemy II code, I'm not at all sure if
this issue is really a Java issue or a Ptolemy issue.  You may want
to poke around in the javax.sound.sampled docs and see if there are
any limitations on the Java side.


In 
http://ptolemy.eecs.berkeley.edu/ptolemyII/ptII1.0/ptII1.0/ptolemy/actor/lib/javasound/AudioCapture.java


The class comment looks like:
  It should be noted that at most one AudioCapture and one AudioPlayer
  actor may be used simultaneously. Otherwise, an exception will
  occur. This restriction may be lifted in a future version of
  this actor.

The initialize() method calls _initializeCapture():

   /** Read parameter values and begin the sound capture process.
     *  An exception will occur if there is a problem starting
     *  the audio capture. This will occur if another AudioCapture actor has
     *  already started capturing.
     *  @exception IllegalActionException If there is a problem
     *   starting audio capture.
     */
    public void initialize() throws IllegalActionException {
        super.initialize();
        if (_debugInfo) {
            System.out.println("AudioCapture: initialize(): invoked");
        }
        try {
            _initializeCapture();
        } catch (IOException ex) {
            throw new IllegalActionException(this,
                    "Cannot initialize audio capture " +
                    ex);
        }
        _safeToInitialize = true;
        _haveASample = false;
    }



/** Initialize audio resources. Reread all parameters, and start
     *  audio capture.
     *  <p>
     *  This method is synchronized since it is not safe to call
     *  LiveSound methods while this method is executing.
     *  @exception IllegalActionException If there is a problem initializing
     *   audio capture.
     */
    private synchronized void _initializeCapture()
            throws IllegalActionException, IOException {
        if (_debugInfo) {
            System.out.println("AudioCapture: _initializeCapture() invoked.");
        }
        if (LiveSound.isCaptureActive()) {
            throw new IllegalActionException(this,
                    "This actor cannot start audio capture because " +
                    "another actor currently has access to the audio "
+
                    "capture resource. Only one AudioCapture actor may
" +
                    "be used at a time.");
            //LiveSound.stopCapture(this);

        }




http://ptolemy.eecs.berkeley.edu/ptolemyII/ptII1.0/ptII1.0/ptolemy/media/javasound/LiveSound.java

Says:
  It should be noted
  that only one object may playback audio simultaneously to the
  audio output port. A future version of this class may support
  multiple objects playing to the output port simultaneously.

LiveSound implements a lock mechanism that ensures that only one
object is playing back at a time.

So, I'm now guessing that this is a limitation in the Ptolemy II
code.  The fix would require rehacking ptolemy/media/javasoft.
It seems like use Mixers might help?


-Christopher

Christopher Hylands    [EMAIL PROTECTED]  University of California
Ptolemy/Gigascale Silicon Research Center     US Mail: 558 Cory Hall #1770
ph: (510)643-9841 fax:(510)642-2739           Berkeley, CA 94720-1770
home: (510)526-4010                           (Office: 400A Cory)

----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]

Reply via email to