summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deadbeef.h1
-rw-r--r--plugins/gtkui/widgets.c11
-rw-r--r--streamer.c24
3 files changed, 27 insertions, 9 deletions
diff --git a/deadbeef.h b/deadbeef.h
index f5ea79e4..132770d4 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -331,6 +331,7 @@ enum ddb_audio_data_type_t {
// audio memory constants
// since 1.5
#define DDB_FREQ_BANDS 256
+#define DDB_FREQ_MAX_CHANNELS 9
// typecasting macros
#define DB_PLUGIN(x) ((DB_plugin_t *)(x))
diff --git a/plugins/gtkui/widgets.c b/plugins/gtkui/widgets.c
index 9eee7ea8..ae9e3185 100644
--- a/plugins/gtkui/widgets.c
+++ b/plugins/gtkui/widgets.c
@@ -2305,16 +2305,21 @@ scope_wavedata_listener (void *ctx, int type, ddb_waveformat_t *fmt, const float
if (w->samples) {
// append
+ int nsamples = in_samples / fmt->channels;
float ratio = fmt->samplerate / 44100.f;
- int size = in_samples / ratio;
+ int size = nsamples / ratio;
int sz = min (w->nsamples, size);
int n = w->nsamples-sz;
memmove (w->samples, w->samples + sz, n * sizeof (float));
float pos = 0;
- for (int i = 0; i < sz && pos < in_samples; i++, pos += ratio) {
- w->samples[n + i] = data[ftoi(pos * fmt->channels)];
+ for (int i = 0; i < sz && pos < nsamples; i++, pos += ratio) {
+ w->samples[n + i] = data[ftoi(pos * fmt->channels) * fmt->channels + 0];
+ for (int j = 1; j < fmt->channels; j++) {
+ w->samples[n + i] += data[ftoi(pos * fmt->channels) * fmt->channels + j];
+ }
+ w->samples[n+i] /= fmt->channels;
}
}
}
diff --git a/streamer.c b/streamer.c
index 5db60e7a..5cba5211 100644
--- a/streamer.c
+++ b/streamer.c
@@ -136,9 +136,10 @@ static int streamer_buffering;
static DB_FILE *streamer_file;
// for vis plugins
-static float freq_data[DDB_FREQ_BANDS];
-static float audio_data[DDB_FREQ_BANDS];
+static float freq_data[DDB_FREQ_BANDS * DDB_FREQ_MAX_CHANNELS];
+static float audio_data[DDB_FREQ_BANDS * DDB_FREQ_MAX_CHANNELS];
static int audio_data_fill = 0;
+static int audio_data_channels = 0;
// message queue
static struct handler_s *handler;
@@ -2286,9 +2287,9 @@ streamer_read (char *bytes, int size) {
int in_frames = sz / in_frame_size;
ddb_waveformat_t out_fmt = {
.bps = 32,
- .channels = 1,
+ .channels = output->fmt.channels,
.samplerate = output->fmt.samplerate,
- .channelmask = DDB_SPEAKER_FRONT_LEFT,
+ .channelmask = output->fmt.channelmask,
.is_float = 1,
.is_bigendian = 0
};
@@ -2303,15 +2304,26 @@ streamer_read (char *bytes, int size) {
}
mutex_unlock (wdl_mutex);
+ if (out_fmt.channels != audio_data_channels) {
+ audio_data_fill = 0;
+ audio_data_channels = out_fmt.channels;
+ }
int remaining = in_frames;
do {
int sz = DDB_FREQ_BANDS-audio_data_fill;
sz = min (sz, remaining);
- memcpy (&audio_data[audio_data_fill], &temp_audio_data[in_frames-remaining], sz * sizeof (float));
+ for (int c = 0; c < audio_data_channels; c++) {
+ for (int s = 0; s < sz; s++) {
+ audio_data[DDB_FREQ_BANDS * c + audio_data_fill + s] = temp_audio_data[(in_frames-remaining + s) * audio_data_channels + c];
+ }
+ }
+// memcpy (&audio_data[audio_data_fill], &temp_audio_data[in_frames-remaining], sz * sizeof (float));
audio_data_fill += sz;
remaining -= sz;
if (audio_data_fill == DDB_FREQ_BANDS) {
- calc_freq (audio_data, freq_data);
+ for (int c = 0; c < audio_data_channels; c++) {
+ calc_freq (&audio_data[DDB_FREQ_BANDS * c], &freq_data[DDB_FREQ_BANDS * c]);
+ }
mutex_lock (wdl_mutex);
for (wavedata_listener_t *l = wavedata_listeners; l; l = l->next) {
if (l->type == DDB_AUDIO_FREQ) {