aboutsummaryrefslogtreecommitdiffhomepage
path: root/sndfile.lua
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2016-01-24 23:07:22 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2016-01-25 03:53:53 +0100
commiteda65ceed1c087b64c0cc7a7f5dce3e76b6c62de (patch)
tree4a35c3b77fd9924843c3deb042be8b319a13432c /sndfile.lua
parent1579f7c0df91df4581c1096448dde8cf9afddb49 (diff)
downloadapplause2-eda65ceed1c087b64c0cc7a7f5dce3e76b6c62de.tar.gz
multi-channel stream support
* This is implemented without introducing the notion of frames into the tick() methods since most multi-channel stream operations can be understood as duplicating the operation on each channel. * Instead there is only ONE explicitly multi-channel stream: MuxStream. It can be used to construct a multi-channel stream from various normal mono streams and is also used internally. * MuxStreams can still be used just like any other stream since the new base class MuxableStream will automatically apply the class constructors on each channel in order. The channels of streams being combined must be equal, unless mono streams are involved. * Mono-streams are automatically blown-up to multi-channel streams when involved in operations with a multi-channel stream. * The remaining multi-channel specific code has been isolated in Stream:foreach() which now receives frames instead of individual samples. * When playing() a multi-channel stream, the applause output ports are played in order. I.e. playing a mono-stream fills output_1. A stereo stream, output_1 and output_2. * The number of Jack output ports can be specified on the applause command line. * All system playback ports are tried to be connected to corresponding applause output ports.
Diffstat (limited to 'sndfile.lua')
-rw-r--r--sndfile.lua17
1 files changed, 14 insertions, 3 deletions
diff --git a/sndfile.lua b/sndfile.lua
index 47ea1ff..e91fb70 100644
--- a/sndfile.lua
+++ b/sndfile.lua
@@ -119,19 +119,22 @@ const char* sf_strerror(SNDFILE *sndfile);
int sf_command(SNDFILE *sndfile, int command, void *data, int datasize);
-sf_count_t sf_read_double(SNDFILE *sndfile, double *ptr, sf_count_t items) ;
+sf_count_t sf_read_double(SNDFILE *sndfile, double *ptr, sf_count_t items);
+sf_count_t sf_readf_double(SNDFILE *sndfile, double *ptr, sf_count_t frames);
+
sf_count_t sf_write_double(SNDFILE *sndfile, const double *ptr, sf_count_t items);
+sf_count_t sf_writef_double(SNDFILE *sndfile, const double *ptr, sf_count_t frames);
int sf_close(SNDFILE *sndfile);
]]
local lib = ffi.load("sndfile")
-local double_type = ffi.typeof("double[?]")
+sndfile.frame_type = ffi.typeof("double[?]")
-- This can be reused in sndfile:read() and sndfile:write()
-- to avoid allocations.
-local double_buffer = double_type(1)
+local double_buffer = sndfile.frame_type(1)
-- NOTE: Constants are also in ffi.C
sndfile.SF_FORMAT = ffi.typeof("SF_FORMAT")
@@ -196,12 +199,20 @@ function sndfile:read()
tonumber(double_buffer[0]) or nil
end
+function sndfile:readf(frame)
+ return lib.sf_readf_double(self.handle, frame, 1) == 1
+end
+
-- TODO: Maybe support writing multiple samples at once
function sndfile:write(sample)
double_buffer[0] = sample
return lib.sf_write_double(self.handle, double_buffer, 1)
end
+function sndfile:writef(frame)
+ return lib.sf_writef_double(self.handle, frame, 1)
+end
+
function sndfile:close()
if self.handle then
lib.sf_close(self.handle)