Skip to content
Browse files

o Match filters in sequence

   1. filter-<samplerate>-<channels>-<bits>.conf
   2. filter-<samplerate>-<channels>.conf
   3. filter-<samplerate>.conf
  • Loading branch information...
1 parent 23b24f0 commit 3e883b7355ec4e59d0c69fc5a37482ea7af3b29e @hzeller committed Sep 18, 2012
Showing with 75 additions and 32 deletions.
  1. +19 −20 README
  2. +33 −6 folve-filesystem.cc
  3. +18 −5 util.cc
  4. +5 −1 util.h
View
39 README
@@ -64,31 +64,31 @@ Microhttpd webserver library http://www.gnu.org/software/libmicrohttpd/
=== Run ===
Since there is no 'make install' yet, let's run it from the local directory.
- Folve requires three parameters: the first is directory to filter
- configurations, the second the directory to the original flac files. The
- third is the mount-point, where the convolved flac files will show up:
+ Folve requires at least two parameters: the directory where your original
+ *.flac files reside and the mount point of this filesystem.
+ Also, do be useful, you need to supply at least one configuration directory
+ with the -c <config-dir> option. Very useful is the -p <port> that starts
+ an HTTP server.
- ./folve -c /filter/dir -f -p 17322 /path/to/original/files /mnt/mountpoint
+ ./folve -c /filter/dir -p 17322 /path/to/original/files /mnt/mountpoint
-Parameters:
- 1) The flag '-c' with parameter /filter/dir needs to be a
- directory that has
- jconvolver filter-configuration files with the following naming scheme:
+The configuration directory should contain configuration files as they're
+found in jconvolver, with the following naming scheme:
- filter-<samplerate>-<bits>-<channels>.conf
+ filter-<samplerate>-<channels>-<bits>.conf OR
+ filter-<samplerate>-<channels>.conf OR
+ filter-<samplerate>.conf
- So if you have flac files with 44.1khz, 16 bits and 2 channel stero,
- you need a filter configuration named:
+So if you have flac files with 44.1kHz, 16 bits and 2 channel stero,
+you need a filter configuration named one of these (in matching sequence):
- /filter/dir/filter-44100-16-2.conf
+ /filter/dir/filter-44100-2-16.conf OR
+ /filter/dir/filter-44100-2.conf OR
+ /filter/dir/filter-44100.conf
- (See README.CONFIG in the jconfolver project how these look like)
+The files are searched from the most specific to the least specific type.
- 2) The original directory that contains your collection of audio files.
- Right now, *.flac files are directly supported; others are attempted
- to read and write out as the same format (libsndfile)
-
- 3) The mount point.
+(See README.CONFIG in the jconvolver project how these look like)
General usage:
usage: ./folve [options] <original-dir> <mount-point>
@@ -109,8 +109,7 @@ The fuse-convolve filesystem will determine the samplerate/bits/channels and
attempt to find the right filter in the filter directory. If there is a filter,
the output is filtered on-the-fly, otherwise the original file is returned.
-
-If you gave folve the flag -p with an status port, it will serve current
+If you gave Folve the flag -p with an status port, it will serve current
status information on a http server; e.g. With ./folve ... -p 17322 have a look
on
http://localhost:17322/
View
39 folve-filesystem.cc
@@ -40,6 +40,7 @@
#include "zita-config.h"
using folve::Appendf;
+using folve::StringPrintf;
static bool global_debug = false;
@@ -82,6 +83,17 @@ class PassThroughFilter : public FileHandler {
HandlerStats info_stats_;
};
+static bool FindFirstAccessiblePath(const std::vector<std::string> &path,
+ std::string *match) {
+ for (size_t i = 0; i < path.size(); ++i) {
+ if (access(path[i].c_str(), R_OK) == 0) {
+ *match = path[i];
+ return true;
+ }
+ }
+ return false;
+}
+
class SndFileHandler :
public FileHandler,
public ConversionBuffer::SoundSource {
@@ -114,17 +126,32 @@ class SndFileHandler :
in_info.samplerate / 1000.0, bits);
partial_file_info->duration_seconds = in_info.frames / in_info.samplerate;
+ std::vector<std::string> path_choices;
+ // From specific to non-specific.
+ path_choices.push_back(StringPrintf("%s/filter-%d-%d-%d.conf",
+ zita_config_dir.c_str(),
+ in_info.samplerate,
+ in_info.channels, bits));
+ path_choices.push_back(StringPrintf("%s/filter-%d-%d.conf",
+ zita_config_dir.c_str(),
+ in_info.samplerate,
+ in_info.channels));
+ path_choices.push_back(StringPrintf("%s/filter-%d.conf",
+ zita_config_dir.c_str(),
+ in_info.samplerate));
+ const int max_choice = path_choices.size() - 1;
std::string config_path;
- Appendf(&config_path, "%s/filter-%d-%d-%d.conf", zita_config_dir.c_str(),
- in_info.samplerate, bits, in_info.channels);
- const bool found_config = (access(config_path.c_str(), R_OK) == 0);
+ const bool found_config = FindFirstAccessiblePath(path_choices,
+ &config_path);
if (found_config) {
DebugLogf("File %s: filter config %s", underlying_file,
config_path.c_str());
} else {
- syslog(LOG_ERR, "File %s: couldn't find filter config %s",
- underlying_file, config_path.c_str());
- partial_file_info->message = "Missing [" + config_path + "]";
+ syslog(LOG_ERR, "File %s: couldn't find filter config %s...%s",
+ underlying_file,
+ path_choices[0].c_str(), path_choices[max_choice].c_str());
+ partial_file_info->message = "Missing ( " + path_choices[0]
+ + "<br/> ... " + path_choices[max_choice] + " )";
sf_close(snd);
return NULL;
}
View
23 util.cc
@@ -25,13 +25,26 @@ double folve::CurrentTime() {
return tv.tv_sec + tv.tv_usec / 1e6;
}
-void folve::Appendf(std::string *str, const char *format, ...) {
- va_list ap;
+static void vAppendf(std::string *str, const char *format, va_list ap) {
const size_t orig_len = str->length();
- const size_t space = 1024;
+ const size_t space = 1024; // there should be better ways to do this...
str->resize(orig_len + space);
- va_start(ap, format);
int written = vsnprintf((char*)str->data() + orig_len, space, format, ap);
- va_end(ap);
str->resize(orig_len + written);
}
+
+void folve::Appendf(std::string *str, const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ vAppendf(str, format, ap);
+ va_end(ap);
+}
+
+std::string folve::StringPrintf(const char *format, ...) {
+ std::string result;
+ va_list ap;
+ va_start(ap, format);
+ vAppendf(&result, format, ap);
+ va_end(ap);
+ return result;
+}
View
6 util.h
@@ -27,7 +27,11 @@ namespace folve {
// Like snprintf, but print to a std::string instead.
void Appendf(std::string *str, const char *format, ...)
__attribute__ ((format (printf, 2, 3)));
-
+
+ // Convenience, that returns a string directly. A bit less efficient than
+ // Appendf().
+ std::string StringPrintf(const char *format, ...)
+ __attribute__ ((format (printf, 1, 2)));
} // namespece fuse_convolve
#endif // FOLVE_UTIL_H

0 comments on commit 3e883b7

Please sign in to comment.
Something went wrong with that request. Please try again.