diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2021-04-08 23:02:15 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2021-04-08 23:02:15 -0400 |
commit | 54fcb907c1c0397973208debea876ef5753d529c (patch) | |
tree | 89baa84fbecab815af6db2ca4b8623603a617da8 | |
parent | e17337c9aab231875234e0485f7175a5a613fb4c (diff) | |
download | rockbox-54fcb907c1c0397973208debea876ef5753d529c.tar.gz 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
-rw-r--r-- | firmware/export/config/fiiom3klinux.h | 1 | ||||
-rw-r--r-- | firmware/export/config/sonynwzlinux.h | 1 | ||||
-rw-r--r-- | firmware/target/hosted/pcm-alsa.c | 54 | ||||
-rw-r--r-- | firmware/target/hosted/pcm-alsa.h | 2 |
4 files changed, 32 insertions, 26 deletions
diff --git a/firmware/export/config/fiiom3klinux.h b/firmware/export/config/fiiom3klinux.h index c383242909..fea464c2de 100644 --- a/firmware/export/config/fiiom3klinux.h +++ b/firmware/export/config/fiiom3klinux.h | |||
@@ -117,6 +117,7 @@ | |||
117 | 117 | ||
118 | /* Audio codec */ | 118 | /* Audio codec */ |
119 | #define HAVE_FIIO_LINUX_CODEC | 119 | #define HAVE_FIIO_LINUX_CODEC |
120 | #define HAVE_ALSA_32BIT | ||
120 | 121 | ||
121 | /* We don't have hardware controls */ | 122 | /* We don't have hardware controls */ |
122 | #define HAVE_SW_TONE_CONTROLS | 123 | #define HAVE_SW_TONE_CONTROLS |
diff --git a/firmware/export/config/sonynwzlinux.h b/firmware/export/config/sonynwzlinux.h index 06120b455b..ffd6778867 100644 --- a/firmware/export/config/sonynwzlinux.h +++ b/firmware/export/config/sonynwzlinux.h | |||
@@ -82,6 +82,7 @@ | |||
82 | 82 | ||
83 | /* Audio codec */ | 83 | /* Audio codec */ |
84 | #define HAVE_NWZ_LINUX_CODEC | 84 | #define HAVE_NWZ_LINUX_CODEC |
85 | #define HAVE_ALSA_32BIT | ||
85 | 86 | ||
86 | #endif /* SIMULATOR */ | 87 | #endif /* SIMULATOR */ |
87 | 88 | ||
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 @@ | |||
69 | #endif | 69 | #endif |
70 | 70 | ||
71 | static const snd_pcm_access_t access_ = SND_PCM_ACCESS_RW_INTERLEAVED; /* access mode */ | 71 | static const snd_pcm_access_t access_ = SND_PCM_ACCESS_RW_INTERLEAVED; /* access mode */ |
72 | #if defined(SONY_NWZ_LINUX) || defined(HAVE_FIIO_LINUX_CODEC) | 72 | #if defined(HAE_ALSA_32BIT) |
73 | /* Sony NWZ must use 32-bit per sample */ | ||
74 | static const snd_pcm_format_t format = SND_PCM_FORMAT_S32_LE; /* sample format */ | 73 | static const snd_pcm_format_t format = SND_PCM_FORMAT_S32_LE; /* sample format */ |
75 | typedef int32_t sample_t; | 74 | typedef int32_t sample_t; |
76 | #else | 75 | #else |
@@ -262,6 +261,7 @@ error: | |||
262 | return err; | 261 | return err; |
263 | } | 262 | } |
264 | 263 | ||
264 | #if defined(HAVE_ALSA_32BIT) | ||
265 | /* Digital volume explanation: | 265 | /* Digital volume explanation: |
266 | * with very good approximation (<0.1dB) the convertion from dB to multiplicative | 266 | * with very good approximation (<0.1dB) the convertion from dB to multiplicative |
267 | * factor, for dB>=0, is 2^(dB/3). We can then notice that if we write dB=3*k+r | 267 | * 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) | |||
303 | dig_vol_mult_r = 1 << vol_shift_r | 1 << (vol_shift_r - 1); | 303 | dig_vol_mult_r = 1 << vol_shift_r | 1 << (vol_shift_r - 1); |
304 | logf("r: %d dB -> factor = %d", vol_db_r - 48, dig_vol_mult_r); | 304 | logf("r: %d dB -> factor = %d", vol_db_r - 48, dig_vol_mult_r); |
305 | } | 305 | } |
306 | #endif | ||
306 | 307 | ||
307 | /* copy pcm samples to a spare buffer, suitable for snd_pcm_writei() */ | 308 | /* copy pcm samples to a spare buffer, suitable for snd_pcm_writei() */ |
308 | static bool copy_frames(bool first) | 309 | static bool copy_frames(bool first) |
@@ -343,37 +344,40 @@ static bool copy_frames(bool first) | |||
343 | panicf("Wrong pcm_size"); | 344 | panicf("Wrong pcm_size"); |
344 | /* the compiler will optimize this test away */ | 345 | /* the compiler will optimize this test away */ |
345 | nframes = MIN((ssize_t)pcm_size/4, frames_left); | 346 | nframes = MIN((ssize_t)pcm_size/4, frames_left); |
346 | if (format == SND_PCM_FORMAT_S32_LE) | 347 | |
348 | #ifdef HAVE_RECORDING | ||
349 | switch (current_alsa_mode) | ||
347 | { | 350 | { |
348 | /* We have to convert 16-bit to 32-bit, the need to multiply the | 351 | case SND_PCM_STREAM_PLAYBACK: |
349 | * sample by some value so the sound is not too low */ | 352 | #endif |
350 | const int16_t *pcm_ptr = pcm_data; | 353 | #if defined(HAVE_ALSA_32BIT) |
351 | sample_t *sample_ptr = &frames[2*(period_size-frames_left)]; | 354 | if (format == SND_PCM_FORMAT_S32_LE) |
352 | for (int i = 0; i < nframes; i++) | ||
353 | { | 355 | { |
354 | *sample_ptr++ = *pcm_ptr++ * dig_vol_mult_l; | 356 | /* We have to convert 16-bit to 32-bit, the need to multiply the |
355 | *sample_ptr++ = *pcm_ptr++ * dig_vol_mult_r; | 357 | * sample by some value so the sound is not too low */ |
358 | const int16_t *pcm_ptr = pcm_data; | ||
359 | sample_t *sample_ptr = &frames[2*(period_size-frames_left)]; | ||
360 | for (int i = 0; i < nframes; i++) | ||
361 | { | ||
362 | *sample_ptr++ = *pcm_ptr++ * dig_vol_mult_l; | ||
363 | *sample_ptr++ = *pcm_ptr++ * dig_vol_mult_r; | ||
364 | } | ||
356 | } | 365 | } |
357 | } | 366 | else |
358 | else | ||
359 | { | ||
360 | #ifdef HAVE_RECORDING | ||
361 | switch (current_alsa_mode) | ||
362 | { | ||
363 | case SND_PCM_STREAM_PLAYBACK: | ||
364 | #endif | 367 | #endif |
368 | { | ||
365 | /* Rockbox and PCM have same format: memcopy */ | 369 | /* Rockbox and PCM have same format: memcopy */ |
366 | memcpy(&frames[2*(period_size-frames_left)], pcm_data, nframes * 4); | 370 | memcpy(&frames[2*(period_size-frames_left)], pcm_data, nframes * 4); |
371 | } | ||
367 | #ifdef HAVE_RECORDING | 372 | #ifdef HAVE_RECORDING |
368 | break; | 373 | break; |
369 | case SND_PCM_STREAM_CAPTURE: | 374 | case SND_PCM_STREAM_CAPTURE: |
370 | memcpy(pcm_data_rec, &frames[2*(period_size-frames_left)], nframes * 4); | 375 | memcpy(pcm_data_rec, &frames[2*(period_size-frames_left)], nframes * 4); |
371 | break; | 376 | break; |
372 | default: | 377 | default: |
373 | break; | 378 | break; |
374 | } | ||
375 | #endif | ||
376 | } | 379 | } |
380 | #endif | ||
377 | pcm_data += nframes*4; | 381 | pcm_data += nframes*4; |
378 | pcm_size -= nframes*4; | 382 | pcm_size -= nframes*4; |
379 | frames_left -= nframes; | 383 | frames_left -= nframes; |
diff --git a/firmware/target/hosted/pcm-alsa.h b/firmware/target/hosted/pcm-alsa.h index 4c0b0d0b9d..f35be60074 100644 --- a/firmware/target/hosted/pcm-alsa.h +++ b/firmware/target/hosted/pcm-alsa.h | |||
@@ -22,7 +22,7 @@ | |||
22 | 22 | ||
23 | #include <config.h> | 23 | #include <config.h> |
24 | 24 | ||
25 | #if defined(SONY_NWZ_LINUX) || defined(HAVE_FIIO_LINUX_CODEC) | 25 | #if defined(HAVE_ALSA_32BIT) |
26 | /* Set the PCM volume in dB: each sample with have this volume applied digitally | 26 | /* Set the PCM volume in dB: each sample with have this volume applied digitally |
27 | * before being sent to ALSA. Volume must satisfy -43 <= dB <= 0 */ | 27 | * before being sent to ALSA. Volume must satisfy -43 <= dB <= 0 */ |
28 | void pcm_set_mixer_volume(int vol_db_l, int vol_db_r); | 28 | void pcm_set_mixer_volume(int vol_db_l, int vol_db_r); |