diff options
author | 2010-11-13 21:35:53 +0100 | |
---|---|---|
committer | 2010-11-13 21:35:53 +0100 | |
commit | 086360352150cd032523090bbd75eb2f4208e6ed (patch) | |
tree | 166ebaa55e0cafa237ad821c77d178d08cc4b6a2 /plugins | |
parent | 607479be3172aed4c5f906dcb326089e1d5538e6 (diff) |
implemented conversion between streams with different channel masks
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/alsa/alsa.c | 42 | ||||
-rw-r--r-- | plugins/gtkui/gtkui.c | 4 | ||||
-rw-r--r-- | plugins/mpgmad/mpgmad.c | 27 | ||||
-rw-r--r-- | plugins/supereq/supereq.c | 2 |
4 files changed, 60 insertions, 15 deletions
diff --git a/plugins/alsa/alsa.c b/plugins/alsa/alsa.c index 837305cd..be744b34 100644 --- a/plugins/alsa/alsa.c +++ b/plugins/alsa/alsa.c @@ -191,7 +191,7 @@ palsa_set_hw_params (ddb_waveformat_t *fmt) { plugin.fmt.samplerate = val; trace ("chosen samplerate: %d Hz\n", val); - if ((err = snd_pcm_hw_params_set_channels (audio, hw_params, fmt->channels)) < 0) { + if ((err = snd_pcm_hw_params_set_channels (audio, hw_params, /*fmt->channels*/6)) < 0) { fprintf (stderr, "cannot set channel count (%s)\n", snd_strerror (err)); goto error; @@ -236,12 +236,34 @@ palsa_set_hw_params (ddb_waveformat_t *fmt) { break; } - plugin.fmt.bps = sample_fmt; plugin.fmt.channels = nchan; plugin.fmt.is_float = 0; plugin.fmt.is_multichannel = 0; plugin.fmt.channelmask = 0; - + if (nchan == 1) { + plugin.fmt.channelmask = DDB_SPEAKER_FRONT_LEFT; + } + if (nchan == 2) { + plugin.fmt.channelmask = DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT; + } + if (nchan == 3) { + plugin.fmt.channelmask = DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT | DDB_SPEAKER_LOW_FREQUENCY; + } + if (nchan == 4) { + plugin.fmt.channelmask = DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT | DDB_SPEAKER_BACK_LEFT | DDB_SPEAKER_BACK_RIGHT; + } + if (nchan == 5) { + plugin.fmt.channelmask = DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT | DDB_SPEAKER_BACK_LEFT | DDB_SPEAKER_BACK_RIGHT | DDB_SPEAKER_FRONT_CENTER; + } + if (nchan == 6) { + plugin.fmt.channelmask = DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT | DDB_SPEAKER_BACK_LEFT | DDB_SPEAKER_BACK_RIGHT | DDB_SPEAKER_FRONT_CENTER | DDB_SPEAKER_LOW_FREQUENCY; + } + if (nchan == 7) { + plugin.fmt.channelmask = DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT | DDB_SPEAKER_BACK_LEFT | DDB_SPEAKER_BACK_RIGHT | DDB_SPEAKER_FRONT_CENTER | DDB_SPEAKER_SIDE_LEFT | DDB_SPEAKER_SIDE_RIGHT; + } + if (nchan == 8) { + plugin.fmt.channelmask = DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT | DDB_SPEAKER_BACK_LEFT | DDB_SPEAKER_BACK_RIGHT | DDB_SPEAKER_FRONT_CENTER | DDB_SPEAKER_SIDE_LEFT | DDB_SPEAKER_SIDE_RIGHT | DDB_SPEAKER_LOW_FREQUENCY; + } error: if (hw_params) { snd_pcm_hw_params_free (hw_params); @@ -512,10 +534,10 @@ palsa_thread (void *context) { break; } err = 0; - char buf[period_size * 4]; - int bytes_to_write = palsa_callback (buf, period_size * 4); + char buf[period_size * (plugin.fmt.bps>>3) * plugin.fmt.channels]; + int bytes_to_write = palsa_callback (buf, period_size * (plugin.fmt.bps>>3) * plugin.fmt.channels); - if ( bytes_to_write >= 4 ) { + if (bytes_to_write >= (plugin.fmt.bps>>3) * plugin.fmt.channels) { err = snd_pcm_writei (audio, buf, snd_pcm_bytes_to_frames(audio, bytes_to_write)); } else { @@ -593,10 +615,10 @@ palsa_callback (char *stream, int len) { ); #else - int16_t ivolume = deadbeef->volume_get_amp () * 1000; - for (int i = 0; i < bytesread/2; i++) { - ((int16_t*)stream)[i] = (int16_t)(((int32_t)(((int16_t*)stream)[i])) * ivolume / 1000); - } +// int16_t ivolume = deadbeef->volume_get_amp () * 1000; +// for (int i = 0; i < bytesread/2; i++) { +// ((int16_t*)stream)[i] = (int16_t)(((int32_t)(((int16_t*)stream)[i])) * ivolume / 1000); +// } #endif return bytesread; } diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index 46b3edf8..a2da9d74 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -45,8 +45,8 @@ #include "eq.h" #include "actions.h" -//#define trace(...) { fprintf(stderr, __VA_ARGS__); } -#define trace(fmt,...) +#define trace(...) { fprintf(stderr, __VA_ARGS__); } +//#define trace(fmt,...) static DB_gui_t plugin; DB_functions_t *deadbeef; diff --git a/plugins/mpgmad/mpgmad.c b/plugins/mpgmad/mpgmad.c index 1d5890ac..6b4d96ea 100644 --- a/plugins/mpgmad/mpgmad.c +++ b/plugins/mpgmad/mpgmad.c @@ -654,6 +654,7 @@ cmp3_init (DB_fileinfo_t *_info, DB_playItem_t *it) { _info->fmt.bps = info->buffer.bitspersample; _info->fmt.samplerate = info->buffer.samplerate; _info->fmt.channels = info->buffer.channels; + _info->fmt.channelmask = _info->fmt.channels == 1 ? DDB_SPEAKER_FRONT_LEFT : (DDB_SPEAKER_FRONT_LEFT | DDB_SPEAKER_FRONT_RIGHT); mad_stream_init(&info->stream); mad_stream_options (&info->stream, MAD_OPTION_IGNORECRC); @@ -937,6 +938,28 @@ cmp3_free (DB_fileinfo_t *_info) { } static int +cmp3_read (DB_fileinfo_t *_info, char *bytes, int size) { +#if WRITE_DUMP + if (!out) { + out = fopen ("out.raw", "w+b"); + } +#endif + mpgmad_info_t *info = (mpgmad_info_t *)_info; + info->buffer.readsize = size; + info->buffer.out = bytes; + cmp3_decode_int16 (info); + info->buffer.currentsample += (size - info->buffer.readsize) / 4; + _info->readpos = (float)(info->buffer.currentsample - info->buffer.startsample) / info->buffer.samplerate; +#if WRITE_DUMP + if (size - info->buffer.readsize > 0) { + fwrite (bytes, 1, size - info->buffer.readsize, out); + } +#endif + return size - info->buffer.readsize; +} + +#if 0 +static int cmp3_read_int16 (DB_fileinfo_t *_info, char *bytes, int size) { #if WRITE_DUMP if (!out) { @@ -968,6 +991,7 @@ cmp3_read_float32 (DB_fileinfo_t *_info, char *bytes, int size) { _info->readpos = (float)(info->buffer.currentsample - info->buffer.startsample) / info->buffer.samplerate; return size - info->buffer.readsize; } +#endif static int cmp3_seek_sample (DB_fileinfo_t *_info, int sample) { @@ -1246,8 +1270,7 @@ static DB_decoder_t plugin = { .open = cmp3_open, .init = cmp3_init, .free = cmp3_free, - .read_int16 = cmp3_read_int16, - .read_float32 = cmp3_read_float32, + .read = cmp3_read, .seek = cmp3_seek, .seek_sample = cmp3_seek_sample, .insert = cmp3_insert, diff --git a/plugins/supereq/supereq.c b/plugins/supereq/supereq.c index 577af84a..6ebf9b24 100644 --- a/plugins/supereq/supereq.c +++ b/plugins/supereq/supereq.c @@ -129,7 +129,7 @@ supereq_regen_table_thread (void *param) { } int -supereq_process_int16 (int16_t *samples, int nsamples, int nch, int bps, int srate) { +supereq_process (char * restrict samples, ddb_waveformat_t * restrict fmt) { if ((nch != 1 && nch != 2) || (bps != 8 && bps != 16 && bps != 24)) return nsamples; if (params_changed && !tid) { tid = deadbeef->thread_start (supereq_regen_table_thread, NULL); |