Move load_sample into drmr_hydrogen.c

This commit is contained in:
Nick Lanham 2012-02-07 21:33:20 +01:00
parent c31bea22f5
commit 8ed58ec1c6
4 changed files with 34 additions and 35 deletions

33
drmr.c
View File

@ -22,39 +22,6 @@
#include "drmr.h" #include "drmr.h"
#include "drmr_hydrogen.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) { static void* load_thread(void* arg) {
DrMr* drmr = (DrMr*)arg; DrMr* drmr = (DrMr*)arg;

2
drmr.h
View File

@ -47,8 +47,6 @@ typedef struct {
float* data; float* data;
} drmr_sample; } drmr_sample;
int load_sample(char* path,drmr_sample* smp);
// lv2 stuff // lv2 stuff
#define DRMR_URI "http://github.com/nicklan/drmr" #define DRMR_URI "http://github.com/nicklan/drmr"

View File

@ -258,6 +258,39 @@ void free_samples(drmr_sample* samples, int num_samples) {
free(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) { int load_hydrogen_kit(DrMr* drmr, char* path) {
char* fp_buf; char* fp_buf;
FILE* file; FILE* file;

View File

@ -20,6 +20,7 @@
kits* scan_kits(); kits* scan_kits();
void free_samples(drmr_sample* samples, int num_samples); 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); int load_hydrogen_kit(DrMr* drmr, char* path);
#endif // DRMR_HYDRO_H #endif // DRMR_HYDRO_H