pcm: Make more of the low-level PCM API private

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit ea570c5728f256d40f27df57e78183bf02c5f7a6
Author: Solomon Peachy <[email protected]>
Date:   Mon Mar 2 12:14:34 2026 -0500

    pcm:  Make more of the low-level PCM API private
    
     * pcm_play_data
     * pcm_play_stop
     * pcm_play_stop_int
     * pcm_is_playing
     * pcm_set_frequency
     * pcm_get_frequency
     * pcm_apply_settings
    
    Now, the only user of these functions are the mixer and recording layers
    that provide a higher-level API to plugins and the main [playback]
    application.
    
    Outside of the PCM core, pcm_apply_settings() was only used immediately
    following a call to mixer_set_frequency(), so the latter function
    now always calls the former.
    
    Change-Id: I61c3144dc156b9de9b7963160b525c6d10c6ad4b

diff --git a/apps/plugin.c b/apps/plugin.c
index d15f88c376..2c0e2e778d 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -644,7 +644,6 @@ static const struct plugin_api rockbox_api = {
 #endif
     &audio_master_sampr_list[0],
     &hw_freq_sampr[0],
-    pcm_apply_settings,
     pcm_play_lock,
     pcm_play_unlock,
     pcm_current_sink_caps,
diff --git a/apps/plugin.h b/apps/plugin.h
index 69cf7659c9..2dcbdbe39f 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -179,7 +179,7 @@ int plugin_open(const char *plugin, const char *parameter);
  * when this happens please take the opportunity to sort in
  * any new functions "waiting" at the end of the list.
  */
-#define PLUGIN_API_VERSION 279
+#define PLUGIN_API_VERSION 280
 
 /* 239 Marks the removal of ARCHOS HWCODEC and CHARCELL */
 
@@ -743,7 +743,6 @@ struct plugin_api {
 #endif
     const unsigned long *audio_master_sampr_list;
     const unsigned long *hw_freq_sampr;
-    void (*pcm_apply_settings)(void);
     void (*pcm_play_lock)(void);
     void (*pcm_play_unlock)(void);
     const struct pcm_sink_caps* (*pcm_current_sink_caps)(void);
diff --git a/apps/plugins/lua/include_lua/pcm.lua b/apps/plugins/lua/include_lua/pcm.lua
index 23f8eb308e..9652c5e3a7 100644
--- a/apps/plugins/lua/include_lua/pcm.lua
+++ b/apps/plugins/lua/include_lua/pcm.lua
@@ -24,6 +24,5 @@
 -- [[ conversion to old style pcm_ functions ]]
 if not rb.pcm then rb.splash(rb.HZ, "No Support!") return nil end
 
-rb.pcm_apply_settings = function() rb.pcm("apply_settings") end
 rb.pcm_play_lock = function() rb.pcm("play_lock") end
 rb.pcm_play_unlock = function() rb.pcm("play_unlock") end
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 0ee104e7fd..4d77afedc0 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -549,10 +549,10 @@ RB_WRAP(sound)
 
 RB_WRAP(pcm)
 {
-    enum e_pcm {PCM_APPLYSETTINGS = 0, PCM_PLAYLOCK, PCM_PLAYUNLOCK,
+    enum e_pcm {PCM_PLAYLOCK = 0, PCM_PLAYUNLOCK,
                 PCM_ECOUNT};
 
-    const char *pcm_option[] = {"apply_settings", "play_lock", "play_unlock",
+    const char *pcm_option[] = {"play_lock", "play_unlock",
                                 NULL};
 
     lua_pushnil(L); /*push nil so options w/o return have something to return */
@@ -560,9 +560,6 @@ RB_WRAP(pcm)
     int option = luaL_checkoption (L, 1, NULL, pcm_option);
     switch(option)
     {
-        case PCM_APPLYSETTINGS:
-            rb->pcm_apply_settings();
-            break;
         case PCM_PLAYLOCK:
             rb->pcm_play_lock();
             break;
diff --git a/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c b/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c
index 17ef90b1d4..5f82f6d393 100644
--- a/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c
+++ b/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c
@@ -64,7 +64,6 @@ void rockbox_open_audio(int rate)
 
     /* Set sample rate of the audio buffer. */
     rb->mixer_set_frequency(rate);
-    rb->pcm_apply_settings();
 
     /* Initialize output buffer. */
     for(i = 0; i < OUTBUFSIZE; i++)
@@ -86,7 +85,6 @@ void rockbox_close_audio(void)
 
     /* Restore default sampling rate. */
     rb->mixer_set_frequency(HW_SAMPR_DEFAULT);
-    rb->pcm_apply_settings();
 }
 
 /* Rockbox audio callback. */
diff --git a/apps/plugins/test_sampr.c b/apps/plugins/test_sampr.c
index 10571a2d98..c73e131072 100644
--- a/apps/plugins/test_sampr.c
+++ b/apps/plugins/test_sampr.c
@@ -168,7 +168,6 @@ static void set_frequency(int index)
     update_gen_step();
 
     rb->mixer_set_frequency(hw_sampr);
-    rb->pcm_apply_settings();
 }
 
 #ifndef HAVE_VOLUME_IN_LIST
diff --git a/apps/plugins/xrick/system/syssnd_rockbox.c b/apps/plugins/xrick/system/syssnd_rockbox.c
index dd522cd6f7..afd0766863 100644
--- a/apps/plugins/xrick/system/syssnd_rockbox.c
+++ b/apps/plugins/xrick/system/syssnd_rockbox.c
@@ -253,7 +253,6 @@ bool syssnd_init(void)
 #endif
 
     rb->mixer_set_frequency(HW_FREQ_44);
-    rb->pcm_apply_settings();
 
     rb->memset(channels, 0, sizeof(channels));
     rb->memset(mixBuffers, 0, sizeof(mixBuffers));
@@ -286,7 +285,6 @@ void syssnd_shutdown(void)
 
     /* Restore default sampling rate. */
     rb->mixer_set_frequency(HW_SAMPR_DEFAULT);
-    rb->pcm_apply_settings();
 
     rb->talk_disable(false);
 
diff --git a/apps/recorder/pcm_record.c b/apps/recorder/pcm_record.c
index 01f0e604dd..0d5581563f 100644
--- a/apps/recorder/pcm_record.c
+++ b/apps/recorder/pcm_record.c
@@ -616,6 +616,10 @@ static void init_state(void)
     record_status = RECORD_STOPPED;
 }
 
+/* To avoid having to pull in all of pcm-internal.h */
+void pcm_set_frequency(unsigned int samplerate);
+void pcm_apply_settings(void);
+
 /* Set hardware samplerate and save it */
 static void update_samplerate_config(unsigned long sampr)
 {
@@ -876,7 +880,7 @@ copy_buffer_mono_lr(void *dst, const void *src, size_t src_size)
     int16_t *d = (int16_t*) dst;
     int16_t const *s = (int16_t const*) src;
     ssize_t copy_size = src_size;
- 
+
      /* mono = (L + R) / 2 */
     while(copy_size > 0) {
         *d++ = ((int32_t)s[0] + (int32_t)s[1] + 1) >> 1;
diff --git a/docs/PLUGIN_API b/docs/PLUGIN_API
index 8fdc10f9eb..65bf9d4c5b 100644
--- a/docs/PLUGIN_API
+++ b/docs/PLUGIN_API
@@ -1754,10 +1754,6 @@ void pcmbuf_set_low_latency(bool state)
     \param state
     \description
 
-void pcm_apply_settings(void)
-    \group sound
-    \description
-
 void pcm_calculate_rec_peaks(int *left, int *right)
     \group sound
     \conditions (defined(HAVE_RECORDING))
diff --git a/firmware/export/pcm-internal.h b/firmware/export/pcm-internal.h
index 4e9cb58c91..4b4890d35a 100644
--- a/firmware/export/pcm-internal.h
+++ b/firmware/export/pcm-internal.h
@@ -71,6 +71,20 @@ void pcm_sync_pcm_factors(void);
     ({ (start) = (void *)(((uintptr_t)(start) + 3) & ~3); \
        (size) &= ~3; })
 
+/* Internal PCM API calls for playback */
+void pcm_play_data(pcm_play_callback_type get_more,
+                   pcm_status_callback_type status_cb,
+                   const void *start, size_t size);
+
+void pcm_play_stop(void);
+void pcm_play_stop_int(void); /* requires PCM lock held */
+bool pcm_is_playing(void);
+
+void pcm_set_frequency(unsigned int samplerate);
+unsigned int pcm_get_frequency(void);
+/* apply settings to hardware immediately */
+void pcm_apply_settings(void);
+
 void pcm_do_peak_calculation(struct pcm_peaks *peaks, bool active,
                              const void *addr, int count);
 
@@ -125,7 +139,6 @@ pcm_play_dma_status_callback(enum pcm_dma_status status)
 #if defined(HAVE_SW_VOLUME_CONTROL) && !defined(PCM_SW_VOLUME_UNBUFFERED)
 void pcm_play_dma_start_int(const void *addr, size_t size);
 void pcm_play_dma_stop_int(void);
-void pcm_play_stop_int(void);
 #endif /* HAVE_SW_VOLUME_CONTROL && !PCM_SW_VOLUME_UNBUFFERED */
 
 /* Called by the bottom layer ISR when more data is needed. Returns true
diff --git a/firmware/export/pcm.h b/firmware/export/pcm.h
index 8c5170ac0e..5f1509ad97 100644
--- a/firmware/export/pcm.h
+++ b/firmware/export/pcm.h
@@ -44,7 +44,7 @@ typedef void (*pcm_play_callback_type)(const void **start, size_t *size);
 /* Typedef for registered status callback */
 typedef enum pcm_dma_status (*pcm_status_callback_type)(enum pcm_dma_status status);
 
-/* set the pcm frequency - use values in hw_sampr_list 
+/* set the pcm frequency - use values in hw_sampr_list
  * when CONFIG_SAMPR_TYPES is #defined, or-in SAMPR_TYPE_* fields with
  * frequency value. SAMPR_TYPE_PLAY is 0 and the default if none is
  * specified. */
@@ -54,15 +54,6 @@ unsigned int pcm_sampr_type_rec_to_play(unsigned int samplerate);
 #endif
 #endif /* CONFIG_SAMPR_TYPES */
 
-/* set next frequency to be used */
-void pcm_set_frequency(unsigned int samplerate);
-/* return last-set frequency */
-unsigned int pcm_get_frequency(void);
-/* apply settings to hardware immediately */
-void pcm_apply_settings(void);
-
-/** RAW PCM playback routines **/
-
 /* Reenterable locks for locking and unlocking the playback interrupt */
 void pcm_play_lock(void);
 void pcm_play_unlock(void);
@@ -77,11 +68,6 @@ const struct pcm_sink_caps* pcm_sink_caps(enum pcm_sink_ids sink);
 /* shortcut for plugins */
 const struct pcm_sink_caps* pcm_current_sink_caps(void);
 
-/* This is for playing "raw" PCM data */
-void pcm_play_data(pcm_play_callback_type get_more,
-                   pcm_status_callback_type status_cb,
-                   const void *start, size_t size);
-
 /* Kept internally for global PCM and used by mixer's verion of peak
    calculation */
 struct pcm_peaks
@@ -92,9 +78,6 @@ struct pcm_peaks
     long tick;      /* Last tick called */
 };
 
-void pcm_play_stop(void);
-bool pcm_is_playing(void);
-
 #ifdef HAVE_RECORDING
 
 /** RAW PCM recording routines **/
diff --git a/firmware/pcm.c b/firmware/pcm.c
index c19ed8e070..0cee855fcc 100644
--- a/firmware/pcm.c
+++ b/firmware/pcm.c
@@ -94,8 +94,6 @@ volatile pcm_status_callback_type
 /* PCM playback state */
 volatile bool pcm_playing SHAREDBSS_ATTR = false;
 
-void pcm_play_stop_int(void);
-
 struct pcm_sink* pcm_get_current_sink(void)
 {
     return sinks[cur_sink];
diff --git a/firmware/pcm_mixer.c b/firmware/pcm_mixer.c
index ca48e3ba10..d36560f149 100644
--- a/firmware/pcm_mixer.c
+++ b/firmware/pcm_mixer.c
@@ -475,6 +475,9 @@ void mixer_set_frequency(unsigned int samplerate)
         mix_frame_size = 1;
 
     mix_frame_size *= MIX_FRAME_SAMPLES * 4;
+
+    if (pcm_is_initialized())
+        pcm_apply_settings();
 }
 
 /* Get output samplerate */
diff --git a/firmware/usbstack/usb_audio.c b/firmware/usbstack/usb_audio.c
index 3e7bab7f45..f8d431705f 100644
--- a/firmware/usbstack/usb_audio.c
+++ b/firmware/usbstack/usb_audio.c
@@ -493,7 +493,6 @@ static void set_playback_sampling_frequency(unsigned long f)
         hw_freq_sampr[as_playback_freq_idx], f);
 
     mixer_set_frequency(hw_freq_sampr[as_playback_freq_idx]);
-    pcm_apply_settings();
 }
 
 unsigned long usb_audio_get_playback_sampling_frequency(void)
@@ -706,7 +705,6 @@ static void usb_audio_start_playback(void)
 #endif
     logf("usbaudio: start playback at %lu Hz", hw_freq_sampr[as_playback_freq_idx]);
     mixer_set_frequency(hw_freq_sampr[as_playback_freq_idx]);
-    pcm_apply_settings();
     mixer_channel_set_amplitude(PCM_MIXER_CHAN_USBAUDIO, MIX_AMP_UNITY);
 
     usb_drv_recv_nonblocking(EP_ISO_OUT, rx_buffer, BUFFER_SIZE);
@@ -787,7 +785,7 @@ int usb_audio_get_alt_intf(void)
 {
     return usb_as_playback_intf_alt;
 }
-    
+
 int32_t usb_audio_get_samplesperframe(void)
 {
     return samples_fb;
@@ -1348,7 +1346,7 @@ bool usb_audio_fast_transfer_complete(int ep, int dir, int status, int length)
     {
         retval = false;
     }
-    
+
     // send feedback value every N frames!
     // NOTE: important that we need to queue this up _the frame before_ it's needed - on MacOS especially!
     if ((usb_drv_get_frame_number()+1) % FEEDBACK_UPDATE_RATE_FRAMES == 0 && send_fb)
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.