public void newSource(AudioSource s, boolean suspend) {
    if (!suspend) {
      //			System.out.println("AudioProcessor.newSource suspend=false");
      source.close();
      source = s;
      AudioFormat format =
          new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 8000, 16, 1, 2, 8000, bigEndian);
      if (source != null) source.init(this, format, frameSize);

    } else {
      //			System.out.println("AudioProcessor.newSource suspend=true");
      //			System.out.println("                         original source="+source.getClass());
      //			System.out.println("                         new source="+s.getClass());
      suspendedSource = source;
      //			System.out.println("                         halting original source");
      source.halt();
      //			System.out.println("                         original source halted");
      source = s;
      AudioFormat format =
          new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 8000, 16, 1, 2, 8000, bigEndian);
      if (source != null) {
        //				System.out.println("                         calling initialize method of new
        // source");
        source.init(this, format, frameSize);
      }
      //				System.out.println("                         new source initialized");
    }
    //		System.out.println("AudioProcessor.newSource exits");
  }
  private void init(
      int payloadType,
      AudioSource src,
      AudioSender snd,
      AudioDestination dst,
      AudioReceiver rcv,
      int fs) {

    Logger.debug("AudioProcessor.init:");
    Logger.debug("		destination=" + dst.getClass());
    if (src != null) Logger.debug("		source=" + src.getClass());
    else Logger.debug("		source=null");
    if (snd != null) Logger.debug("		sender=" + snd.getClass());
    else Logger.debug("		sender=null");
    if (rcv != null) Logger.debug("		receiver=" + rcv.getClass());
    else Logger.debug("		receiver=null");
    this.payloadType = payloadType;
    frameSize = fs;
    {
      Logger.debug("");
      switch (this.payloadType) {
        case 0:
          encoder = new PCMUCodec4(this);
          decoder = new PCMUCodec4(this);
          break;
        case 8:
          encoder = new PCMACodec(this);
          decoder = new PCMACodec(this);
          break;
        default:
          encoder = null;
          decoder = null;
          break;
      }
      if (encoder != null) Logger.debug("encoder=" + encoder.getClass());
      if (decoder != null) Logger.debug("decoder=" + decoder.getClass());
      if (encoder != null) encoder.init();
      if (decoder != null) decoder.init();
    }
    source = src;
    sender = snd;
    destination = dst;
    // Logger.debug("AudioProcessor constructor: destination="+destination);
    receiver = rcv;
    if (sender != null) sender.init(this.payloadType);
    AudioFormat format =
        new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 8000, 16, 1, 2, 8000, bigEndian);
    //	AudioFormat format=new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,22050,8,1,1,22050,false);
    if (source != null) source.init(this, format, frameSize);
    if (destination != null) destination.init(this, format, frameSize);
    else Logger.error("AudioProcessor: destination=null");
    if (receiver != null) receiver.init(this);
  }
 public boolean resumeSuspendedSource() {
   Logger.debug("audioprosessor.resumesuspendedsource starts");
   if (suspendedSource == null) return false;
   Logger.debug("close source");
   source.close();
   Logger.debug("source closed");
   source = null;
   Logger.debug("vanha source");
   source = suspendedSource;
   Logger.debug("unhalt vanha source");
   boolean ok = source.unhalt();
   Logger.debug("vanha source unhalted");
   Logger.debug("audioprosessor.resumesuspendedsource ends");
   return ok;
 }
  public void stop() {

    Logger.info("AudioProcessor.stop: closing all inputs and outputs");
    if (source != null) source.close();
    if (sender != null) sender.close();
    if (destination != null) destination.close();
    if (receiver != null) receiver.close();

    return;
  }
  public boolean start() {
    boolean ok = false;

    if (source != null) source.go();
    if (sender != null) sender.go();
    if (destination != null) destination.go();
    if (receiver != null) receiver.go();

    ok = true;

    return ok;
  }
Exemple #6
0
  public static void main(String args[]) throws IOException, InterruptedException {
    AudioMaster.init();
    AudioMaster.setListenerData(0, 0, 0);

    int buffer = AudioMaster.loadSound("audio/music.wav");
    AudioSource source = new AudioSource();
    source.setLooping(true);
    source.play(buffer);

    float xPos = 8;
    source.setPosition(xPos, 2, 0);

    char c = ' ';
    while (c != 'q') {
      xPos -= 0.03f;
      source.setPosition(xPos, 2, 0);
      Thread.sleep(10);
    }

    source.delete();
    AudioMaster.cleanUp();
  }