diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2023-12-12 23:17:35 +0100 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2023-12-12 23:17:35 +0100 |
commit | 0f08bc5487adffde5f3e0aff30ffe41b53a21bf1 (patch) | |
tree | dce92f6daa256f17d8e292e1578605af2f2218f9 /app | |
parent | 93a9691246574b6d51ddbbdb5be3dceb89ff24e9 (diff) | |
download | libfshift-0f08bc5487adffde5f3e0aff30ffe41b53a21bf1.tar.gz |
- f must be divisors of 44100 and be positive
- 44100 hardcoded
Diffstat (limited to 'app')
-rw-r--r-- | app/unisono/CMakeLists.txt | 13 | ||||
-rw-r--r-- | app/unisono/main.c | 27 |
2 files changed, 31 insertions, 9 deletions
diff --git a/app/unisono/CMakeLists.txt b/app/unisono/CMakeLists.txt index 8a44354..67bf8e0 100644 --- a/app/unisono/CMakeLists.txt +++ b/app/unisono/CMakeLists.txt @@ -22,7 +22,18 @@ find_library(LIBSNDFILE_LIBRARY message(STATUS "sndfile include dirs path: ${LIBSNDFILE_INCLUDE_DIR}") message(STATUS "sndfile libs path: ${LIBSNDFILE_LIBRARY}") +if(LIBFSHIFT_BUILD_PUB_HEADER) + message(STATUS "use libfshift include path: ${LIBFSHIFT_BUILD_PUB_HEADER}") + include_directories(${LIBFSHIFT_BUILD_PUB_HEADER}) +endif() + add_executable(unisono "main.c") + +if(LIBFSHIFT_BUILD_LIB_PATH) + message(STATUS "use libfshift lib path: ${LIBFSHIFT_BUILD_LIB_PATH}") + target_link_libraries(unisono PRIVATE ${LIBFSHIFT_BUILD_LIB_PATH}) +endif() + include_directories(${LIBSNDFILE_INCLUDE_DIRS}) -target_link_libraries(unisono PRIVATE ${LIBSNDFILE_LIBRARY}) +target_link_libraries(unisono PRIVATE ${LIBSNDFILE_LIBRARY} m) diff --git a/app/unisono/main.c b/app/unisono/main.c index 4940962..8af3d68 100644 --- a/app/unisono/main.c +++ b/app/unisono/main.c @@ -4,12 +4,15 @@ #include <sndfile.h> +#include <libfshift.h> + static void print_usage(const char* name) { fprintf(stdout, "usage: %s\n", name); } -#define BUFFER_LEN 16384 +#define BUFFER_LEN_POW 14 +#define BUFFER_LEN (1 << BUFFER_LEN_POW) static float in_data[BUFFER_LEN]; static float out_data[BUFFER_LEN]; @@ -25,13 +28,14 @@ void downmix(float* in, int len) } } -void process(float *in, float *out, const SF_INFO *info, int len) +void process(float *in, float *out, const SF_INFO *info, int len, fshift_ctx_t ctx) { - int i; + fshift_run(ctx, in, out + len/2, in + len/2); + int i, j; // Call processing here for (int i = 0; i < len / 2; i++) { - out[i * 2] = in[i]; - out[i * 2 + 1] = -in[i]; + out[i * 2] = in[len / 2 + i]; + out[i * 2 + 1] = out[len / 2 + i]; } } @@ -48,6 +52,7 @@ int main(int argc, char** argv) int read_channels; int read_block_sz = BUFFER_LEN; int read_count; + fshift_ctx_t ctx; while ((ch = getopt(argc, argv, "f:i:")) != -1) { switch (ch) { @@ -70,6 +75,11 @@ int main(int argc, char** argv) out_file_nm = argv[optind]; fprintf(stderr, "input: %s -> %s, shift: %f hz\n", in_file_nm, out_file_nm, shift); + ctx = fshift_create_ctx(shift, BUFFER_LEN_POW - 1); + if (NULL == ctx) { + fprintf(stderr, "unable to create libfshift ctx\n"); + } + memset(&sf_info, 0, sizeof(sf_info)); if (!(in_file = sf_open(in_file_nm, SFM_READ, &sf_info))) { @@ -101,12 +111,13 @@ int main(int argc, char** argv) while ((read_count = (int)sf_readf_float(in_file, in_data, BUFFER_LEN / 2))) { if (read_channels == 2) downmix(in_data, BUFFER_LEN); - process(in_data, out_data, &sf_info, BUFFER_LEN); + process(in_data, out_data, &sf_info, BUFFER_LEN, ctx); sf_writef_float(out_file, out_data, read_count); } - sf_close(in_file) ; - sf_close(out_file) ; + sf_close(in_file); + sf_close(out_file); + fshift_free_ctx(ctx); return 0; } |