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
This commit is contained in:
Solomon Peachy 2026-03-02 12:14:34 -05:00
parent be1e074800
commit ea570c5728
14 changed files with 28 additions and 44 deletions

View file

@ -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,

View file

@ -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);

View file

@ -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

View file

@ -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;

View file

@ -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. */

View file

@ -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

View file

@ -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);

View file

@ -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;

View file

@ -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))

View file

@ -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

View file

@ -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 **/

View file

@ -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];

View file

@ -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 */

View file

@ -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)