/**
   * Creates an AudioSource which can be to manipulate a Sound buffer. An AudioSource can be created
   * multiple times and use the same Sound buffer.
   */
  public AudioSource createAudioSource(final String _file, final StreamType _type) {
    final AudioBuffer<AndroidSound> buffer =
        (AudioBuffer<AndroidSound>) staticSoundManager.get(_file);
    if (buffer == null) {
      System.out.println("Sound Doesn't exist.");
      return null;
    }

    final AndroidSound sound = buffer.getBuffer();
    return new AndroidSource(sound.getBuffer());
  }
Esempio n. 2
0
  /** When udpListener gets a packet */
  public void packetReceived(DatagramSocket socket, DatagramPacket packet) {
    this.rtpClient = packet.getAddress(); // The client address

    int type = packet.getData()[1] & ~0x80;
    if (type == 0x60 || type == 0x56) { // audio data / resend
      // Decale de 4 bytes supplementaires
      int off = 0;
      if (type == 0x56) {
        off = 4;
      }

      // seqno is on two byte
      int seqno =
          (int) ((packet.getData()[2 + off] & 0xff) * 256 + (packet.getData()[3 + off] & 0xff));

      // + les 12 (cfr. RFC RTP: champs a ignorer)
      byte[] pktp = new byte[packet.getLength() - off - 12];
      for (int i = 0; i < pktp.length; i++) {
        pktp[i] = packet.getData()[i + 12 + off];
      }

      audioBuf.putPacketInBuffer(seqno, pktp);
    }
  }
Esempio n. 3
0
  @SuppressWarnings("SleepWhileInLoop")
  @Override
  boolean bindAudioBuffer(AudioBuffer audioBuffer) {
    // First check we've been initialised
    if (!initialised) {
      return false;
    }

    // Wait for AudioBuffer to be loaded, or 20 seconds
    long startTime = System.currentTimeMillis();
    while (audioBuffer.getState() != AudioBuffer.STATE_LOADED
        && System.currentTimeMillis() - startTime < 20000) {
      try {
        Thread.sleep(50);
      } catch (InterruptedException ex) {
      }
    }

    if (audioBuffer instanceof JavaSoundAudioBuffer
        && audioBuffer.getState() == AudioBuffer.STATE_LOADED) {
      // Cast to JavaSoundAudioBuffer to enable easier access to specific methods
      JavaSoundAudioBuffer buffer = (JavaSoundAudioBuffer) audioBuffer;

      // Get a JavaSound DataLine and Clip
      DataLine.Info lineInfo;
      lineInfo = new DataLine.Info(Clip.class, buffer.getAudioFormat());
      Clip newClip;
      try {
        newClip = (Clip) mixer.getLine(lineInfo);
      } catch (LineUnavailableException ex) {
        log.warn(
            "Error binding JavaSoundSource ("
                + this.getSystemName()
                + ") to AudioBuffer ("
                + this.getAssignedBufferName()
                + ") "
                + ex);
        return false;
      }

      this.clip = newClip;

      try {
        clip.open(
            buffer.getAudioFormat(),
            buffer.getDataStorageBuffer(),
            0,
            buffer.getDataStorageBuffer().length);
      } catch (LineUnavailableException ex) {
        log.warn(
            "Error binding JavaSoundSource ("
                + this.getSystemName()
                + ") to AudioBuffer ("
                + this.getAssignedBufferName()
                + ")"
                + ex);
      }
      if (log.isDebugEnabled()) {
        log.debug(
            "Bind JavaSoundAudioSource ("
                + this.getSystemName()
                + ") to JavaSoundAudioBuffer ("
                + audioBuffer.getSystemName()
                + ")");
      }
      return true;
    } else {
      log.warn(
          "AudioBuffer not loaded error when binding JavaSoundSource ("
              + this.getSystemName()
              + ") to AudioBuffer ("
              + this.getAssignedBufferName()
              + ")");
      return false;
    }
  }
Esempio n. 4
0
 /** Flush the audioBuffer */
 public void flush() {
   audioBuf.flush();
 }