From 1ed9a80f26a82ef36c303b8a98bef131a42fe35b Mon Sep 17 00:00:00 2001 From: William Toohey Date: Thu, 23 Mar 2017 22:46:35 +1000 Subject: [PATCH] Working preview trim --- 2dxWav.c | 16 ++++++++-------- 2dxWavConvert.c | 10 +++++++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/2dxWav.c b/2dxWav.c index c98c40f..e9985f8 100644 --- a/2dxWav.c +++ b/2dxWav.c @@ -110,24 +110,24 @@ int convert_wav(char* inFile, char* outWav, int trimPreview) { assert(sox_add_effect(chain, e, &interm_signal, &out->signal) == SOX_SUCCESS); free(e); } - - if (in->signal.channels != out->signal.channels) { - e = sox_create_effect(sox_find_effect("channels")); - assert(sox_effect_options(e, 0, NULL) == SOX_SUCCESS); - assert(sox_add_effect(chain, e, &interm_signal, &out->signal) == SOX_SUCCESS); - free(e); - } // Only use 10 seconds of audio for previews if(trimPreview) { e = sox_create_effect(sox_find_effect("trim")); args[0] = "0"; args[1] = "10"; - assert(sox_effect_options(e, 1, args) == SOX_SUCCESS); + assert(sox_effect_options(e, 2, args) == SOX_SUCCESS); assert(sox_add_effect(chain, e, &interm_signal, &in->signal) == SOX_SUCCESS); free(e); } + if (in->signal.channels != out->signal.channels) { + e = sox_create_effect(sox_find_effect("channels")); + assert(sox_effect_options(e, 0, NULL) == SOX_SUCCESS); + assert(sox_add_effect(chain, e, &interm_signal, &out->signal) == SOX_SUCCESS); + free(e); + } + e = sox_create_effect(sox_find_effect("output")); args[0] = (char *)out; assert(sox_effect_options(e, 1, args) == SOX_SUCCESS); diff --git a/2dxWavConvert.c b/2dxWavConvert.c index 8416735..2d31652 100644 --- a/2dxWavConvert.c +++ b/2dxWavConvert.c @@ -1,18 +1,22 @@ #include #include #include +#include #include "shared.h" #include "2dxWav.h" int main(int argc, char * argv[]) { - if(argc != 3) { - printf("2dxWavConvert infile outwav\n"); + if(argc != 3 && argc != 4) { + printf("2dxWavConvert infile outwav [preview]\n"); return 1; } + int preview = 0; + if(argc == 4 && !strcmp("preview", argv[3])) + preview = 1; - if(convert_wav(argv[1], argv[2], 0)) { + if(convert_wav(argv[1], argv[2], preview)) { printf("Conversion failed!\n"); return 1; }