summaryrefslogtreecommitdiff
path: root/src/audiofile.cc
diff options
context:
space:
mode:
authordeva <deva>2011-03-01 19:19:02 +0000
committerdeva <deva>2011-03-01 19:19:02 +0000
commite190d38057892b69246391841b234a368bc2b4ad (patch)
tree34f946bc1c3b86997d4cd45e63c433ef07b36486 /src/audiofile.cc
parentc393edc920f8ee126d1bced3500b6bc1ecf86f83 (diff)
MAJOR rewrite of the internals. New input/output 'plugin' system. Still a lot missing.
Diffstat (limited to 'src/audiofile.cc')
-rw-r--r--src/audiofile.cc61
1 files changed, 20 insertions, 41 deletions
diff --git a/src/audiofile.cc b/src/audiofile.cc
index 9c00bed..2533b33 100644
--- a/src/audiofile.cc
+++ b/src/audiofile.cc
@@ -31,22 +31,12 @@
#include <sndfile.h>
-AudioFile::AudioFile(std::string filename, bool preload, int min_velocity)
+AudioFile::AudioFile(std::string filename)
{
this->filename = filename;
+
data = NULL;
size = 0;
-
- char *p = (char*)filename.c_str() + filename.length() - 6;
- int num = atoi(p);
- if(num < 0) num *= -1;
-
- //printf("%s", filename.c_str());
- if(preload && num >= min_velocity) {
- //printf(" ... loading");
- load();
- }
- printf("."); fflush(stdout);
}
AudioFile::~AudioFile()
@@ -56,40 +46,29 @@ AudioFile::~AudioFile()
void AudioFile::unload()
{
- if(!data) return;
-
- free(data);
- data = NULL;
- size = 0;
+ if(data) {
+ delete data;
+ data = NULL;
+ size = 0;
+ }
}
-#define THRESHOLD 0.0001
void AudioFile::load()
{
if(data) return;
- SF_INFO sf_info;
- SNDFILE *fh = sf_open(filename.c_str(), SFM_READ, &sf_info);
-
- size = sf_seek(fh, 0, SEEK_END);
- jack_default_audio_sample_t* tmp_data = (jack_default_audio_sample_t*)malloc(sizeof(jack_default_audio_sample_t)*size);
-
- // printf("Loading %s, %d samples\n", filename.c_str(), size);
-
- sf_seek(fh, 0, SEEK_SET);
- sf_read_float(fh, tmp_data, size);
-
- // for(size_t i = 0; i < size; i++) data[i] *= 0.1;
-
- sf_close(fh);
-
- // Find real size (crop 'silence')
- while(size > 0 && tmp_data[size--] < THRESHOLD) {}
- data = (jack_default_audio_sample_t*)malloc(sizeof(jack_default_audio_sample_t)*size);
- for(size_t i = 0; i < size; i++) data[i] = tmp_data[i];
- // ramp down
- // if(size > 1024) for(size_t i = 1024; i >= 0; i--) data[size - i] *= (float)i/1024.0;
- free(tmp_data);
-
+ SF_INFO sf_info;
+ SNDFILE *fh = sf_open(filename.c_str(), SFM_READ, &sf_info);
+ if(!fh) {
+ printf("Load error...\n");
+ return;
+ }
+
+ size = sf_info.frames;
+ data = new sample_t[size];
+
+ sf_read_float(fh, data, size);
+
+ sf_close(fh);
}