···3333 before the last samples are sent to the codec and so things are done in
3434 parallel (as much as possible) with sending-out data. */
35353636-static unsigned int mixer_sampr = -1U;
3736static unsigned int mix_frame_size = MIX_FRAME_SAMPLES*4;
38373938/* Define this to nonzero to add a marker pulse at each frame start */
···7574static struct mixer_channel * active_channels[PCM_MIXER_NUM_CHANNELS+1] IBSS_ATTR;
76757776/* Number of silence frames to play after all data has played */
7878-#define MAX_IDLE_FRAMES (mixer_sampr*3 / (mix_frame_size / 4))
7977static unsigned int idle_counter = 0;
80787979+#ifdef CONFIG_SAMPR_TYPES
8080+#define SAMPR_NUM(sampr) (sampr & ~SAMPR_TYPE_MASK)
8181+#else
8282+#define SAMPR_NUM(sampr) (sampr)
8383+#endif
8484+8585+static inline unsigned int max_idle_frames(void)
8686+{
8787+ return SAMPR_NUM(pcm_get_frequency()) * 3 / (mix_frame_size / 4);
8888+}
8989+8190/** Mixing routines, CPU optmized **/
8291#include "asm/pcm-mixer.c"
8392···233242 goto fill_frame;
234243 }
235244 }
236236- else if (idle_counter++ < MAX_IDLE_FRAMES)
245245+ else if (idle_counter++ < max_idle_frames())
237246 {
238247 /* Pad incomplete frames with silence */
239248 if (idle_counter <= 3)
···265274 return;
266275#endif
267276268268- /* Requires a shared global sample rate for all channels */
269269- if (mixer_sampr == -1U)
270270- mixer_sampr = pcm_get_frequency();
271271- else
272272- pcm_set_frequency(mixer_sampr);
273273-274277 /* Prepare initial frames and set up the double buffer */
275278 mixer_buffer_callback(PCM_DMAST_STARTED);
276279···454457/* Set output samplerate */
455458void mixer_set_frequency(unsigned int samplerate)
456459{
457457- pcm_set_frequency(samplerate);
458458- samplerate = pcm_get_frequency();
460460+ if(pcm_get_frequency() == samplerate)
461461+ return;
459462460460-#ifdef CONFIG_SAMPR_TYPES
461461- samplerate &= ~SAMPR_TYPE_MASK;
462462-#endif
463463-464464- if (samplerate == mixer_sampr)
465465- return;
466466- mixer_sampr = samplerate;
463463+ pcm_set_frequency(samplerate);
467464468465 for (size_t i = 0; i < ARRAYLEN(active_channels) && active_channels[i]; i += 1)
469466 {
···474471 {
475472 if (chan->play_cbs->sampr_changed)
476473 {
477477- chan->play_cbs->sampr_changed(samplerate);
474474+ chan->play_cbs->sampr_changed(SAMPR_NUM(samplerate));
478475 }
479476 if (chan->play_cbs->get_more)
480477 {
···496493 {
497494 if (chan->buf_cbs->sampr_changed)
498495 {
499499- chan->buf_cbs->sampr_changed(samplerate);
496496+ chan->buf_cbs->sampr_changed(SAMPR_NUM(samplerate));
500497 }
501498 }
502499 }
503500504501 /* Work out how much space we really need */
505505- if (samplerate > SAMPR_96)
502502+ if (SAMPR_NUM(samplerate) > SAMPR_96)
506503 mix_frame_size = 4;
507507- else if (samplerate > SAMPR_48)
504504+ else if (SAMPR_NUM(samplerate) > SAMPR_48)
508505 mix_frame_size = 2;
509506 else
510507 mix_frame_size = 1;
···518515/* Get output samplerate */
519516unsigned int mixer_get_frequency(void)
520517{
521521- return mixer_sampr;
518518+ return pcm_get_frequency();
522519}