--- Begin Message ---
Package: lv2file
Version: 0.83-1
Severity: wishlist
Tags: patch
This allows lv2file to be used in a pipeline with other programs
which work with raw floating point audio data, such as sox and
ecasound.
An example using sox and sc4 is below:
sox -V3 foo.flac -tf32 -r48000 - \
| lv2file -i - -o - -r48000 -n2 \
-c 1:left_in -c 2:right_in \
-p attack:5 -p release:5 \
-p threshold:-6 -p makeup_gain:5 -p knee:6 -p ratio:2 \
http://plugin.org.uk/swh-plugins/sc4 \
| sox -r48000 -t f32 -c2 - -b16 -r 48000 foo.ogg
This can be useful for real-time playback systems using
sox/ecasound, such as dtas-player in dtas <http://dtas.80x24.org/>
>From 61a2f330c030544055c4f546966254722363e063 Mon Sep 17 00:00:00 2001
From: Eric Wong <[email protected]>
Date: Sun, 6 Oct 2013 04:00:48 +0000
Subject: [PATCH] allow piping raw FP audio from stdin to stdout
This allows lv2file to be used in a pipeline with other programs
which work with raw floating point audio data, such as sox and
ecasound.
An example using sox and sc4 is below:
sox -V3 foo.flac -tf32 -r48000 - \
| lv2file -i - -o - -r48000 -n2 \
-c 1:left_in -c 2:right_in \
-p attack:5 -p release:5 \
-p threshold:-6 -p makeup_gain:5 -p knee:6 -p ratio:2 \
http://plugin.org.uk/swh-plugins/sc4 \
| sox -r48000 -t f32 -c2 - -b16 -r 48000 foo.ogg
This can be useful for real-time playback systems using
sox/ecasound, such as dtas-player in dtas <http://dtas.80x24.org/>
---
README | 9 +++++++++
debian/lv2file.1 | 10 ++++++++++
lv2file.c | 33 ++++++++++++++++++++++++++++++---
3 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/README b/README
index 65a589a..299f802 100644
--- a/README
+++ b/README
@@ -19,6 +19,8 @@ lv2file --nameports PLUGIN
lv2file -i IFILE -o OFILE -c CHANNEL:PORT -p PORT:VALUE PLUGIN
* Applies the PLUGIN to to IFILE and outputs the results to OFILE.
+lv2file -i - -o - -r RATE -n CHANNELS -c CHANNEL:PORT -p PORT:VALUE PLUGIN
+ * read raw 32-bit floating point samples of sample rate RATE and CHANNELS from stdin and output to stdout.
==Example==
lv2file -c 1:voice -p pitch_correction:1 -i speechsample.wav -o outfile.wav http://hyperglitch.com/dev/VocProc
@@ -45,5 +47,12 @@ You should note that because lv2file uses LV2 plugins, the VALUES will always be
===-b===
The option -b, or --blocksize, controls the size of the chunks the audio is processed in. Larger sizes may be slightly faster, but will use more memory. The default is 512 frames.
+===-n===
+
+The option -n should be used to specify the input/output channel count to read from stdin and write to stdout. This must be combined with -r/--rate
+
+===-r==
+The option -r should be used to specify the input/output sample rate when reading from stdin and writing to stdout. This must be combined with -n/--channels.
+
===--ignore-clipping===
By default, lv2file will check every sample for clipping and will warn the user if any clipping occurs. However, if know that the effect won't produce clipping, or you don't care if it does, you can use this option to turn off the check for clipping. This will make lv2file run slightly faster.
diff --git a/debian/lv2file.1 b/debian/lv2file.1
index 80405f3..56eb9ad 100644
--- a/debian/lv2file.1
+++ b/debian/lv2file.1
@@ -60,9 +60,19 @@ List all the input and control ports for the specified plugin.
.TP
.B \-i \fIFILE\fR
Input the audio from a given FILE. Most common sampled audio formats are supported.
+If "-" is given and "--channels" and "--rate" are both specified, then input
+will be read as raw, 32-bit floating point samples from stdin.
.TP
.B \-o \fIFILE\fR
Output to given FILE.
+If "-" is given and "--channels" and "--rate" are both specified, then output
+will be written as raw, 32-bit floating point samples to stdout.
+.TP
+.B \-n, \-\-channels \fICHANNELS\fR
+Specify the channel count when reading from stdin and writing to stdout.
+.TP
+.B \-r, \-\-rate \fIRATE\fR
+Specify the sample rate reading from stdin and writing to stdout.
.TP
.B \-c, \-\-connect \fICHANNEL\fR:\fIPORT\fR
Connect the channel CHANNEL in the input file to the audio port PORT of the plugin.
diff --git a/lv2file.c b/lv2file.c
index c63ee96..37857b9 100644
--- a/lv2file.c
+++ b/lv2file.c
@@ -1,3 +1,4 @@
+#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sndfile.h>
@@ -218,14 +219,18 @@ int main(int argc, char** argv) {
struct arg_file* infile = arg_file1("i", NULL,"input", "Input sound file");
struct arg_file* outfile = arg_file1("o", NULL,"output", "Output sound file");
+ struct arg_int* rate = arg_int0("r","--rate","<int>", "sample rate for raw float data");
+ struct arg_int* channels = arg_int0("n","--channels","<int>", "channel count for raw float data");
struct arg_rex* controls = arg_rexn("p", "parameters","(\\w+:\\w+,?)*","<controlport>:<float>",0,200,REG_EXTENDED, "Pass a value to a plugin control port.");
pluginname = arg_str1(NULL,NULL,"plugin","The LV2 URI of the plugin");
struct arg_int* blksize = arg_int0("b","blocksize","<int>","Chunk size in which the sound is processed. This is frames, not samples.");
struct arg_lit* mono = arg_lit0("m","mono","Mix all of the channels together before processing.");
struct arg_lit* ignore_clipping = arg_lit0(NULL,"ignore-clipping", "Do not check for clipping. This option is slightly faster");
blksize->ival[0]=512;
+ rate->ival[0]=-1;
+ channels->ival[0]=-1;
struct arg_end *endarg = arg_end(20);
- void *argtable[] = {infile, outfile,controls,connectargs,blksize,mono,ignore_clipping,pluginname, endarg};
+ void *argtable[] = {infile, outfile,rate,channels,controls,connectargs,blksize,mono,ignore_clipping,pluginname, endarg};
if (arg_nullcheck(argtable) != 0) {
fprintf(stderr,"Error: insufficient memory\n");
goto cleanup_argtable;
@@ -242,6 +247,11 @@ int main(int argc, char** argv) {
arg_print_glossary_gnu(stderr, argtable);
goto cleanup_argtable;
}
+ bool dopipe=(rate->ival[0]>0 && channels->ival[0]>0);
+ if ((rate->ival[0]<0 && channels->ival[0]>0) || (rate->ival[0]>0 && channels->ival[0]<0)) {
+ fprintf(stderr,"--rate/-r and --channels/-n must both be specified or not at all");
+ goto cleanup_argtable;
+ }
bool mixdown=mono->count;
@@ -252,7 +262,19 @@ int main(int argc, char** argv) {
}
SF_INFO formatinfo;
formatinfo.format=0;
- SNDFILE* insndfile=sf_open(*(infile->filename), SFM_READ, &formatinfo);
+ SNDFILE* insndfile;
+ if (dopipe) {
+ memset(&formatinfo, 0, sizeof(SF_INFO));
+ formatinfo.format=SF_FORMAT_FLOAT | SF_FORMAT_RAW | SF_ENDIAN_CPU;
+ formatinfo.samplerate=rate->ival[0];
+ formatinfo.channels=channels->ival[0];
+ }
+ if (dopipe && !strcmp(*(infile->filename),"-")) {
+ insndfile=sf_open_fd(STDIN_FILENO, SFM_READ, &formatinfo, 0);
+ } else {
+ insndfile=sf_open(*(infile->filename), SFM_READ, &formatinfo);
+ }
+
int sndfileerr=sf_error(insndfile) ;
if(sndfileerr) {
fprintf(stderr,"Error reading input file: %s\n",sf_error_number(sndfileerr));
@@ -320,7 +342,12 @@ int main(int argc, char** argv) {
goto cleanup_sndfile;
}
formatinfo.channels=numout;
- SNDFILE* outsndfile=sf_open(*(outfile->filename), SFM_WRITE, &formatinfo);
+ SNDFILE* outsndfile;
+ if (dopipe && !strcmp(*(outfile->filename),"-")) {
+ outsndfile=sf_open_fd(STDOUT_FILENO, SFM_WRITE, &formatinfo, 0);
+ } else {
+ outsndfile=sf_open(*(outfile->filename), SFM_WRITE, &formatinfo);
+ }
sndfileerr=sf_error(outsndfile) ;
if(sndfileerr) {
--
EW
--- End Message ---