Permalink
Browse files

o Found a project name: "Folve". Some renamings because of that.

  • Loading branch information...
1 parent 0aee3bb commit a9d3e538bf852c72e77521b55c25e4febfc3b479 @hzeller committed Sep 16, 2012
View
@@ -5,11 +5,11 @@ CFLAGS=-D_FILE_OFFSET_BITS=64 -Wall -O2
CXXFLAGS=$(CFLAGS)
LDFLAGS=-lfuse -lsndfile -lzita-convolver -lmicrohttpd
-OBJECTS = fuse-convolve.o convolver.o conversion-buffer.o \
+OBJECTS = folve-main.o folve-filesystem.o conversion-buffer.o \
file-handler-cache.o status-server.o util.o \
zita-audiofile.o zita-config.o zita-fconfig.o zita-sstring.o
-fuse-convolve: $(OBJECTS)
+folve: $(OBJECTS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
clean:
View
34 README
@@ -1,15 +1,41 @@
-A fuse filesystem that takes an original path to a directory with flac-files
-and provides these files that are convolved on the fly using the zita convolver
-(usually used in jconvolve).
+ Folve - Fuse Convolve
+ A fuse filesystem with on-the-fly convolving of sound files
+
+This fuse filesystem takes an original path to a directory with flac-files
+and provides these files at the mount point. Accessing sound files will
+automatically convolve these on-the-fly using the zita convolver by
+Fons Adriaensen (Files in this directory starting with zita-* are imported
+from his jconvolver project to parse the same configuration files).
+
+This solves the problem that many media servers don't provide a convolving
+option and their only interface to the outside world is to access a file
+system.
+Also in general the beauty of simply accessing files to convolve is very
+useful and allows for simple experiments.
+
+This project is based on
+Fuse: Filesystem in Userspace http://fuse.sourceforge.net/
+JConvolver Jack audio convolver http://apps.linuxaudio.org/apps/all/jconvolver
+
+Folve has been tested with various players and music servers (and
+workes around bugs in these). Still, this is the first version made public, so
+you should expect rough edges.
=== To compile on Ubuntu ===
+ This requires the latest versions of libfuse and libzita convolver to compile.
+ .. and a couple of other libs:
+
$ sudo aptitude install libsndfile-dev libflac-dev libzita-convolver-dev libfuse-dev fftw3-dev libboost-dev libmicrohttpd-dev
$ make
=== Run ===
- ./fuse-convolve /directory/with/filters /path/to/original/fileystem /mnt/mountpoint -f
+ Fuse convolve 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:
+
+ ./fuse-convolve /directory/with/filters /path/to/original/files /mnt/mountpoint -f
Parameters:
1) The /directory/with/filters needs to be a directory that has
View
@@ -13,6 +13,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#include "conversion-buffer.h"
+
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@@ -21,16 +23,14 @@
#include <sys/types.h>
#include <unistd.h>
-#include "conversion-buffer.h"
-
ConversionBuffer::ConversionBuffer(SoundSource *source, const SF_INFO &info)
- : source_(source), tmpfile_(-1), snd_writing_enabled_(true),
+ : source_(source), tmpfile_filedes_(-1), snd_writing_enabled_(true),
total_written_(0), header_end_(0) {
// We need to be able to skip backwards but we don't want to fill our
// memory. So lets create a temporary file.
- const char *filename = tempnam(NULL, "fuse-");
- tmpfile_ = open(filename, O_RDWR|O_CREAT|O_NOATIME, S_IRUSR|S_IWUSR);
- if (tmpfile_ < 0) {
+ const char *filename = tempnam(NULL, "folve");
+ tmpfile_filedes_ = open(filename, O_RDWR|O_CREAT|O_NOATIME, S_IRUSR|S_IWUSR);
+ if (tmpfile_filedes_ < 0) {
perror("Problem opening buffer file");
}
unlink(filename);
@@ -40,7 +40,7 @@ ConversionBuffer::ConversionBuffer(SoundSource *source, const SF_INFO &info)
}
ConversionBuffer::~ConversionBuffer() {
- close(tmpfile_);
+ close(tmpfile_filedes_);
}
sf_count_t ConversionBuffer::SndTell(void *userdata) {
@@ -81,12 +81,12 @@ SNDFILE *ConversionBuffer::CreateOutputSoundfile(const SF_INFO &out_info) {
}
ssize_t ConversionBuffer::Append(const void *data, size_t count) {
- if (tmpfile_ < 0) return -1;
+ if (tmpfile_filedes_ < 0) return -1;
//fprintf(stderr, "Extend horizon by %ld bytes.\n", count);
int remaining = count;
const char *buf = (const char*)data;
while (remaining > 0) {
- int w = write(tmpfile_, data, count);
+ int w = write(tmpfile_filedes_, data, count);
if (w < 0) return -errno;
remaining -= w;
buf += w;
@@ -96,8 +96,8 @@ ssize_t ConversionBuffer::Append(const void *data, size_t count) {
}
void ConversionBuffer::WriteCharAt(unsigned char c, off_t offset) {
- if (tmpfile_ < 0) return;
- if (pwrite(tmpfile_, &c, 1, offset) != 1) fprintf(stderr, "mmh");
+ if (tmpfile_filedes_ < 0) return;
+ if (pwrite(tmpfile_filedes_, &c, 1, offset) != 1) fprintf(stderr, "Oops.");
}
ssize_t ConversionBuffer::SndAppend(const void *data, size_t count) {
@@ -123,20 +123,12 @@ ssize_t ConversionBuffer::Read(char *buf, size_t size, off_t offset) {
// required_min_written = offset + size; // all requested bytes.
const off_t required_min_written = offset + (offset >= header_end_ ? size : 1);
- // Skipping the file looks like reading beyond what the user already
- // consumed. Print this as diagnostic message.
-#if 0
- if (total_written_ + 1 < offset) {
- fprintf(stderr, "(skip> %ld -> %ld)", total_written_, offset);
- }
-#endif
-
// 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())
break;
}
- return pread(tmpfile_, buf, size, offset);
+ return pread(tmpfile_filedes_, buf, size, offset);
}
View
@@ -1,3 +1,4 @@
+// -*- c++ -*-
// Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
//
// This program is free software; you can redistribute it and/or modify
@@ -13,14 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#ifndef FOLVE_CONVERSION_BUFFER_H
+#define FOLVE_CONVERSION_BUFFER_H
+
#include <sndfile.h>
// A file-backed buffer for a SNDFILE, that is only filled on demand via
// a SoundSource.
// If Read() is called beyond the current available data, a callback is
// called to write more into the SNDFILE.
class ConversionBuffer {
- public:
+public:
// SoundSource, a instance of which needs to be passed to the
// ConversionBuffer.
class SoundSource {
@@ -35,27 +39,28 @@ class ConversionBuffer {
// sf_close() the file.
virtual void SetOutputSoundfile(ConversionBuffer *parent,
SNDFILE *sndfile) = 0;
-
+
// 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;
};
- // Create a conversion buffer that holds "buffer_size" bytes.
- // The "source" will be informed to what SNDFILE to write to and whenever
- // this ConversionBuffer lusts for more data (it then calls
- // AddMoreSoundData()).
+ // Create a conversion buffer providing an sound output described in
+ // "out_info".
+ // The "source" will be called back whenever this conversion buffer needs
+ // more data.
+ //
// Ownership is not taken over for source.
- ConversionBuffer(SoundSource *source, const SF_INFO &info);
+ ConversionBuffer(SoundSource *source, const SF_INFO &out_info);
~ConversionBuffer();
// Read data from buffer. Can block and call the SoundSource first to get
// more data if needed.
ssize_t Read(char *buf, size_t size, off_t offset);
// Append data. Usually called via the SndWrite() virtual-SNFFILE callback,
- // but can be used to write raw data as well.
+ // but can be used to write raw data as well (e.g. to write headers).
ssize_t Append(const void *data, size_t count);
// Write at a particular position. Writes a single character - this is
@@ -70,17 +75,17 @@ class ConversionBuffer {
bool sndfile_writes_enabled() const { return snd_writing_enabled_; }
// Tell conversion buffer when we're done writing the header. It needs to
- // know to do some buffer trickery.
+ // know so that it can serve reads in these different regions differently.
+ // (Long story, see Read() for details).
void HeaderFinished();
// Current max file position.
off_t FileSize() const { return total_written_; }
- private:
+private:
static sf_count_t SndTell(void *userdata);
static sf_count_t SndWrite(const void *ptr, sf_count_t count, void *userdata);
-
// Append for the SndWrite callback.
ssize_t SndAppend(const void *data, size_t count);
@@ -89,8 +94,10 @@ class ConversionBuffer {
SNDFILE *CreateOutputSoundfile(const SF_INFO &info);
SoundSource *const source_;
- int tmpfile_;
+ int tmpfile_filedes_;
bool snd_writing_enabled_;
off_t total_written_;
off_t header_end_;
};
+
+#endif // FOLVE_CONVERSION_BUFFER_H
View
@@ -46,7 +46,7 @@ FileHandler *FileHandlerCache::InsertPinned(const std::string &key,
if (cache_.size() > max_size_) {
CleanupOldestUnreferenced_Locked();
}
- ins->second->last_access = fuse_convolve::CurrentTime();
+ ins->second->last_access = folve::CurrentTime();
if (observer_) observer_->InsertHandlerEvent(ins->second->handler);
return ins->second->handler;
}
@@ -57,7 +57,7 @@ FileHandler *FileHandlerCache::FindAndPin(const std::string &key) {
if (found == cache_.end())
return NULL;
++found->second->references;
- found->second->last_access = fuse_convolve::CurrentTime();
+ found->second->last_access = folve::CurrentTime();
return found->second->handler;
}
View
@@ -14,20 +14,24 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#ifndef _FUSE_CONVOLVER_FILE_HANDLER_CACHE_H
-#define _FUSE_CONVOLVER_FILE_HANDLER_CACHE_H
+#ifndef FOLVE_FILE_HANDLER_CACHE_H
+#define FOLVE_FILE_HANDLER_CACHE_H
#include <time.h>
#include <map>
-#include <vector>
#include <string>
+#include <vector>
+
#include <boost/thread/mutex.hpp>
+#include "file-handler.h"
+
class FileHandler;
-// Cache of in-use file handlers. We sometimes get multiple requests for the
-// same file, so we want to map them all to the same FileHandler.
+// Cache of in-use file handlers. We sometimes get multiple open()/close()
+// request for the same file by some programs. Also, some constantly monitor
+// the file-size while the file is open.
//
// This Cache manages the lifecycle of a FileHandler object; the user creates
// it, but this Cache handles deletion.
@@ -48,12 +52,12 @@ class FileHandlerCache {
// Insert a new object under the given key.
// Ownership is handed over to this map.
- // If there was already an object stored under that key, that is returned
- // instead and the new object discarded.
+ // If there was already an object stored under that key, the existing one
+ // is returned instead and the passed object discarded.
FileHandler *InsertPinned(const std::string &key, FileHandler *handler);
- // Find an object in this map and pin it down. You've to Unpin() it after
- // use.
+ // Find an object in this map and pin it down so that it is not evicted.
+ // You've to Unpin() it after use.
FileHandler *FindAndPin(const std::string &key);
// Unpin object. If the last object is unpinned, the PinnedMap may decide
@@ -82,4 +86,4 @@ class FileHandlerCache {
CacheMap cache_;
};
-#endif // _FUSE_CONVOLVER_FILE_HANDLER_CACHE_H
+#endif // FOLVE_FILE_HANDLER_CACHE_H
View
@@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#ifndef _FUSE_CONVOLVER_FILE_HANDLER_H
-#define _FUSE_CONVOLVER_FILE_HANDLER_H
+#ifndef FOLVE_FILE_HANDLER_H
+#define FOLVE_FILE_HANDLER_H
#include <string>
@@ -32,6 +32,11 @@ struct HandlerStats {
double last_access;
};
+// A handler that deals with operations on files. Since we only provide read
+// access, this is limited to very few operations.
+// Closing in particular is not done by this file handler as it might
+// have a longer life-time than an open()/close() cycle we get from the
+// fuse filesystem (see file-handler-cache.h for rationale)
class FileHandler {
public:
virtual ~FileHandler() {}
@@ -44,4 +49,4 @@ class FileHandler {
virtual void GetHandlerStatus(struct HandlerStats *s) = 0;
};
-#endif // _FUSE_CONVOLVER_FILE_HANDLER_H
+#endif // FOLVE_FILE_HANDLER_H
Oops, something went wrong.

0 comments on commit a9d3e53

Please sign in to comment.