Permalink
Browse files

Fix bug: the last couple of sound-samples were not flushed. We want

to avoid that sndfile messes with our header, so we switched off
writing on close(); However, at this point, sndfile might not have
flushed the last couple of sound-samples.

So now, we switch off writing when we start seeking the Seek() to
the beginning of the file.
  • Loading branch information...
1 parent 38cdeb1 commit 0b0bd3382348ef1ee5e46819677e20f549ced66d @hzeller committed Sep 21, 2012
Showing with 17 additions and 9 deletions.
  1. +7 −6 conversion-buffer.cc
  2. +10 −3 folve-filesystem.cc
View
@@ -53,13 +53,14 @@ sf_count_t ConversionBuffer::SndWrite(const void *ptr, sf_count_t count,
// These callbacks we don't care about.
static sf_count_t DummySeek(sf_count_t offset, int whence, void *userdata) {
- // This seems to be called after we're closing, probably to modify the
- // header. It then actually attempts to write, but we're already not
- // sndfile write enabled. So print this as a warning if we're write enabled,
+ // This seems to be called while closing, probably to modify the
+ // header. But we already have a custom header, so we need to avoid writing
+ // to that position. So as soon as we see this, disable writing,
// because it would mess up the file.
- if (offset > 0 &&
- reinterpret_cast<ConversionBuffer*>(userdata)->sndfile_writes_enabled()) {
- fprintf(stderr, "DummySeek called %lld\n", (long long int) offset);
+ if (offset > 0) {
+ reinterpret_cast<ConversionBuffer*>(userdata)
+ ->set_sndfile_writes_enabled(false);
+ //fprintf(stderr, "Skipping seek to %lld\n", (long long int) offset);
}
return 0;
}
View
@@ -45,7 +45,10 @@ using folve::StringPrintf;
static bool global_debug = false;
-static void DebugLogf(const char *format, ...) {
+static void DebugLogf(const char *format, ...)
+ __attribute__ ((format (printf, 1, 2)));
+
+void DebugLogf(const char *format, ...) {
if (!global_debug) return;
va_list ap;
va_start(ap, format);
@@ -140,12 +143,15 @@ class SndFileHandler :
path_choices.push_back(StringPrintf("%s/filter-%d.conf",
zita_config_dir.c_str(),
in_info.samplerate));
+ const int seconds = in_info.frames / in_info.samplerate;
const int max_choice = path_choices.size() - 1;
std::string config_path;
const bool found_config = FindFirstAccessiblePath(path_choices,
&config_path);
if (found_config) {
- DebugLogf("File %s: filter config %s", underlying_file,
+ DebugLogf("File %s, %.1fkHz, %d Bit, %d:%02d: filter config %s",
+ underlying_file, in_info.samplerate / 1000.0, bits,
+ seconds / 60, seconds % 60,
config_path.c_str());
} else {
DebugLogf("File %s: couldn't find filter config %s...%s",
@@ -439,7 +445,8 @@ class SndFileHandler :
base_stats_.filename.c_str(), processor_->max_output_value(),
1.0 / processor_->max_output_value(), config_path_.c_str());
}
- output_buffer_->set_sndfile_writes_enabled(false);
+ // We can't disable buffer writes here, because outfile closing will flush
+ // the last couple of sound samples.
if (snd_in_) sf_close(snd_in_);
if (snd_out_) sf_close(snd_out_);
snd_out_ = NULL;

0 comments on commit 0b0bd33

Please sign in to comment.