fix reverse play buffer refilling; turn on Blink signal again
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 15 Feb 2007 16:07:45 +0000 (16:07 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 15 Feb 2007 16:07:45 +0000 (16:07 +0000)
git-svn-id: svn://localhost/ardour2/trunk@1464 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/ardour_ui.cc
gtk2_ardour/ardour_ui2.cc
libs/ardour/audio_diskstream.cc
libs/ardour/audiofilter.cc
libs/ardour/reverse.cc
libs/ardour/sndfilesource.cc

index 8f07d091a77a6af734c95df1c7650a611943ea64..febdbab088f28809beb076662c2e7160800c7b45 100644 (file)
@@ -1489,7 +1489,7 @@ ARDOUR_UI::_blink (void *arg)
 void
 ARDOUR_UI::blink ()
 {
-       // Blink (blink_on = !blink_on); /* EMIT_SIGNAL */
+       Blink (blink_on = !blink_on); /* EMIT_SIGNAL */
 }
 
 void
index 63104f003465ee1aff2b385f258b52ddbbabca89..5f1f0e3b7b285b5a7ae03c36d687a46dae6f2a37 100644 (file)
@@ -176,20 +176,6 @@ ARDOUR_UI::transport_forwarding ()
        auto_loop_button.set_visual_state (0);
 }
 
-bool
-messagefoo (GdkEventButton* ev)
-{
-       cerr << " roll  button pressed\n";
-       return false;
-}
-
-bool
-messagefoo2 (GdkEventButton* ev)
-{
-       cerr << " roll  button release\n";
-       return false;
-}
 void
 ARDOUR_UI::setup_transport ()
 {
@@ -267,9 +253,6 @@ ARDOUR_UI::setup_transport ()
 
        RefPtr<Action> act;
 
-       roll_button.signal_button_press_event().connect (sigc::ptr_fun (messagefoo));
-       roll_button.signal_button_release_event().connect (sigc::ptr_fun (messagefoo2));
-
        act = ActionManager::get_action (X_("Transport"), X_("Stop"));
        act->connect_proxy (stop_button);
        act = ActionManager::get_action (X_("Transport"), X_("Roll"));
index 9c101bd757ee27fd589f25e7a08780fa5bc269c3..c22ba75c7d7868186a82474a2ce4558eb592fb5a 100644 (file)
@@ -982,7 +982,10 @@ AudioDiskstream::read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer,
        nframes_t offset = 0;
        Location *loc = 0;
 
+       /* XXX we don't currently play loops in reverse. not sure why */
+
        if (!reversed) {
+
                /* Make the use of a Location atomic for this read operation.
                   
                   Note: Locations don't get deleted, so all we care about
@@ -1006,11 +1009,16 @@ AudioDiskstream::read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer,
                        start = loop_start + ((start - loop_start) % loop_length);
                        //cerr << "to " << start << endl;
                }
+
                //cerr << "start is " << start << "  loopstart: " << loop_start << "  loopend: " << loop_end << endl;
        }
 
        while (cnt) {
 
+               if (reversed) {
+                       start -= cnt;
+               }
+                       
                /* take any loop into account. we can't read past the end of the loop. */
 
                if (loc && (loop_end - start < cnt)) {
@@ -1038,9 +1046,6 @@ AudioDiskstream::read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer,
                
                if (reversed) {
 
-                       /* don't adjust start, since caller has already done that
-                        */
-
                        swap_by_ptr (buf, buf + this_read - 1);
                        
                } else {
@@ -1096,7 +1101,7 @@ AudioDiskstream::_do_refill (Sample* mixdown_buffer, float* gain_buffer)
        if ((total_space = vector.len[0] + vector.len[1]) == 0) {
                return 0;
        }
-       
+
        /* if there are 2+ chunks of disk i/o possible for
           this track, let the caller know so that it can arrange
           for us to be called again, ASAP.
@@ -1126,6 +1131,8 @@ AudioDiskstream::_do_refill (Sample* mixdown_buffer, float* gain_buffer)
                return 0;
        }
 
+       /* never do more than disk_io_chunk_frames worth of disk input per call (limit doesn't apply for memset) */
+
        total_space = min (disk_io_chunk_frames, total_space);
 
        if (reversed) {
@@ -1159,11 +1166,6 @@ AudioDiskstream::_do_refill (Sample* mixdown_buffer, float* gain_buffer)
 
                } else {
                        
-                       /* move read position backwards because we are going
-                          to reverse the data.
-                       */
-                       
-                       file_frame -= total_space;
                        zero_fill = 0;
                }
 
@@ -1209,21 +1211,36 @@ AudioDiskstream::_do_refill (Sample* mixdown_buffer, float* gain_buffer)
 
                chan.playback_buf->get_write_vector (&vector);
 
+               if (vector.len[0] > disk_io_chunk_frames) {
+                       
+                       /* we're not going to fill the first chunk, so certainly do not bother with the
+                          other part. it won't be connected with the part we do fill, as in:
+                          
+                          .... => writable space
+                          ++++ => readable space
+                          ^^^^ => 1 x disk_io_chunk_frames that would be filled
+                          
+                          |......|+++++++++++++|...............................|
+                          buf1                buf0
+                                               ^^^^^^^^^^^^^^^
+                          
+                          
+                          So, just pretend that the buf1 part isn't there.                                     
+                          
+                       */
+               
+                       vector.buf[1] = 0;
+                       vector.len[1] = 0;
+               
+               } 
+
                ts = total_space;
                file_frame_tmp = file_frame;
 
-               if (reversed) {
-                       buf1 = vector.buf[1];
-                       len1 = vector.len[1];
-                       buf2 = vector.buf[0];
-                       len2 = vector.len[0];
-               } else {
-                       buf1 = vector.buf[0];
-                       len1 = vector.len[0];
-                       buf2 = vector.buf[1];
-                       len2 = vector.len[1];
-               }
-
+               buf1 = vector.buf[0];
+               len1 = vector.len[0];
+               buf2 = vector.buf[1];
+               len2 = vector.len[1];
 
                to_read = min (ts, len1);
                to_read = min (to_read, disk_io_chunk_frames);
@@ -1234,7 +1251,7 @@ AudioDiskstream::_do_refill (Sample* mixdown_buffer, float* gain_buffer)
                                ret = -1;
                                goto out;
                        }
-                       
+
                        chan.playback_buf->increment_write_ptr (to_read);
                        ts -= to_read;
                }
@@ -1243,7 +1260,6 @@ AudioDiskstream::_do_refill (Sample* mixdown_buffer, float* gain_buffer)
 
                if (to_read) {
 
-                       
                        /* we read all of vector.len[0], but it wasn't an entire disk_io_chunk_frames of data,
                           so read some or all of vector.len[1] as well.
                        */
index a7117cf9dc1646ad87f61408dc3f2a35f8d8d7b1..6987ec7c0bebbd70a4649cfc101de16d02c5c480 100644 (file)
@@ -79,6 +79,7 @@ AudioFilter::finish (boost::shared_ptr<AudioRegion> region, SourceList& nsrcs)
                boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource>(*si);
                if (afs) {
                        afs->update_header (region->position(), *now, xnow);
+                       afs->mark_immutable ();
                }
        }
 
index eb68a09049c1e6194e0f4aacde8a450d71353c6b..7495fd177f008aeac62373ea2365edb40830a4e6 100644 (file)
@@ -47,10 +47,9 @@ Reverse::run (boost::shared_ptr<AudioRegion> region)
 {
        SourceList nsrcs;
        SourceList::iterator si;
-       const nframes_t blocksize = 256 * 1048;
-       Sample buf[blocksize];
+       nframes_t blocksize = 256 * 1024;
+       Sample* buf;
        nframes_t fpos;
-       nframes_t fend;
        nframes_t fstart;
        nframes_t to_read;
        int ret = -1;
@@ -61,31 +60,34 @@ Reverse::run (boost::shared_ptr<AudioRegion> region)
                goto out;
        }
 
-       fend = region->start() + region->length();
        fstart = region->start();
 
-       if (blocksize < fend) {
-               fpos =max(fstart, fend - blocksize);
-       } else {
-               fpos = fstart;
+       if (blocksize > region->length()) {
+               blocksize = region->length();
        }
 
-       to_read = min (region->length(), blocksize);
+       fpos = max (fstart, (fstart + region->length() - blocksize));
+       buf = new Sample[blocksize];
+       to_read = blocksize;
+
+       cerr << "Reverse " << region->name() << " len = " << region->length() << " blocksize = " << blocksize << " start at " << fstart << endl;
 
        /* now read it backwards */
 
-       while (1) {
+       while (to_read) {
 
                uint32_t n;
 
                for (n = 0, si = nsrcs.begin(); n < region->n_channels(); ++n, ++si) {
 
                        /* read it in */
+
+                       cerr << "read at " << fpos << " for " << to_read << endl;
                        
                        if (region->source (n)->read (buf, fpos, to_read) != to_read) {
                                goto out;
                        }
-                       
+
                        /* swap memory order */
                        
                        for (nframes_t i = 0; i < to_read/2; ++i) {
@@ -99,13 +101,12 @@ Reverse::run (boost::shared_ptr<AudioRegion> region)
                        }
                }
 
-               if (fpos == fstart) {
-                       break;
-               } else if (fpos > fstart + to_read) {
+               if (fpos > fstart + blocksize) {
                        fpos -= to_read;
-                       to_read = min (fstart - fpos, blocksize);
+                       to_read = blocksize;
                } else {
-                       to_read = fpos-fstart;
+                       to_read = fpos - fstart;
+                       cerr << "Last read detected, only " << fpos - fstart << " left; move to start and read " << to_read << endl;
                        fpos = fstart;
                }
        };
@@ -114,6 +115,8 @@ Reverse::run (boost::shared_ptr<AudioRegion> region)
 
   out:
 
+       delete [] buf;
+
        if (ret) {
                for (si = nsrcs.begin(); si != nsrcs.end(); ++si) {
                        (*si)->mark_for_remove ();
index 629b3e41581833d128903118a1afc8d6a3925a52..296f7471ad78dde27021c188a956e11ce53a823a 100644 (file)
@@ -388,6 +388,8 @@ SndFileSource::nondestructive_write_unlocked (Sample *data, nframes_t cnt)
        
        nframes_t oldlen;
        int32_t frame_pos = _length;
+
+       cerr << _name << " write " << cnt << " floats to " << frame_pos << endl;
        
        if (write_float (data, frame_pos, cnt) != cnt) {
                return 0;
@@ -396,6 +398,8 @@ SndFileSource::nondestructive_write_unlocked (Sample *data, nframes_t cnt)
        oldlen = _length;
        update_length (oldlen, cnt);
 
+       cerr << "\t length is now " << _length << endl;
+
        if (_build_peakfiles) {
                PeakBuildRecord *pbr = 0;