alsa: instead of per-target tests, use HAVE_ALSA_32BIT
Affects all Sony NWZ (linux) and the fiio m3k linux targets. Change-Id: I2fcf121bd026103d2b72332a5a52cc2b5e93949f
This commit is contained in:
parent
e17337c9aa
commit
54fcb907c1
4 changed files with 34 additions and 28 deletions
|
@ -117,6 +117,7 @@
|
||||||
|
|
||||||
/* Audio codec */
|
/* Audio codec */
|
||||||
#define HAVE_FIIO_LINUX_CODEC
|
#define HAVE_FIIO_LINUX_CODEC
|
||||||
|
#define HAVE_ALSA_32BIT
|
||||||
|
|
||||||
/* We don't have hardware controls */
|
/* We don't have hardware controls */
|
||||||
#define HAVE_SW_TONE_CONTROLS
|
#define HAVE_SW_TONE_CONTROLS
|
||||||
|
|
|
@ -82,6 +82,7 @@
|
||||||
|
|
||||||
/* Audio codec */
|
/* Audio codec */
|
||||||
#define HAVE_NWZ_LINUX_CODEC
|
#define HAVE_NWZ_LINUX_CODEC
|
||||||
|
#define HAVE_ALSA_32BIT
|
||||||
|
|
||||||
#endif /* SIMULATOR */
|
#endif /* SIMULATOR */
|
||||||
|
|
||||||
|
|
|
@ -69,8 +69,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const snd_pcm_access_t access_ = SND_PCM_ACCESS_RW_INTERLEAVED; /* access mode */
|
static const snd_pcm_access_t access_ = SND_PCM_ACCESS_RW_INTERLEAVED; /* access mode */
|
||||||
#if defined(SONY_NWZ_LINUX) || defined(HAVE_FIIO_LINUX_CODEC)
|
#if defined(HAE_ALSA_32BIT)
|
||||||
/* Sony NWZ must use 32-bit per sample */
|
|
||||||
static const snd_pcm_format_t format = SND_PCM_FORMAT_S32_LE; /* sample format */
|
static const snd_pcm_format_t format = SND_PCM_FORMAT_S32_LE; /* sample format */
|
||||||
typedef int32_t sample_t;
|
typedef int32_t sample_t;
|
||||||
#else
|
#else
|
||||||
|
@ -262,6 +261,7 @@ error:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HAVE_ALSA_32BIT)
|
||||||
/* Digital volume explanation:
|
/* Digital volume explanation:
|
||||||
* with very good approximation (<0.1dB) the convertion from dB to multiplicative
|
* with very good approximation (<0.1dB) the convertion from dB to multiplicative
|
||||||
* factor, for dB>=0, is 2^(dB/3). We can then notice that if we write dB=3*k+r
|
* factor, for dB>=0, is 2^(dB/3). We can then notice that if we write dB=3*k+r
|
||||||
|
@ -303,6 +303,7 @@ void pcm_set_mixer_volume(int vol_db_l, int vol_db_r)
|
||||||
dig_vol_mult_r = 1 << vol_shift_r | 1 << (vol_shift_r - 1);
|
dig_vol_mult_r = 1 << vol_shift_r | 1 << (vol_shift_r - 1);
|
||||||
logf("r: %d dB -> factor = %d", vol_db_r - 48, dig_vol_mult_r);
|
logf("r: %d dB -> factor = %d", vol_db_r - 48, dig_vol_mult_r);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* copy pcm samples to a spare buffer, suitable for snd_pcm_writei() */
|
/* copy pcm samples to a spare buffer, suitable for snd_pcm_writei() */
|
||||||
static bool copy_frames(bool first)
|
static bool copy_frames(bool first)
|
||||||
|
@ -343,37 +344,40 @@ static bool copy_frames(bool first)
|
||||||
panicf("Wrong pcm_size");
|
panicf("Wrong pcm_size");
|
||||||
/* the compiler will optimize this test away */
|
/* the compiler will optimize this test away */
|
||||||
nframes = MIN((ssize_t)pcm_size/4, frames_left);
|
nframes = MIN((ssize_t)pcm_size/4, frames_left);
|
||||||
if (format == SND_PCM_FORMAT_S32_LE)
|
|
||||||
{
|
|
||||||
/* We have to convert 16-bit to 32-bit, the need to multiply the
|
|
||||||
* sample by some value so the sound is not too low */
|
|
||||||
const int16_t *pcm_ptr = pcm_data;
|
|
||||||
sample_t *sample_ptr = &frames[2*(period_size-frames_left)];
|
|
||||||
for (int i = 0; i < nframes; i++)
|
|
||||||
{
|
|
||||||
*sample_ptr++ = *pcm_ptr++ * dig_vol_mult_l;
|
|
||||||
*sample_ptr++ = *pcm_ptr++ * dig_vol_mult_r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef HAVE_RECORDING
|
#ifdef HAVE_RECORDING
|
||||||
switch (current_alsa_mode)
|
switch (current_alsa_mode)
|
||||||
{
|
{
|
||||||
case SND_PCM_STREAM_PLAYBACK:
|
case SND_PCM_STREAM_PLAYBACK:
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(HAVE_ALSA_32BIT)
|
||||||
|
if (format == SND_PCM_FORMAT_S32_LE)
|
||||||
|
{
|
||||||
|
/* We have to convert 16-bit to 32-bit, the need to multiply the
|
||||||
|
* sample by some value so the sound is not too low */
|
||||||
|
const int16_t *pcm_ptr = pcm_data;
|
||||||
|
sample_t *sample_ptr = &frames[2*(period_size-frames_left)];
|
||||||
|
for (int i = 0; i < nframes; i++)
|
||||||
|
{
|
||||||
|
*sample_ptr++ = *pcm_ptr++ * dig_vol_mult_l;
|
||||||
|
*sample_ptr++ = *pcm_ptr++ * dig_vol_mult_r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
/* Rockbox and PCM have same format: memcopy */
|
/* Rockbox and PCM have same format: memcopy */
|
||||||
memcpy(&frames[2*(period_size-frames_left)], pcm_data, nframes * 4);
|
memcpy(&frames[2*(period_size-frames_left)], pcm_data, nframes * 4);
|
||||||
|
}
|
||||||
#ifdef HAVE_RECORDING
|
#ifdef HAVE_RECORDING
|
||||||
break;
|
break;
|
||||||
case SND_PCM_STREAM_CAPTURE:
|
case SND_PCM_STREAM_CAPTURE:
|
||||||
memcpy(pcm_data_rec, &frames[2*(period_size-frames_left)], nframes * 4);
|
memcpy(pcm_data_rec, &frames[2*(period_size-frames_left)], nframes * 4);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
pcm_data += nframes*4;
|
pcm_data += nframes*4;
|
||||||
pcm_size -= nframes*4;
|
pcm_size -= nframes*4;
|
||||||
frames_left -= nframes;
|
frames_left -= nframes;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#if defined(SONY_NWZ_LINUX) || defined(HAVE_FIIO_LINUX_CODEC)
|
#if defined(HAVE_ALSA_32BIT)
|
||||||
/* Set the PCM volume in dB: each sample with have this volume applied digitally
|
/* Set the PCM volume in dB: each sample with have this volume applied digitally
|
||||||
* before being sent to ALSA. Volume must satisfy -43 <= dB <= 0 */
|
* before being sent to ALSA. Volume must satisfy -43 <= dB <= 0 */
|
||||||
void pcm_set_mixer_volume(int vol_db_l, int vol_db_r);
|
void pcm_set_mixer_volume(int vol_db_l, int vol_db_r);
|
||||||
|
|
Loading…
Reference in a new issue