Changeset 563 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2008-02-25T14:59:31+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java
r559 r563 38 38 private double bytesPerSecond; 39 39 private static long chunk = 8000; /* bytes */ 40 private double speed = 1.0; 40 41 41 42 /** … … 48 49 private URL url; 49 50 private double offset; // seconds 50 51 private double speed; // ratio 52 51 53 /* 52 54 * Called to execute the commands in the other thread 53 55 */ 54 protected void play(URL url, double offset ) throws Exception {56 protected void play(URL url, double offset, double speed) throws Exception { 55 57 this.url = url; 56 58 this.offset = offset; 59 this.speed = speed; 57 60 command = Command.PLAY; 58 61 result = Result.WAITING; … … 85 88 return offset; 86 89 } 90 protected double speed() { 91 return speed; 92 } 87 93 protected URL url() { 88 94 return url; … … 102 108 */ 103 109 public static void play(URL url) throws Exception { 104 AudioPlayer. play(url, 0.0);110 AudioPlayer.get().command.play(url, 0.0, 1.0); 105 111 } 106 112 … … 112 118 */ 113 119 public static void play(URL url, double seconds) throws Exception { 114 AudioPlayer.get().command.play(url, seconds); 120 AudioPlayer.get().command.play(url, seconds, 1.0); 121 } 122 123 /** 124 * Plays a WAV audio file from a specified position at variable speed. 125 * @param url The resource to play, which must be a WAV file or stream 126 * @param seconds The number of seconds into the audio to start playing 127 * @param speed Rate at which audio playes (1.0 = real time, > 1 is faster) 128 * @throws audio fault exception, e.g. can't open stream, unhandleable audio format 129 */ 130 public static void play(URL url, double seconds, double speed) throws Exception { 131 AudioPlayer.get().command.play(url, seconds, speed); 115 132 } 116 133 … … 155 172 } 156 173 174 /** 175 * Speed at which we will play. 176 * @returns double, speed multiplier 177 */ 178 public static double speed() { 179 return AudioPlayer.get().speed; 180 } 181 157 182 /** 158 183 * gets the singleton object, and if this is the first time, creates it along with … … 241 266 case PLAY: 242 267 double offset = command.offset(); 268 speed = command.speed(); 243 269 if (playingUrl != command.url() || 244 270 stateChange != State.PAUSED || … … 252 278 audioInputStream = AudioSystem.getAudioInputStream(playingUrl); 253 279 audioFormat = audioInputStream.getFormat(); 254 DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);255 280 long nBytesRead = 0; 256 281 position = 0.0; … … 258 283 bytesPerSecond = audioFormat.getFrameRate() /* frames per second */ 259 284 * audioFormat.getFrameSize() /* bytes per frame */; 285 if (speed * bytesPerSecond > 256000.0) 286 speed = 256000 / bytesPerSecond; 260 287 if (offset != 0.0 && adjustedOffset > 0.0) { 261 288 long bytesToSkip = (long)( … … 275 302 position = adjustedOffset; 276 303 } 277 if (audioOutputLine == null) { 278 audioOutputLine = (SourceDataLine) AudioSystem.getLine(info); 279 audioOutputLine.open(audioFormat); 280 audioOutputLine.start(); 281 } 304 if (audioOutputLine != null) 305 audioOutputLine.close(); 306 audioFormat = new AudioFormat(audioFormat.getEncoding(), 307 audioFormat.getSampleRate() * (float) speed, 308 audioFormat.getSampleSizeInBits(), 309 audioFormat.getChannels(), 310 audioFormat.getFrameSize(), 311 audioFormat.getFrameRate() * (float) speed, 312 audioFormat.isBigEndian()); 313 DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat); 314 audioOutputLine = (SourceDataLine) AudioSystem.getLine(info); 315 audioOutputLine.open(audioFormat); 316 audioOutputLine.start(); 282 317 } 283 318 stateChange = State.PLAYING;
Note:
See TracChangeset
for help on using the changeset viewer.