Changeset 563 in josm for trunk/src/org


Ignore:
Timestamp:
2008-02-25T14:59:31+01:00 (16 years ago)
Author:
david
Message:

implement fast/slow forward

Location:
trunk/src/org/openstreetmap/josm
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/audio/AudioPlayPauseAction.java

    r547 r563  
    2626                                AudioPlayer.play(url);
    2727                        } else if (AudioPlayer.playing()){
    28                                 AudioPlayer.pause();
     28                                if (AudioPlayer.speed() != 1.0)
     29                                        AudioPlayer.play(url, AudioPlayer.position());
     30                                else
     31                                        AudioPlayer.pause();
    2932                        } else {
    3033                                // find first audio marker to play
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r558 r563  
    4747import org.openstreetmap.josm.actions.audio.AudioPlayPauseAction;
    4848import org.openstreetmap.josm.actions.audio.AudioPrevAction;
     49import org.openstreetmap.josm.actions.audio.AudioFasterAction;
     50import org.openstreetmap.josm.actions.audio.AudioSlowerAction;
    4951import org.openstreetmap.josm.actions.search.SearchAction;
    5052import org.openstreetmap.josm.data.DataSetChecker;
     
    100102        public final JosmAction audioFwd = new AudioFwdAction();
    101103        public final JosmAction audioBack = new AudioBackAction();
     104        public final JosmAction audioFaster = new AudioFasterAction();
     105        public final JosmAction audioSlower = new AudioSlowerAction();
    102106
    103107        /* Help menu */
     
    222226                        current = audioMenu.add(audioBack);
    223227                        current.setAccelerator(audioBack.shortCut);
     228                        current = audioMenu.add(audioSlower);
     229                        current.setAccelerator(audioSlower.shortCut);
     230                        current = audioMenu.add(audioFaster);
     231                        current.setAccelerator(audioFaster.shortCut);
    224232                        add(audioMenu);
    225233                }
  • trunk/src/org/openstreetmap/josm/gui/preferences/AudioPreference.java

    r557 r563  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
    21package org.openstreetmap.josm.gui.preferences;
    32
     
    4039        private JTextField audioLeadIn = new JTextField(8);
    4140        private JTextField audioForwardBackAmount = new JTextField(8);
     41        private JTextField audioFastForwardMultiplier = new JTextField(8);
    4242        private JTextField audioCalibration = new JTextField(8);
    4343
     
    106106                gui.audio.add(audioForwardBackAmount, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
    107107
     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
    108113                audioLeadIn.setText(Main.pref.get("audio.leadin", "1"));
    109114                audioLeadIn.setToolTipText(tr("Playback starts this number of seconds before (or after, if negative) the audio track position requested"));
     
    127132                Main.pref.put("marker.audiosampleminmetres", audioSampleMinMetres.getText());           
    128133                Main.pref.put("audio.forwardbackamount", audioForwardBackAmount.getText());             
     134                Main.pref.put("audio.fastfwdmultiplier", audioFastForwardMultiplier.getText());         
    129135                Main.pref.put("audio.leadin", audioLeadIn.getText());           
    130136                Main.pref.put("audio.calibration", audioCalibration.getText());         
  • trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java

    r559 r563  
    3838        private double bytesPerSecond;
    3939        private static long chunk = 8000; /* bytes */
     40        private double speed = 1.0;
    4041
    4142        /**
     
    4849                private URL url;
    4950                private double offset; // seconds
    50 
     51                private double speed; // ratio
     52               
    5153                /*
    5254                 * Called to execute the commands in the other thread
    5355                 */
    54                 protected void play(URL url, double offset) throws Exception {
     56                protected void play(URL url, double offset, double speed) throws Exception {
    5557                        this.url = url;
    5658                        this.offset = offset;
     59                        this.speed = speed;
    5760                        command = Command.PLAY;
    5861                        result = Result.WAITING;
     
    8588                        return offset;
    8689                }
     90                protected double speed() {
     91                        return speed;
     92                }
    8793                protected URL url() {
    8894                        return url;
     
    102108         */
    103109        public static void play(URL url) throws Exception {
    104                 AudioPlayer.play(url, 0.0);
     110                AudioPlayer.get().command.play(url, 0.0, 1.0);
    105111        }
    106112       
     
    112118         */
    113119        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);
    115132        }
    116133       
     
    155172        }
    156173       
     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
    157182        /**
    158183         *  gets the singleton object, and if this is the first time, creates it along with
     
    241266                                        case PLAY:     
    242267                                                double offset = command.offset();
     268                                                speed = command.speed();
    243269                                                if (playingUrl != command.url() ||
    244270                                                        stateChange != State.PAUSED ||
     
    252278                                                        audioInputStream = AudioSystem.getAudioInputStream(playingUrl);
    253279                                                        audioFormat = audioInputStream.getFormat();
    254                                                         DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
    255280                                                        long nBytesRead = 0;
    256281                                                        position = 0.0;
     
    258283                                                        bytesPerSecond = audioFormat.getFrameRate() /* frames per second */
    259284                                                                * audioFormat.getFrameSize() /* bytes per frame */;
     285                                                        if (speed * bytesPerSecond > 256000.0)
     286                                                                speed = 256000 / bytesPerSecond;
    260287                                                        if (offset != 0.0 && adjustedOffset > 0.0) {
    261288                                                                long bytesToSkip = (long)(
     
    275302                                                                position = adjustedOffset;
    276303                                                        }
    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();
    282317                                                }
    283318                                                stateChange = State.PLAYING;
Note: See TracChangeset for help on using the changeset viewer.