summaryrefslogtreecommitdiffstats
path: root/firmware/target/hosted/pcm-alsa.c
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2021-04-08 23:02:15 -0400
committerSolomon Peachy <pizza@shaftnet.org>2021-04-08 23:02:15 -0400
commit54fcb907c1c0397973208debea876ef5753d529c (patch)
tree89baa84fbecab815af6db2ca4b8623603a617da8 /firmware/target/hosted/pcm-alsa.c
parente17337c9aab231875234e0485f7175a5a613fb4c (diff)
downloadrockbox-54fcb907c1c0397973208debea876ef5753d529c.tar.gz
rockbox-54fcb907c1c0397973208debea876ef5753d529c.tar.bz2
rockbox-54fcb907c1c0397973208debea876ef5753d529c.zip
alsa: instead of per-target tests, use HAVE_ALSA_32BIT
Affects all Sony NWZ (linux) and the fiio m3k linux targets. Change-Id: I2fcf121bd026103d2b72332a5a52cc2b5e93949f
Diffstat (limited to 'firmware/target/hosted/pcm-alsa.c')
-rw-r--r--firmware/target/hosted/pcm-alsa.c54
1 files changed, 29 insertions, 25 deletions
diff --git a/firmware/target/hosted/pcm-alsa.c b/firmware/target/hosted/pcm-alsa.c
index 1854f67ba0..e2f8a346a9 100644
--- a/firmware/target/hosted/pcm-alsa.c
+++ b/firmware/target/hosted/pcm-alsa.c
@@ -69,8 +69,7 @@
#endif
static const snd_pcm_access_t access_ = SND_PCM_ACCESS_RW_INTERLEAVED; /* access mode */
-#if defined(SONY_NWZ_LINUX) || defined(HAVE_FIIO_LINUX_CODEC)
-/* Sony NWZ must use 32-bit per sample */
+#if defined(HAE_ALSA_32BIT)
static const snd_pcm_format_t format = SND_PCM_FORMAT_S32_LE; /* sample format */
typedef int32_t sample_t;
#else
@@ -262,6 +261,7 @@ error:
return err;
}
+#if defined(HAVE_ALSA_32BIT)
/* Digital volume explanation:
* 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
@@ -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);
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() */
static bool copy_frames(bool first)
@@ -343,37 +344,40 @@ static bool copy_frames(bool first)
panicf("Wrong pcm_size");
/* the compiler will optimize this test away */
nframes = MIN((ssize_t)pcm_size/4, frames_left);
- if (format == SND_PCM_FORMAT_S32_LE)
+
+#ifdef HAVE_RECORDING
+ switch (current_alsa_mode)
{
- /* 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++)
+ case SND_PCM_STREAM_PLAYBACK:
+#endif
+#if defined(HAVE_ALSA_32BIT)
+ if (format == SND_PCM_FORMAT_S32_LE)
{
- *sample_ptr++ = *pcm_ptr++ * dig_vol_mult_l;
- *sample_ptr++ = *pcm_ptr++ * dig_vol_mult_r;
+ /* 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
- switch (current_alsa_mode)
- {
- case SND_PCM_STREAM_PLAYBACK:
+ else
#endif
+ {
/* Rockbox and PCM have same format: memcopy */
memcpy(&frames[2*(period_size-frames_left)], pcm_data, nframes * 4);
+ }
#ifdef HAVE_RECORDING
- break;
- case SND_PCM_STREAM_CAPTURE:
- memcpy(pcm_data_rec, &frames[2*(period_size-frames_left)], nframes * 4);
- break;
- default:
- break;
- }
-#endif
+ break;
+ case SND_PCM_STREAM_CAPTURE:
+ memcpy(pcm_data_rec, &frames[2*(period_size-frames_left)], nframes * 4);
+ break;
+ default:
+ break;
}
+#endif
pcm_data += nframes*4;
pcm_size -= nframes*4;
frames_left -= nframes;