summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2019-08-07 17:16:48 -0400
committerSolomon Peachy <pizza@shaftnet.org>2019-08-08 22:37:30 +0200
commit5b23c9eb0a97534f0d0fc3aa0c1ad302199eb8dc (patch)
tree7151fdb71b085b9a43113832c0d478b84bfbbf49
parenta430e275dddab24059ba15d2621e518562392540 (diff)
downloadrockbox-5b23c9eb0a97534f0d0fc3aa0c1ad302199eb8dc.tar.gz
rockbox-5b23c9eb0a97534f0d0fc3aa0c1ad302199eb8dc.zip
Introduce HW_SAMPR_MIN_GE_22 macro
Gives us the lowest HW sample rate that's >= 22KHz. Needed because some targets that don't support 22K support 11K or 8K, so HW_SAMPR_MIN will give us much lower quality than is acceptable. Take advantage of this new macro in the SDL, MIDI, and MIKMOD plugins, and implement a crude "fast enough" test to enable higher sample rates on more capable targets. Change-Id: I6ad38026fb3410c62da028e78512e027729bb851
-rw-r--r--apps/plugins/midi/midiutil.h57
-rw-r--r--apps/plugins/mikmod/mikmod_supp.h23
-rw-r--r--apps/plugins/sdl/include/SDL_config_rockbox.h6
-rw-r--r--firmware/export/pcm_sampr.h16
4 files changed, 87 insertions, 15 deletions
diff --git a/apps/plugins/midi/midiutil.h b/apps/plugins/midi/midiutil.h
index 72bff11b3f..ee9769b108 100644
--- a/apps/plugins/midi/midiutil.h
+++ b/apps/plugins/midi/midiutil.h
@@ -27,28 +27,67 @@
#define NBUF 2
#define MAX_SAMPLES 512
-#ifndef SIMULATOR
+#ifdef SIMULATOR
-#define SAMPLE_RATE SAMPR_44 /* 44100 */
+/* Simulator requires 44100Hz, and we can afford to use more voices */
+#define SAMPLE_RATE SAMPR_44
+#define MAX_VOICES 48
+
+#elif (CONFIG_PLATFORM & PLATFORM_HOSTED)
+
+/* All hosted targets have CPU to spare */
+#define MAX_VOICES 48
+#define SAMPLE_RATE SAMPR_44
+
+#elif defined(CPU_PP)
/* Some of the pp based targets can't handle too many voices
mainly because they have to use 44100Hz sample rate, this could be
improved to increase MAX_VOICES for targets that can do 22kHz */
-#ifdef CPU_PP
+#define SAMPLE_RATE HW_SAMPR_MIN_GE_22
+#if HW_SAMPR_CAPS & SAMPR_CAP_22
+#define MAX_VOICES 24 /* General MIDI minimum */
+#else
#define MAX_VOICES 16
-#elif (CONFIG_PLATFORM & PLATFORM_HOSTED)
+#endif
+
+#elif defined(CPU_MIPS)
+
+/* All MIPS targets are pretty fast */
#define MAX_VOICES 48
-#else
-#define MAX_VOICES 24 /* Note: 24 midi channels is the minimum general midi spec implementation */
-#endif /* CPU_PP */
+#define SAMPLE_RATE SAMPR_44
-#else /* Simulator requires 44100Hz, and we can afford to use more voices */
+#elif defined(CPU_ARM)
+/* ARMv4 targets are slow, but treat everything else as fast */
+
+#if (ARM_ARCH >= 6)
+#define MAX_VOICES 32
#define SAMPLE_RATE SAMPR_44
-#define MAX_VOICES 48
+#elif (ARM_ARCH >= 5)
+#define MAX_VOICES 32
+#define SAMPLE_RATE HW_SAMPR_MIN_GE_22
+#else /* ie v4 */
+#define SAMPLE_RATE HW_SAMPR_MIN_GE_22
+#if HW_SAMPR_CAPS & SAMPR_CAP_22
+#define MAX_VOICES 24 /* General MIDI minimum */
+#else
+#define MAX_VOICES 16
+#endif
+#endif /* ARM_ARCH < 5*/
+
+#else /* !CPU_ARM */
+/* Treat everything else as slow */
+#define SAMPLE_RATE HW_SAMPR_MIN_GE_22
+#if HW_SAMPR_CAPS & SAMPR_CAP_22
+#define MAX_VOICES 24 /* General MIDI minimum */
+#else
+#define MAX_VOICES 16
#endif
+#endif /* Wrap it up. */
+
#define BYTE unsigned char
/* Data chunk ID types, returned by readID() */
diff --git a/apps/plugins/mikmod/mikmod_supp.h b/apps/plugins/mikmod/mikmod_supp.h
index 29fa7ebf35..ad8aaafebc 100644
--- a/apps/plugins/mikmod/mikmod_supp.h
+++ b/apps/plugins/mikmod/mikmod_supp.h
@@ -63,8 +63,29 @@ int mmsupp_sprintf(char *buf, const char *fmt, ... );
extern const struct plugin_api * rb;
+#ifdef SIMULATOR
-#define SAMPLE_RATE SAMPR_44 /* 44100 */
+#define SAMPLE_RATE SAMPR_44 /* Required by Simulator */
+
+#elif ((CONFIG_PLATFORM & PLATFORM_HOSTED) || defined(CPU_MIPS))
+
+#define SAMPLE_RATE SAMPR_44 /* All MIPS and hosted targets are fast */
+
+#elif defined(CPU_ARM)
+
+/* Treat ARMv5+ as fast */
+#if (ARM_ARCH >= 5)
+#define SAMPLE_RATE SAMPR_44
+#else
+#define SAMPLE_RATE SAMPR_MIN_GE_22
+#endif
+
+#else /* !CPU_ARM */
+
+/* Treat everyone else as slow */
+#define SAMPLE_RATE HW_SAMPR_MIN_GE_22
+
+#endif /* !SIMULATOR */
#define BUF_SIZE 4096*8
#define NBUF 2
diff --git a/apps/plugins/sdl/include/SDL_config_rockbox.h b/apps/plugins/sdl/include/SDL_config_rockbox.h
index 40bd7fe177..91183ebf88 100644
--- a/apps/plugins/sdl/include/SDL_config_rockbox.h
+++ b/apps/plugins/sdl/include/SDL_config_rockbox.h
@@ -47,11 +47,7 @@
#ifdef SIMULATOR
#define RB_SAMPR SAMPR_44
#else
-#if HW_SAMPR_CAPS & SAMPR_CAP_22
-#define RB_SAMPR SAMPR_22
-#else
-#define RB_SAMPR HW_SAMPR_MIN
-#endif
+#define RB_SAMPR HW_SAMPR_MIN_GE_22 /* Min HW rate at least 22KHz */
#endif
/* Enable the stub cdrom driver (src/cdrom/dummy/\*.c) */
diff --git a/firmware/export/pcm_sampr.h b/firmware/export/pcm_sampr.h
index dcb1bdd80f..84f4466308 100644
--- a/firmware/export/pcm_sampr.h
+++ b/firmware/export/pcm_sampr.h
@@ -80,6 +80,11 @@
SAMPR_CAP_24 | SAMPR_CAP_22 | SAMPR_CAP_16 | \
SAMPR_CAP_12 | SAMPR_CAP_11 | SAMPR_CAP_8)
+/* List of sampling rates that are good enough for most purposes. */
+#define SAMPR_CAP_ALL_GE_22 (SAMPR_CAP_96 | SAMPR_CAP_88 | SAMPR_CAP_64 | \
+ SAMPR_CAP_48 | SAMPR_CAP_44 | SAMPR_CAP_32 | \
+ SAMPR_CAP_24 | SAMPR_CAP_22)
+
#ifndef PCM_SAMPR_CONFIG_ONLY
/* Master list of all "standard" rates supported. */
extern const unsigned long audio_master_sampr_list[SAMPR_NUM_FREQ];
@@ -231,6 +236,17 @@ extern const unsigned long hw_freq_sampr[HW_NUM_FREQ];
# define HW_SAMPR_MIN SAMPR_44
#endif
+#define HW_SAMPR_CAPS_QUAL (HW_SAMPR_CAPS & SAMPR_CAP_ALL_GE_22)
+#if HW_SAMPR_CAPS_QUAL & SAMPR_CAP_22
+# define HW_SAMPR_MIN_GE_22 SAMPR_22
+#elif HW_SAMPR_CAPS_QUAL & SAMPR_CAP_24
+# define HW_SAMPR_MIN_GE_22 SAMPR_24
+#elif HW_SAMPR_CAPS_QUAL & SAMPR_CAP_32
+# define HW_SAMPR_MIN_GE_22 SAMPR_32
+#else
+# define HW_SAMPR_MIN_GE_22 SAMPR_44
+#endif
+
#ifdef HAVE_RECORDING
#ifndef PCM_SAMPR_CONFIG_ONLY