summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2010-11-22 21:38:06 +0100
committerGravatar waker <wakeroid@gmail.com>2010-11-22 21:38:06 +0100
commit19a188df769b29df82c12e9b684f13000544fd5e (patch)
tree8f38cf4dbd227d8e287e2266bcb072a1c53de428
parenta839ce76b389e7bfa71e7eb17c6ce2a3e0243aab (diff)
added float clamp(-1,1) in premix
added plugin pointer to dsp instances code cleanup
-rw-r--r--deadbeef.h8
-rw-r--r--plugins/dsp_libsrc/src.c2
-rw-r--r--premix.c18
-rw-r--r--streamer.c96
4 files changed, 69 insertions, 55 deletions
diff --git a/deadbeef.h b/deadbeef.h
index 049cfa2e..05392c61 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -66,8 +66,8 @@ extern "C" {
// 0.2 -- deadbeef-0.2.3
// 0.1 -- deadbeef-0.2.0
-#define DB_API_VERSION_MAJOR 0
-#define DB_API_VERSION_MINOR 10
+#define DB_API_VERSION_MAJOR 9
+#define DB_API_VERSION_MINOR 9
#define DB_PLUGIN_SET_API_VERSION\
.plugin.api_vmajor = DB_API_VERSION_MAJOR,\
@@ -740,14 +740,16 @@ typedef struct DB_output_s {
} DB_output_t;
// dsp plugin
-#define DDB_INIT_DSP_INSTANCE(var,type) {\
+#define DDB_INIT_DSP_INSTANCE(var,type,plug) {\
memset(var,0,sizeof(type));\
strncpy (var->inst.id, id, 9);\
var->inst.id[9]=0;\
+ var->inst.plugin=plug;\
}
typedef struct DB_dsp_instance_s {
char id[10];
+ struct DB_dsp_s *plugin;
struct DB_dsp_instance_s *next;
unsigned enabled : 1;
} DB_dsp_instance_t;
diff --git a/plugins/dsp_libsrc/src.c b/plugins/dsp_libsrc/src.c
index 19317b68..872b196f 100644
--- a/plugins/dsp_libsrc/src.c
+++ b/plugins/dsp_libsrc/src.c
@@ -49,7 +49,7 @@ typedef struct {
DB_dsp_instance_t* ddb_src_open (const char *id) {
ddb_src_libsamplerate_t *src = malloc (sizeof (ddb_src_libsamplerate_t));
- DDB_INIT_DSP_INSTANCE (src,ddb_src_libsamplerate_t);
+ DDB_INIT_DSP_INSTANCE (src,ddb_src_libsamplerate_t,&plugin.dsp);
src->mutex = deadbeef->mutex_create ();
char var[20];
diff --git a/premix.c b/premix.c
index 8c6f7e81..43a7ed8f 100644
--- a/premix.c
+++ b/premix.c
@@ -211,7 +211,14 @@ pcm_write_samples_float_to_16 (const ddb_waveformat_t * restrict inputfmt, const
if (channelmap[c] != -1) {
int16_t *out = (int16_t*)(output + (outputfmt->bps >> 3) * channelmap[c]);
float sample = *((float*)input);
- *out = (int16_t)ftoi (sample*0x7ff0);
+ // FIXME: sse optimize
+ if (sample > 1) {
+ sample = 1;
+ }
+ if (sample < -1) {
+ sample = -1;
+ }
+ *out = (int16_t)ftoi (sample*0x7fff);
}
input += 4;
}
@@ -229,7 +236,14 @@ pcm_write_samples_float_to_8 (const ddb_waveformat_t * restrict inputfmt, const
if (channelmap[c] != -1) {
int8_t *out = (int8_t*)(output + (outputfmt->bps >> 3) * channelmap[c]);
float sample = *((float*)input);
- *out = (int8_t)ftoi (sample*0x7e);
+ // FIXME: sse optimize
+ if (sample > 1) {
+ sample = 1;
+ }
+ if (sample < -1) {
+ sample = -1;
+ }
+ *out = (int8_t)ftoi (sample*0x7f);
}
input += 4;
}
diff --git a/streamer.c b/streamer.c
index ca1b6b22..16e9150c 100644
--- a/streamer.c
+++ b/streamer.c
@@ -1317,75 +1317,73 @@ streamer_read_async (char *bytes, int size) {
if (fileinfo->fmt.samplerate != -1) {
DB_dsp_t **dsp = deadbeef->plug_get_dsp_list ();
+ int outputsamplesize = (output->fmt.bps>>3)*output->fmt.channels;
+ int inputsamplesize = (fileinfo->fmt.bps>>3)*fileinfo->fmt.channels;
if (!memcmp (&fileinfo->fmt, &output->fmt, sizeof (ddb_waveformat_t))) {
+ // pass through from input to output
bytesread = fileinfo->plugin->read (fileinfo, bytes, size);
if (bytesread != size) {
is_eof = 1;
}
}
- else {
- if (output->fmt.samplerate != fileinfo->fmt.samplerate) {
- // convert to float, pass through streamer DSP chain
- int outputsamplesize = (output->fmt.bps>>3)*output->fmt.channels;
- int inputsamplesize = (fileinfo->fmt.bps>>3)*fileinfo->fmt.channels;
- int dspsamplesize = output->fmt.channels * sizeof (float);
-
- float ratio = output->fmt.samplerate/(float)fileinfo->fmt.samplerate;
+ else if (output->fmt.samplerate != fileinfo->fmt.samplerate) {
+ // convert to float, pass through streamer DSP chain
+ int dspsamplesize = output->fmt.channels * sizeof (float);
- int max_out_frames = size / (output->fmt.channels * (output->fmt.bps>>3));
- int dsp_num_frames = max_out_frames;
+ float ratio = output->fmt.samplerate/(float)fileinfo->fmt.samplerate;
- char outbuf[dsp_num_frames * dspsamplesize];
+ int max_out_frames = size / (output->fmt.channels * (output->fmt.bps>>3));
+ int dsp_num_frames = max_out_frames;
- bytesread = 0;
+ char outbuf[dsp_num_frames * dspsamplesize];
- ddb_waveformat_t dspfmt;
- memcpy (&dspfmt, &output->fmt, sizeof (dspfmt));
- dspfmt.bps = 32;
- dspfmt.is_float = 1;
+ bytesread = 0;
- int inputsize = dsp_num_frames * inputsamplesize;
- char input[inputsize];
+ ddb_waveformat_t dspfmt;
+ memcpy (&dspfmt, &output->fmt, sizeof (dspfmt));
+ dspfmt.bps = 32;
+ dspfmt.is_float = 1;
- // decode pcm
- int nb = fileinfo->plugin->read (fileinfo, input, inputsize);
- if (nb != inputsize) {
- is_eof = 1;
- }
- inputsize = nb;
+ int inputsize = dsp_num_frames * inputsamplesize;
+ char input[inputsize];
- if (inputsize > 0) {
- // make 2x size buffer for float data
- char tempbuf[inputsize/inputsamplesize * dspsamplesize * 2];
+ // decode pcm
+ int nb = fileinfo->plugin->read (fileinfo, input, inputsize);
+ if (nb != inputsize) {
+ is_eof = 1;
+ }
+ inputsize = nb;
- // convert to float
- int tempsize = pcm_convert (&fileinfo->fmt, input, &dspfmt, tempbuf, inputsize);
+ if (inputsize > 0) {
+ // make 2x size buffer for float data
+ char tempbuf[inputsize/inputsamplesize * dspsamplesize * 2];
- srcplug->set_ratio (src, ratio);
+ // convert to float
+ int tempsize = pcm_convert (&fileinfo->fmt, input, &dspfmt, tempbuf, inputsize);
- int nframes = inputsize / inputsamplesize;
- DB_dsp_instance_t *dsp = src;
- while (dsp) {
- nframes = srcplug->dsp.process (dsp, (float *)tempbuf, nframes, dspfmt.channels);
- dsp = dsp->next;
- }
- int n = pcm_convert (&dspfmt, tempbuf, &output->fmt, bytes, nframes * dspsamplesize);
+ srcplug->set_ratio (src, ratio);
- bytesread += n;
+ int nframes = inputsize / inputsamplesize;
+ DB_dsp_instance_t *dsp = src;
+ while (dsp) {
+ nframes = dsp->plugin->process (dsp, (float *)tempbuf, nframes, dspfmt.channels);
+ dsp = dsp->next;
}
+ int n = pcm_convert (&dspfmt, tempbuf, &output->fmt, bytes, nframes * dspsamplesize);
+
+ bytesread += n;
}
- else {
- int outputsamplesize = (output->fmt.bps>>3)*output->fmt.channels;
- int inputsamplesize = (fileinfo->fmt.bps>>3)*fileinfo->fmt.channels;
- int inputsize = size/outputsamplesize*inputsamplesize;
- char input[inputsize];
- int nb = fileinfo->plugin->read (fileinfo, input, inputsize);
- if (nb != inputsize) {
- is_eof = 1;
- }
- inputsize = nb;
- bytesread = pcm_convert (&fileinfo->fmt, input, &output->fmt, bytes, inputsize);
+ }
+ else {
+ // convert from input fmt to output fmt
+ int inputsize = size/outputsamplesize*inputsamplesize;
+ char input[inputsize];
+ int nb = fileinfo->plugin->read (fileinfo, input, inputsize);
+ if (nb != inputsize) {
+ is_eof = 1;
}
+ inputsize = nb;
+ bytesread = pcm_convert (&fileinfo->fmt, input, &output->fmt, bytes, inputsize);
}
#if WRITE_DUMP
if (bytesread) {