Increasing channel using libsox

梦想的初衷 提交于 2020-01-25 06:51:08

问题


I am trying to use libsox to increase the channel of a wav file. I have read the related question: Reducing a channel from wav file using libsox I also read the libsox's exampl3.c. I take a deep copy of in->signal as interm_signal. But the resulting file is still half the duration of the original file.

Here is my code:

int main(int argc, char * argv[])
{
  sox_format_t        *input  = NULL;
  sox_format_t        *output = NULL;
  sox_effects_chain_t *chain  = NULL;
  sox_effect_t        *e      = NULL;

  char * args[10];

  assert(sox_init()==SOX_SUCCESS);
  assert(input = sox_open_read(argv[1], NULL, NULL, NULL));

  sox_signalinfo_t output_signal;
  output_signal = input->signal; /** Deep Copy */
  output_signal.channels = 2;

  assert(output = sox_open_write(argv[2], &output_signal, NULL, NULL, NULL, NULL));

  chain = sox_create_effects_chain(&input->encoding, &output->encoding);

  sox_signalinfo_t interm_signal;
  interm_signal = input->signal; /** Deep Copy */

  e = sox_create_effect(sox_find_effect("input"));
  args[0] = (char *)input, assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
  assert(sox_add_effect(chain, e, &interm_signal, &input->signal) == SOX_SUCCESS);
  free(e);

  // output->signal.rate = 16000;
  // e = sox_create_effect(sox_find_effect("rate"));
  // args[0]="16000", assert(sox_effect_options(e, 0, args) == SOX_SUCCESS);
  // // e->handler.flags |= SOX_EFF_LENGTH;
  // assert(sox_add_effect(chain, e, &interm_signal, &output->signal) == SOX_SUCCESS);
  // free(e);

  // output->signal.channels = 2;
  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, &output->signal) == SOX_SUCCESS);
  free(e);

  // output->signal.precision = 8;
  e = sox_create_effect(sox_find_effect("output"));
  args[0] = (char *)output, assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
  assert(sox_add_effect(chain, e, &interm_signal, &output->signal) == SOX_SUCCESS);
  free(e);

  sox_flow_effects(chain, NULL, NULL);

  sox_delete_effects_chain(chain);
  // free(output_signal);
  // free(interm_signal);
  sox_close(output);
  sox_close(input);
  sox_quit();

  return 0;
}

来源:https://stackoverflow.com/questions/58834069/increasing-channel-using-libsox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!