Permalink
Browse files

o implement initial skip mode detection.

  • Loading branch information...
1 parent 51c305b commit f11d8cdf789e5a5a89f38b684bb54a2f8844c13a @hzeller committed Sep 12, 2012
Showing with 24 additions and 18 deletions.
  1. +9 −13 conversion-buffer.cc
  2. +1 −1 conversion-buffer.h
  3. +14 −4 convolver.cc
View
@@ -119,24 +119,20 @@ ssize_t ConversionBuffer::Read(char *buf, size_t size, off_t offset) {
// consumed. Right now, we have to fill the buffer up to that point, but
// we might need to find a shortcut for that: some programs just skip to the
// end of the file apparently - which makes us convolve the while file.
- const bool looks_like_skipping = total_written_ + 1 < offset;
- const size_t initial_written = total_written_;
+ if (total_written_ + 1 < offset) {
+ fprintf(stderr, "(skip> %ld -> %ld)", total_written_, offset);
+ }
// As soon as someone tries to read beyond of what we already have, we call
// our WriteToSoundfile() callback that fills more of it.
while (total_written_ < required_min_written) {
- if (!source_->AddMoreSoundData())
+ // We skip up until 32k before the requested start-offset.
+ // TODO(hzeller): remember that the skipped parts are actually not convolved
+ // so if someone skips back we know that we need to re-do that.
+ const bool skip_mode = total_written_ + (32 << 10) < offset;
+ if (!source_->AddMoreSoundData(skip_mode))
break;
}
- const ssize_t result = pread(tmpfile_, buf, size, offset);
-
- if (looks_like_skipping) {
- fprintf(stderr, "File skipping: "
- "From %ld -> %ld to read %ld bytes (got %ld)"
- "(and we filtered all that audio data in-between .. in vain)\n",
- initial_written, offset, size, result);
- }
-
- return result;
+ return pread(tmpfile_, buf, size, offset);
}
View
@@ -38,7 +38,7 @@ class ConversionBuffer {
// This callback is called by the ConversionBuffer if it needs more data.
// Rerturns 'true' if there is more, 'false' if that was the last available
// data.
- virtual bool AddMoreSoundData() = 0;
+ virtual bool AddMoreSoundData(bool in_skip_mode) = 0;
};
// Create a conversion buffer that holds "buffer_size" bytes.
View
@@ -153,7 +153,7 @@ class SndFileFilter :
// If the input was ogg, we're re-coding this to flac, because it
// wouldn't let us stream the output.
out_info.format = SF_FORMAT_FLAC;
- out_info.format |= (in_info.format & SF_FORMAT_SUBMASK);
+ out_info.format |= SF_FORMAT_PCM_16;
}
else if ((in_info.format & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV
&& (in_info.format & SF_FORMAT_SUBMASK) != SF_FORMAT_PCM_16) {
@@ -198,23 +198,33 @@ class SndFileFilter :
out_buffer->HeaderFinished();
}
- virtual bool AddMoreSoundData() {
+ virtual bool AddMoreSoundData(bool in_skip_mode) {
if (!input_frames_left_)
return false;
if (!zita_.convproc) {
// First time we're called.
zita_.convproc = new Convproc();
- raw_sample_buffer_ = new float[zita_.fragm * channels_];
config(&zita_, config_path_.c_str());
+ raw_sample_buffer_ = new float[zita_.fragm * channels_];
zita_.convproc->start_process(0, 0);
fprintf(stderr, "Convolver initialized; chunksize=%d\n", zita_.fragm);
}
int r = sf_readf_float(snd_in_, raw_sample_buffer_, zita_.fragm);
if (r == (int) zita_.fragm) {
- fprintf(stderr, ".");
+ fprintf(stderr, "%s", in_skip_mode ? "x" : ".");
} else {
fprintf(stderr, "[%d]", r);
}
+ if (in_skip_mode) {
+ // If someone skips forward we don't do any encoding. That should
+ // be faster, but skipping back will be dangerous: we haven't actually
+ // encoded that part of the data. So we need to remember that this is
+ // a no-go area. mmh.
+ sf_writef_float(snd_out_, raw_sample_buffer_, r);
+ input_frames_left_ -= r;
+ return input_frames_left_;
+ }
+
if (r < (int) zita_.fragm) {
// Zero out the rest of the buffer.
const int missing = zita_.fragm - r;

0 comments on commit f11d8cd

Please sign in to comment.