Changeset 563 in josm
- Timestamp:
- 2008-02-25T14:59:31+01:00 (17 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/audio/AudioPlayPauseAction.java
r547 r563 26 26 AudioPlayer.play(url); 27 27 } else if (AudioPlayer.playing()){ 28 AudioPlayer.pause(); 28 if (AudioPlayer.speed() != 1.0) 29 AudioPlayer.play(url, AudioPlayer.position()); 30 else 31 AudioPlayer.pause(); 29 32 } else { 30 33 // find first audio marker to play -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r558 r563 47 47 import org.openstreetmap.josm.actions.audio.AudioPlayPauseAction; 48 48 import org.openstreetmap.josm.actions.audio.AudioPrevAction; 49 import org.openstreetmap.josm.actions.audio.AudioFasterAction; 50 import org.openstreetmap.josm.actions.audio.AudioSlowerAction; 49 51 import org.openstreetmap.josm.actions.search.SearchAction; 50 52 import org.openstreetmap.josm.data.DataSetChecker; … … 100 102 public final JosmAction audioFwd = new AudioFwdAction(); 101 103 public final JosmAction audioBack = new AudioBackAction(); 104 public final JosmAction audioFaster = new AudioFasterAction(); 105 public final JosmAction audioSlower = new AudioSlowerAction(); 102 106 103 107 /* Help menu */ … … 222 226 current = audioMenu.add(audioBack); 223 227 current.setAccelerator(audioBack.shortCut); 228 current = audioMenu.add(audioSlower); 229 current.setAccelerator(audioSlower.shortCut); 230 current = audioMenu.add(audioFaster); 231 current.setAccelerator(audioFaster.shortCut); 224 232 add(audioMenu); 225 233 } -
trunk/src/org/openstreetmap/josm/gui/preferences/AudioPreference.java
r557 r563 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others2 1 package org.openstreetmap.josm.gui.preferences; 3 2 … … 40 39 private JTextField audioLeadIn = new JTextField(8); 41 40 private JTextField audioForwardBackAmount = new JTextField(8); 41 private JTextField audioFastForwardMultiplier = new JTextField(8); 42 42 private JTextField audioCalibration = new JTextField(8); 43 43 … … 106 106 gui.audio.add(audioForwardBackAmount, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5)); 107 107 108 audioFastForwardMultiplier.setText(Main.pref.get("audio.fastfwdmultiplier", "1.3")); 109 audioFastForwardMultiplier.setToolTipText(tr("The amount by which the speed is multiplied for fast forwarding")); 110 gui.audio.add(new JLabel(tr("Fast forward multiplier")), GBC.std()); 111 gui.audio.add(audioFastForwardMultiplier, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5)); 112 108 113 audioLeadIn.setText(Main.pref.get("audio.leadin", "1")); 109 114 audioLeadIn.setToolTipText(tr("Playback starts this number of seconds before (or after, if negative) the audio track position requested")); … … 127 132 Main.pref.put("marker.audiosampleminmetres", audioSampleMinMetres.getText()); 128 133 Main.pref.put("audio.forwardbackamount", audioForwardBackAmount.getText()); 134 Main.pref.put("audio.fastfwdmultiplier", audioFastForwardMultiplier.getText()); 129 135 Main.pref.put("audio.leadin", audioLeadIn.getText()); 130 136 Main.pref.put("audio.calibration", audioCalibration.getText()); -
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.