diff --git a/.gitignore b/.gitignore index 31e290143c65acc4d55e83ee6c2c513870191370..837619f9c89b93c94a420399ebf8307f15c5fb81 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ opus_demo repacketizer_demo stamp-h1 test-driver +trivial_example *.sw* *.o *.lo diff --git a/Makefile.am b/Makefile.am index 470b8e70e176f53abc1017a5a3f0e7112721c2e4..6d579fe4d89f803805fe0e22e781f119dce28426 100644 --- a/Makefile.am +++ b/Makefile.am @@ -103,7 +103,8 @@ noinst_PROGRAMS = celt/tests/test_unit_cwrs32 \ tests/test_opus_decode \ tests/test_opus_encode \ tests/test_opus_padding \ - tests/test_opus_projection + tests/test_opus_projection \ + trivial_example TESTS = celt/tests/test_unit_cwrs32 \ celt/tests/test_unit_dft \ @@ -131,6 +132,9 @@ repacketizer_demo_LDADD = libopus.la $(NE10_LIBS) $(LIBM) opus_compare_SOURCES = src/opus_compare.c opus_compare_LDADD = $(LIBM) +trivial_example_SOURCES = doc/trivial_example.c +trivial_example_LDADD = libopus.la $(LIBM) + tests_test_opus_api_SOURCES = tests/test_opus_api.c tests/test_opus_common.h tests_test_opus_api_LDADD = libopus.la $(NE10_LIBS) $(LIBM) diff --git a/doc/trivial_example.c b/doc/trivial_example.c index 047ca0a2906a91188ea3b4976e751cdc265d04d5..9cf435b4a9a00002090299b96ef4c07745205311 100644 --- a/doc/trivial_example.c +++ b/doc/trivial_example.c @@ -85,7 +85,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } inFile = argv[1]; - fin = fopen(inFile, "r"); + fin = fopen(inFile, "rb"); if (fin==NULL) { fprintf(stderr, "failed to open input file: %s\n", strerror(errno)); @@ -101,7 +101,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } outFile = argv[2]; - fout = fopen(outFile, "w"); + fout = fopen(outFile, "wb"); if (fout==NULL) { fprintf(stderr, "failed to open output file: %s\n", strerror(errno)); @@ -113,14 +113,25 @@ int main(int argc, char **argv) int i; unsigned char pcm_bytes[MAX_FRAME_SIZE*CHANNELS*2]; int frame_size; + size_t samples; /* Read a 16 bits/sample audio frame. */ - fread(pcm_bytes, sizeof(short)*CHANNELS, FRAME_SIZE, fin); - if (feof(fin)) + samples = fread(pcm_bytes, sizeof(short)*CHANNELS, FRAME_SIZE, fin); + + /* For simplicity, only read whole frames. In a real application, + * we'd pad the final partial frame with zeroes, record the exact + * duration, and trim the decoded audio to match. + */ + if (samples != FRAME_SIZE) + { break; + } + /* Convert from little-endian ordering. */ for (i=0;i