Created
January 7, 2013 20:27
-
-
Save andrewrk/4478108 to your computer and use it in GitHub Desktop.
sox issue test case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sox.h> | |
#include <limits.h> | |
// use this program with | |
// https://s3.amazonaws.com/superjoe/temp/02a7a451c263b29c79e43ef3ae7c8538.wmv | |
// to demonstrate as sox issue | |
// it should run and spam the console with a bunch of output and then quit | |
// instead it hangs forever at 100% CPU | |
int main(int argc, char * argv[]) { | |
char * in_file_path = argv[1]; | |
sox_format_init(); | |
sox_format_t * input = sox_open_read(in_file_path, NULL, NULL, NULL); | |
if (! input) { | |
fprintf(stderr, "Unrecognized audio format for input file: %s\n", in_file_path); | |
return 1; | |
} | |
int channel_count = input->signal.channels; | |
int frame_count = input->signal.length; | |
// allocate memory to read from library | |
printf("allocate sox memory\n"); | |
const int buffer_frame_count = 2048; | |
size_t frames_size = sizeof(sox_sample_t) * channel_count * buffer_frame_count; | |
sox_sample_t * frames = (sox_sample_t *) malloc(frames_size); | |
if (! frames) { | |
fprintf(stderr, "Out of memory."); | |
return 1; | |
} | |
if (frame_count == 0) { | |
printf("frame count scan sox open read\n"); | |
// scan for the duration | |
sox_format_t * input2 = sox_open_read(in_file_path, NULL, NULL, NULL); | |
if (! input2) { | |
fprintf(stderr, "Had to open the file twice to scan duration, but it didn't work the second time.\n"); | |
return 1; | |
} | |
size_t count = buffer_frame_count; | |
printf("while count == buffer frame count\n"); | |
printf("buffer frame count: %i\n", (int) count); | |
while (count == buffer_frame_count) { | |
printf("1\n"); | |
count = sox_read(input2, frames, buffer_frame_count); | |
printf("2\n"); | |
frame_count += count; | |
} | |
sox_close(input2); | |
fprintf(stderr, "Warning: Had to scan for frame count. Found %i frames.\n", frame_count); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment