Example #1
0
 public final boolean init(VSDFile vf, BufferMode mode) {
   AudioManager am = jmri.InstanceManager.getDefault(jmri.AudioManager.class);
   if (!initialized) {
     try {
       sound_src = (AudioSource) am.provideAudio(SrcSysNamePrefix + system_name);
       sound_src.setUserName(BufUserNamePrefix + user_name);
       setLooped(false);
       if (mode == BufferMode.BOUND_MODE) {
         sound_buf = (AudioBuffer) am.provideAudio(BufSysNamePrefix + system_name);
         sound_buf.setUserName(BufUserNamePrefix + user_name);
         if (vf == null) {
           sound_buf.setURL(vsd_file_base + filename);
         } else {
           java.io.InputStream ins = vf.getInputStream(filename);
           if (ins != null) {
             sound_buf.setInputStream(ins);
           } else {
             return (false);
           }
         }
         sound_src.setAssignedBuffer(sound_buf);
         setLength();
       }
     } catch (AudioException | IllegalArgumentException ex) {
       log.warn("Problem creating SoundBite: " + ex);
     }
   }
   return (true);
 }
Example #2
0
  public static long calcLength(AudioBuffer buf) {
    // Assumes later getBuffer() will find the buffer from AudioManager instead
    // of the current local reference... that's why I'm not directly using sound_buf here.

    // Required buffer functions not yet implemented
    long num_frames;
    int frequency;

    if (buf != null) {
      num_frames = buf.getLength();
      frequency = buf.getFrequency();
    } else {
      // No buffer attached!
      num_frames = 0;
      frequency = 0;
    }

    /*
    long num_frames = 1;
    long frequency = 125;
    */
    if (frequency <= 0) {
      // Protect against divide-by-zero errors
      return (0l);
    } else {
      return ((1000 * num_frames) / frequency);
    }
  }
Example #3
0
  public void queueBuffer(AudioBuffer b) {
    if (bufferMode == BufferMode.QUEUE_MODE) {
      if (b == null) {
        log.debug("queueAudioBuffer with null buffer input");
        return;
      }
      if (sound_src == null) {
        log.debug("queueAudioBuffer with null sound_src");
        return;
      }

      log.debug("Queueing Buffer: " + b.getSystemName());

      sound_src.queueBuffer(b);
    } else {
      log.warn("Attempted to Queue buffer to a Bound SoundBite.");
    }
  }
Example #4
0
 public void setURL(String filename) {
   this.filename = filename;
   sound_buf.setURL(vsd_file_base + filename);
 }