KelvinJin/libsox-iOS

LibSox "pad" command not producing expected results in code objective c

AwaisFayyaz opened this issue · 1 comments

hi,

I am using the prebuilt version of libSox-iOS. I am trying to add silence to audio files using the 'pad' command. but this pad command is not producing expected output when i use it in my code. i have a mac app written in objective c.

however, on terminal the pad command works fine. i installed sox on terminal using home brew.

Am i missing something or the prebuilt version is old or broken ?

Here is my code

@try {
   static sox_format_t *in, *out; /* input and output files */
   sox_effects_chain_t * effectsChain;
   sox_effect_t * soxEffect;
   char *args[10];
   /* All libSoX applications must start by initialising the SoX library */
   assert(sox_init() == SOX_SUCCESS);
   //NSLog(@"path.fileSystemRepresentation %s",startInputDirectoryPath.fileSystemRepresentation);
   assert(in = sox_open_read(srcURL.fileSystemRepresentation, NULL, NULL, NULL));
   
   /* Open the output file; we must specify the output signal characteristics.
    * Since we are using only simple effects, they are the same as the input
    * file characteristics */
   
   //NSLog(@"path.fileSystemRepresentation %s",modifiedAudio.fileSystemRepresentation);
   assert(out = sox_open_write(dstURL.fileSystemRepresentation, &in->signal, NULL, NULL, NULL, NULL));
   
   /* Create an effects chain; some effects need to know about the input
    * or output file encoding so we provide that information here */
   effectsChain = sox_create_effects_chain(&in->encoding, &out->encoding);
   
   //* The first effect in the effect chain must be something that can source
   //* samples; in this case, we use the built-in handler that inputs
   //* data from an audio file */
   
   soxEffect = sox_create_effect(sox_find_effect("input"));
   (void)(args[0] = (char *)in), assert(sox_effect_options(soxEffect, 1, args) == SOX_SUCCESS);
   /* This becomes the first `effect' in the chain */
   assert(sox_add_effect(effectsChain, soxEffect, &in->signal, &in->signal) == SOX_SUCCESS);
   
   char *options[10];
   
   options[0] = ("0");
   options[1] = ("1");
   
   soxEffect = sox_create_effect(sox_find_effect("pad"));
   
   if(sox_effect_options(soxEffect, 2, options) != SOX_SUCCESS) {
     //                             on_error("silence1 effect options error!");
     //                            printf("silence1 effect options error!");
     NSLog(@"pad effect options error!");
   }
   if(sox_add_effect(effectsChain, soxEffect, &in->signal, &in->signal) != SOX_SUCCESS) {
     NSLog(@"pad add effect error");
     //          on_error("add effect error!");
   }
   free(soxEffect);
   
   

   /* The last effect in the effect chain must be something that only consumes
    * samples; in this case, we use the built-in handler that outputs
    * data to an audio file */
   
   
   soxEffect = sox_create_effect(sox_find_effect("output"));
   (void)(args[0] = (char *)out), assert(sox_effect_options(soxEffect, 1, args) == SOX_SUCCESS);
   assert(sox_add_effect(effectsChain, soxEffect, &out->signal, &out->signal) == SOX_SUCCESS);
   
   /* Flow samples through the effects processing chain until EOF is reached */
   sox_flow_effects(effectsChain, NULL, NULL);
   
   /* All done; tidy up: */
   sox_delete_effects_chain(effectsChain);
   sox_close(out);
   sox_close(in);
   sox_quit();
   //  });
   
   
 }@catch (NSException *exception) {
   NSLog(@"Error Occure During Trimming: %@", [exception description]);
   //    [self errorOccuredDuringFileTrim];
   //return NO;
 }

Sample project: https://github.com/AwaisFayyaz/Soxlib-iOS-Test

Sorry mate, I haven't touched audio stuff for a long time and I'm not really familiar with sox. You might get better answer on Stackoverflow...