From 8ed58ec1c6d87de9133babf313d28653c4461c86 Mon Sep 17 00:00:00 2001 From: Nick Lanham Date: Tue, 7 Feb 2012 21:33:20 +0100 Subject: [PATCH] Move load_sample into drmr_hydrogen.c --- drmr.c | 33 --------------------------------- drmr.h | 2 -- drmr_hydrogen.c | 33 +++++++++++++++++++++++++++++++++ drmr_hydrogen.h | 1 + 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/drmr.c b/drmr.c index 9ffca42..1306032 100644 --- a/drmr.c +++ b/drmr.c @@ -22,39 +22,6 @@ #include "drmr.h" #include "drmr_hydrogen.h" -int load_sample(char* path, drmr_sample* samp) { - SNDFILE* sndf; - int size; - - //printf("Loading: %s\n",path); - - samp->active = 0; - - memset(&(samp->info),0,sizeof(SF_INFO)); - sndf = sf_open(path,SFM_READ,&(samp->info)); - - if (!sndf) { - fprintf(stderr,"Failed to open sound file: %s - %s\n",path,sf_strerror(sndf)); - return 1; - } - - if (samp->info.channels > 2) { - fprintf(stderr, "File has too many channels. Can only handle mono/stereo samples\n"); - return 1; - } - size = samp->info.frames * samp->info.channels; - samp->limit = size; - samp->data = malloc(size*sizeof(float)); - if (!samp->data) { - fprintf(stderr,"Failed to allocate sample memory for %s\n",path); - return 1; - } - - sf_read_float(sndf,samp->data,size); - sf_close(sndf); - return 0; -} - static void* load_thread(void* arg) { DrMr* drmr = (DrMr*)arg; diff --git a/drmr.h b/drmr.h index 02ecef7..d9818f6 100644 --- a/drmr.h +++ b/drmr.h @@ -47,8 +47,6 @@ typedef struct { float* data; } drmr_sample; -int load_sample(char* path,drmr_sample* smp); - // lv2 stuff #define DRMR_URI "http://github.com/nicklan/drmr" diff --git a/drmr_hydrogen.c b/drmr_hydrogen.c index 47b1618..1cff750 100644 --- a/drmr_hydrogen.c +++ b/drmr_hydrogen.c @@ -258,6 +258,39 @@ void free_samples(drmr_sample* samples, int num_samples) { free(samples); } +int load_sample(char* path, drmr_sample* samp) { + SNDFILE* sndf; + int size; + + //printf("Loading: %s\n",path); + + samp->active = 0; + + memset(&(samp->info),0,sizeof(SF_INFO)); + sndf = sf_open(path,SFM_READ,&(samp->info)); + + if (!sndf) { + fprintf(stderr,"Failed to open sound file: %s - %s\n",path,sf_strerror(sndf)); + return 1; + } + + if (samp->info.channels > 2) { + fprintf(stderr, "File has too many channels. Can only handle mono/stereo samples\n"); + return 1; + } + size = samp->info.frames * samp->info.channels; + samp->limit = size; + samp->data = malloc(size*sizeof(float)); + if (!samp->data) { + fprintf(stderr,"Failed to allocate sample memory for %s\n",path); + return 1; + } + + sf_read_float(sndf,samp->data,size); + sf_close(sndf); + return 0; +} + int load_hydrogen_kit(DrMr* drmr, char* path) { char* fp_buf; FILE* file; diff --git a/drmr_hydrogen.h b/drmr_hydrogen.h index 49a3bbb..eb6b8e2 100644 --- a/drmr_hydrogen.h +++ b/drmr_hydrogen.h @@ -20,6 +20,7 @@ kits* scan_kits(); void free_samples(drmr_sample* samples, int num_samples); +int load_sample(char* path,drmr_sample* smp); int load_hydrogen_kit(DrMr* drmr, char* path); #endif // DRMR_HYDRO_H