From 017dd72ff3f787f2c818530293656658d338aa2f Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Sat, 21 Feb 2026 08:02:12 -0500 Subject: [PATCH] plugins: Convert all plugins to using mixer API for playback pcm_play_data -> mixer_channel_play_data pcm_set_frequeny -> mixer_set_frequency pcm_play_stop -> audio_stop at startup / mixer_channel_stop at shutdown pcm_is_playing -> mixer_channel_status All of these have been removed from the plugin API. Updated API docs to clarify role of audio_stop() vs mixer_channel_stop() Todo: get rid of pcm_play_[un]lock(). Change-Id: I8800c131b51f064ee923a4c6e42aa405d33851fc --- apps/plugin.c | 4 - apps/plugin.h | 8 +- apps/plugins/doom/i_sound.c | 10 +- apps/plugins/imageviewer/imageviewer.c | 2 +- apps/plugins/lua/include_lua/pcm.lua | 3 - apps/plugins/lua/rocklib.c | 20 +--- apps/plugins/metronome.c | 15 ++- apps/plugins/midi/midiplay.c | 2 +- apps/plugins/mikmod/mikmod.c | 9 +- apps/plugins/pacbox/pacbox.c | 10 +- apps/plugins/pdbox/PDa/src/s_audio_rockbox.c | 11 +-- apps/plugins/pitch_detector.c | 4 +- apps/plugins/rockboy/rbsound.c | 17 ++-- .../sdl/src/audio/rockbox/SDL_rockboxaudio.c | 8 +- apps/plugins/test_sampr.c | 10 +- apps/plugins/xrick/system/syssnd_rockbox.c | 11 +-- apps/plugins/xworld/sys.c | 4 +- apps/plugins/zxbox/spmain.c | 12 +-- apps/plugins/zxbox/spsound.c | 93 +++++++++---------- apps/plugins/zxbox/zxbox.c | 10 +- docs/PLUGIN_API | 24 +---- firmware/pcm_mixer.c | 4 + 22 files changed, 113 insertions(+), 178 deletions(-) diff --git a/apps/plugin.c b/apps/plugin.c index fd886ea93f..0aa800b5cd 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -645,10 +645,6 @@ static const struct plugin_api rockbox_api = { &audio_master_sampr_list[0], &hw_freq_sampr[0], pcm_apply_settings, - pcm_play_data, - pcm_play_stop, - pcm_set_frequency, - pcm_is_playing, pcm_play_lock, pcm_play_unlock, beep_play, diff --git a/apps/plugin.h b/apps/plugin.h index bc700cbbc1..52c11a5af3 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -178,7 +178,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 278 +#define PLUGIN_API_VERSION 279 /* 239 Marks the removal of ARCHOS HWCODEC and CHARCELL */ @@ -743,12 +743,6 @@ struct plugin_api { const unsigned long *audio_master_sampr_list; const unsigned long *hw_freq_sampr; void (*pcm_apply_settings)(void); - 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_set_frequency)(unsigned int frequency); - bool (*pcm_is_playing)(void); void (*pcm_play_lock)(void); void (*pcm_play_unlock)(void); void (*beep_play)(unsigned int frequency, unsigned int duration, diff --git a/apps/plugins/doom/i_sound.c b/apps/plugins/doom/i_sound.c index bdf70c1215..68fb8bdc6c 100644 --- a/apps/plugins/doom/i_sound.c +++ b/apps/plugins/doom/i_sound.c @@ -471,13 +471,13 @@ void I_SubmitSound(void) if (!enable_sound) return; - rb->pcm_play_data(&get_more, NULL, NULL, 0); + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &get_more, NULL, 0); } void I_ShutdownSound(void) { - rb->pcm_play_stop(); - rb->pcm_set_frequency(HW_SAMPR_DEFAULT); // 44100 + rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); + rb->mixer_set_frequency(HW_SAMPR_DEFAULT); } void I_InitSound() @@ -486,14 +486,14 @@ void I_InitSound() // Initialize external data (all sounds) at start, keep static. printf( "I_InitSound: "); - rb->pcm_play_stop(); + rb->audio_stop(); #if INPUT_SRC_CAPS != 0 /* Select playback */ rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); #endif - rb->pcm_set_frequency(SAMPLERATE); + rb->mixer_set_frequency(SAMPLERATE); vol_lookup=malloc(128*256*sizeof(int)); diff --git a/apps/plugins/imageviewer/imageviewer.c b/apps/plugins/imageviewer/imageviewer.c index b9213decf1..b67ff764aa 100644 --- a/apps/plugins/imageviewer/imageviewer.c +++ b/apps/plugins/imageviewer/imageviewer.c @@ -342,7 +342,7 @@ static int show_menu(void) /* return 1 to quit */ /* slideshow times < 10s keep disk spinning */ rb->storage_spindown(0); } - else if (!rb->pcm_is_playing()) + else if (rb->mixer_channel_status(PCM_MIXER_CHAN_PLAYBACK) != CHANNEL_PLAYING) { /* slideshow times > 10s and not playing: ata_off after load */ iv_api.immediate_ata_off = true; diff --git a/apps/plugins/lua/include_lua/pcm.lua b/apps/plugins/lua/include_lua/pcm.lua index 299f7730e9..23f8eb308e 100644 --- a/apps/plugins/lua/include_lua/pcm.lua +++ b/apps/plugins/lua/include_lua/pcm.lua @@ -25,8 +25,5 @@ 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_set_frequency = function(freq) rb.pcm("set_frequency", freq) end -rb.pcm_play_stop = function() rb.pcm("play_stop") end rb.pcm_play_lock = function() rb.pcm("play_lock") end rb.pcm_play_unlock = function() rb.pcm("play_unlock") end -rb.pcm_is_playing = function() return rb.pcm("is_playing") end diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 4404598ad3..a28b292f47 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c @@ -549,13 +549,11 @@ RB_WRAP(sound) RB_WRAP(pcm) { - enum e_pcm {PCM_APPLYSETTINGS = 0, PCM_ISPLAYING, - PCM_PLAYSTOP, PCM_PLAYLOCK, PCM_PLAYUNLOCK, - PCM_SETFREQUENCY, PCM_ECOUNT}; + enum e_pcm {PCM_APPLYSETTINGS = 0, PCM_PLAYLOCK, PCM_PLAYUNLOCK, + PCM_ECOUNT}; - const char *pcm_option[] = {"apply_settings", "is_playing", - "play_stop", "play_lock", "play_unlock", - "set_frequency", NULL}; + const char *pcm_option[] = {"apply_settings", "play_lock", "play_unlock", + NULL}; bool b_result; lua_pushnil(L); /*push nil so options w/o return have something to return */ @@ -566,22 +564,12 @@ RB_WRAP(pcm) case PCM_APPLYSETTINGS: rb->pcm_apply_settings(); break; - case PCM_ISPLAYING: - b_result = rb->pcm_is_playing(); - lua_pushboolean(L, b_result); - break; - case PCM_PLAYSTOP: - rb->pcm_play_stop(); - break; case PCM_PLAYLOCK: rb->pcm_play_lock(); break; case PCM_PLAYUNLOCK: rb->pcm_play_unlock(); break; - case PCM_SETFREQUENCY: - rb->pcm_set_frequency((unsigned int) luaL_checkint(L, 2)); - break; } yield(); diff --git a/apps/plugins/metronome.c b/apps/plugins/metronome.c index dbbb2b40ac..f7baccf84f 100644 --- a/apps/plugins/metronome.c +++ b/apps/plugins/metronome.c @@ -809,9 +809,6 @@ static int bpm_step_counter = 0; static bool sound_trigger = false; -#define MET_IS_PLAYING rb->pcm_is_playing() -#define MET_PLAY_STOP rb->audio_stop() - /* Really necessary? Cannot just play mono? Also: This is wasted memory! */ static short tick_buf[sizeof(tick_sound)*2]; @@ -829,12 +826,12 @@ static void prepare_buffers(void) static void play_tick(void) { - rb->pcm_play_data(NULL, NULL, tick_buf, sizeof(tick_buf)); + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, NULL, tick_buf, sizeof(tick_buf)); } static void play_tock(void) { - rb->pcm_play_data(NULL, NULL, tock_buf, sizeof(tock_buf)); + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, NULL, tock_buf, sizeof(tock_buf)); } /* State: 0: blank/title, 1: tick, 2: tock 3: silent klick */ @@ -1216,10 +1213,10 @@ static void cleanup(void) if(fd >= 0) rb->close(fd); metronome_pause(); - MET_PLAY_STOP; /* stop audio ISR */ + rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); tweak_volume(0); rb->led(0); - rb->pcm_set_frequency(HW_SAMPR_DEFAULT); + rb->mixer_set_frequency(HW_SAMPR_DEFAULT); } /* @@ -1555,7 +1552,7 @@ enum plugin_status plugin_start(const void* file) mem_init(); - if(MET_IS_PLAYING) MET_PLAY_STOP; /* stop audio IS */ + rb->audio_stop(); prepare_buffers(); #if INPUT_SRC_CAPS != 0 @@ -1563,7 +1560,7 @@ enum plugin_status plugin_start(const void* file) rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); #endif - rb->pcm_set_frequency(SAMPR_44); + rb->mixer_set_frequency(SAMPR_44); if(file) { diff --git a/apps/plugins/midi/midiplay.c b/apps/plugins/midi/midiplay.c index 510b03f789..2689e96ba1 100644 --- a/apps/plugins/midi/midiplay.c +++ b/apps/plugins/midi/midiplay.c @@ -520,7 +520,7 @@ static int midimain(const void * filename) } rb->talk_force_shutup(); - rb->pcm_play_stop(); + rb->audio_stop(); #if INPUT_SRC_CAPS != 0 /* Select playback */ rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); diff --git a/apps/plugins/mikmod/mikmod.c b/apps/plugins/mikmod/mikmod.c index fc12e38c29..ddd4bc3fd6 100644 --- a/apps/plugins/mikmod/mikmod.c +++ b/apps/plugins/mikmod/mikmod.c @@ -536,7 +536,7 @@ static void applysettings(void) if (inited && (md_mixfreq != rb->hw_freq_sampr[settings.sample_rate])) { md_mixfreq = rb->hw_freq_sampr[settings.sample_rate]; // MikMod_Reset(""); BROKEN! - rb->pcm_play_stop(); + rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); rb->mixer_set_frequency(md_mixfreq); rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); } @@ -964,7 +964,7 @@ enum plugin_status plugin_start(const void* parameter) rb->lcd_getstringsize("A", NULL, &font_h); rb->talk_force_shutup(); - rb->pcm_play_stop(); + rb->audio_stop(); #if INPUT_SRC_CAPS != 0 /* Select playback */ rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); @@ -1019,10 +1019,11 @@ enum plugin_status plugin_start(const void* parameter) retval = playfile(np_file); } while (retval == PLUGIN_NEWSONG); - MikMod_Exit(); - rb->pcmbuf_fade(false, false); rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); + + MikMod_Exit(); + rb->mixer_set_frequency(orig_samplerate); if (retval == PLUGIN_OK) diff --git a/apps/plugins/pacbox/pacbox.c b/apps/plugins/pacbox/pacbox.c index c5e9e9c22e..a8208f1e51 100644 --- a/apps/plugins/pacbox/pacbox.c +++ b/apps/plugins/pacbox/pacbox.c @@ -387,6 +387,8 @@ static void start_sound(void) if (sound_playing) return; + rb->audio_stop(); + #ifndef USE_IRAM /* Ensure control of PCM - stopping music itn't obligatory */ rb->plugin_get_audio_buffer(NULL); @@ -405,8 +407,8 @@ static void start_sound(void) wsg3_set_sampling_rate(rb->hw_freq_sampr[sr_index]); - rb->pcm_set_frequency(rb->hw_freq_sampr[sr_index]); - rb->pcm_play_data(get_more, NULL, NULL, 0); + rb->mixer_set_frequency(rb->hw_freq_sampr[sr_index]); + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); sound_playing = true; } @@ -419,8 +421,8 @@ static void stop_sound(void) if (!sound_playing) return; - rb->pcm_play_stop(); - rb->pcm_set_frequency(HW_SAMPR_DEFAULT); + rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); + rb->mixer_set_frequency(HW_SAMPR_DEFAULT); sound_playing = false; } diff --git a/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c b/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c index 6571f74edf..17ef90b1d4 100644 --- a/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c +++ b/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c @@ -54,7 +54,7 @@ void rockbox_open_audio(int rate) playing = false; /* Stop playing to reconfigure audio settings. */ - rb->pcm_play_stop(); + rb->audio_stop(); #if INPUT_SRC_CAPS != 0 /* Select playback */ @@ -63,7 +63,7 @@ void rockbox_open_audio(int rate) #endif /* Set sample rate of the audio buffer. */ - rb->pcm_set_frequency(rate); + rb->mixer_set_frequency(rate); rb->pcm_apply_settings(); /* Initialize output buffer. */ @@ -79,13 +79,13 @@ void rockbox_open_audio(int rate) void rockbox_close_audio(void) { /* Stop playback. */ - rb->pcm_play_stop(); + rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); /* Reset playing status. */ playing = false; /* Restore default sampling rate. */ - rb->pcm_set_frequency(HW_SAMPR_DEFAULT); + rb->mixer_set_frequency(HW_SAMPR_DEFAULT); rb->pcm_apply_settings(); } @@ -183,7 +183,7 @@ int rockbox_send_dacs(void) if(!playing && outbuf_fill > 0) { /* Start playing. */ - rb->pcm_play_data(pdbox_get_more, NULL, NULL, 0); + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, pdbox_get_more, NULL, 0); /* Set status flag. */ playing = true; @@ -191,4 +191,3 @@ int rockbox_send_dacs(void) return SENDDACS_YES; } - diff --git a/apps/plugins/pitch_detector.c b/apps/plugins/pitch_detector.c index 9bed3ff754..a651bb8c26 100644 --- a/apps/plugins/pitch_detector.c +++ b/apps/plugins/pitch_detector.c @@ -1084,7 +1084,7 @@ static void record_and_get_pitch(void) } } rb->pcm_close_recording(); - rb->pcm_set_frequency(HW_SAMPR_RESET | SAMPR_TYPE_REC); + rb->mixer_set_frequency(HW_SAMPR_RESET | SAMPR_TYPE_REC); #ifdef HAVE_SCHEDULER_BOOSTCTRL rb->cancel_cpu_boost(); #endif @@ -1118,7 +1118,7 @@ static void init_everything(void) sample_rate = rb->round_value_to_list32(9000, rb->rec_freq_sampr, REC_NUM_FREQ, false); sample_rate = rb->rec_freq_sampr[sample_rate]; - rb->pcm_set_frequency(sample_rate | SAMPR_TYPE_REC); + rb->mixer_set_frequency(sample_rate | SAMPR_TYPE_REC); rb->pcm_init_recording(); /* avoid divsion by zero */ diff --git a/apps/plugins/rockboy/rbsound.c b/apps/plugins/rockboy/rbsound.c index c36e24b578..60f877471e 100644 --- a/apps/plugins/rockboy/rbsound.c +++ b/apps/plugins/rockboy/rbsound.c @@ -47,24 +47,23 @@ void rockboy_pcm_init(void) pcm.pos = 0; memset(buf, 0, pcm.len * N_BUFS*sizeof(short)); } - - rb->pcm_play_stop(); + rb->audio_stop(); #if INPUT_SRC_CAPS != 0 /* Select playback */ rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); #endif - - rb->pcm_set_frequency(pcm.hz); /* 44100 22050 11025 */ + + rb->mixer_set_frequency(pcm.hz); /* 44100 22050 11025 */ } void rockboy_pcm_close(void) { - memset(&pcm, 0, sizeof pcm); - newly_started = true; - rb->pcm_play_stop(); - rb->pcm_set_frequency(HW_SAMPR_DEFAULT); + memset(&pcm, 0, sizeof pcm); + newly_started = true; + rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); + rb->mixer_set_frequency(HW_SAMPR_DEFAULT); } int rockboy_pcm_submit(void) @@ -74,7 +73,7 @@ int rockboy_pcm_submit(void) if(newly_started) { - rb->pcm_play_data(&get_more, NULL, NULL,0); + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &get_more, NULL, 0); newly_started = false; } diff --git a/apps/plugins/sdl/src/audio/rockbox/SDL_rockboxaudio.c b/apps/plugins/sdl/src/audio/rockbox/SDL_rockboxaudio.c index ac268b4a19..7317ae0383 100644 --- a/apps/plugins/sdl/src/audio/rockbox/SDL_rockboxaudio.c +++ b/apps/plugins/sdl/src/audio/rockbox/SDL_rockboxaudio.c @@ -215,7 +215,7 @@ static Uint8 *ROCKBOXAUD_GetAudioBuf(_THIS) static void ROCKBOXAUD_CloseAudio(_THIS) { - rb->pcm_play_stop(); + rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); if ( this->hidden->mixbuf != NULL ) { SDL_FreeAudioMem(this->hidden->mixbuf); this->hidden->mixbuf = NULL; @@ -226,7 +226,7 @@ static void ROCKBOXAUD_CloseAudio(_THIS) if(this->hidden->rb_buf[i]) SDL_FreeAudioMem(this->hidden->rb_buf[i]); } - rb->pcm_set_frequency(HW_SAMPR_DEFAULT); + rb->mixer_set_frequency(HW_SAMPR_DEFAULT); } static bool freq_ok(unsigned int freq) @@ -257,7 +257,7 @@ static int ROCKBOXAUD_OpenAudio(_THIS, SDL_AudioSpec *spec) SDL_CalculateAudioSpec(spec); LOGF("samplerate %d", spec->freq); - rb->pcm_set_frequency(spec->freq); + rb->mixer_set_frequency(spec->freq); /* Allocate mixing buffer */ this->hidden->mixlen = spec->size; @@ -286,7 +286,7 @@ static int ROCKBOXAUD_OpenAudio(_THIS, SDL_AudioSpec *spec) rbaud_underruns = 0; - rb->pcm_play_data(get_more, NULL, NULL, 0); + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); /* We're ready to rock and roll. :-) */ return(0); diff --git a/apps/plugins/test_sampr.c b/apps/plugins/test_sampr.c index 64754efc19..10571a2d98 100644 --- a/apps/plugins/test_sampr.c +++ b/apps/plugins/test_sampr.c @@ -167,7 +167,7 @@ static void set_frequency(int index) output_clear(); update_gen_step(); - rb->pcm_set_frequency(hw_sampr); + rb->mixer_set_frequency(hw_sampr); rb->pcm_apply_settings(); } @@ -220,7 +220,7 @@ static void play_tone(bool volume_set) rb->cpu_boost(true); #endif - rb->pcm_set_frequency(rb->hw_freq_sampr[freq]); + rb->mixer_set_frequency(rb->hw_freq_sampr[freq]); #if INPUT_SRC_CAPS != 0 /* Recordable targets can play back from other sources */ @@ -237,7 +237,7 @@ static void play_tone(bool volume_set) IF_PRIO(, PRIORITY_PLAYBACK) IF_COP(, CPU)); - rb->pcm_play_data(get_more, NULL, NULL, 0); + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); #ifndef HAVE_VOLUME_IN_LIST if (volume_set) @@ -260,7 +260,7 @@ static void play_tone(bool volume_set) rb->thread_wait(gen_thread_id); - rb->pcm_play_stop(); + rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); #ifdef HAVE_ADJUSTABLE_CPU_FREQ rb->cpu_boost(false); @@ -268,7 +268,7 @@ static void play_tone(bool volume_set) /* restore default - user of apis is responsible for restoring default state - normally playback at 44100Hz */ - rb->pcm_set_frequency(HW_FREQ_DEFAULT); + rb->mixer_set_frequency(HW_FREQ_DEFAULT); } /* Tests hardware sample rate switching */ diff --git a/apps/plugins/xrick/system/syssnd_rockbox.c b/apps/plugins/xrick/system/syssnd_rockbox.c index 97ed5474f1..dd522cd6f7 100644 --- a/apps/plugins/xrick/system/syssnd_rockbox.c +++ b/apps/plugins/xrick/system/syssnd_rockbox.c @@ -222,7 +222,7 @@ void syssnd_update(void) if (!isAudioPlaying && fillCount > 0) { - rb->pcm_play_data(&get_more, NULL, NULL, 0); + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); isAudioPlaying = true; } } @@ -240,6 +240,7 @@ bool syssnd_init(void) IFDEBUG_AUDIO(sys_printf("xrick/audio: start\n");); + rb->audio_stop(); rb->talk_disable(true); /* Stop playback to reconfigure audio settings and acquire audio buffer */ @@ -251,7 +252,7 @@ bool syssnd_init(void) rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); #endif - rb->pcm_set_frequency(HW_FREQ_44); + rb->mixer_set_frequency(HW_FREQ_44); rb->pcm_apply_settings(); rb->memset(channels, 0, sizeof(channels)); @@ -278,13 +279,13 @@ void syssnd_shutdown(void) } /* Stop playback. */ - rb->pcm_play_stop(); + rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); /* Reset playing status. */ isAudioPlaying = false; /* Restore default sampling rate. */ - rb->pcm_set_frequency(HW_SAMPR_DEFAULT); + rb->mixer_set_frequency(HW_SAMPR_DEFAULT); rb->pcm_apply_settings(); rb->talk_disable(false); @@ -361,9 +362,7 @@ void syssnd_pauseAll(bool pause) return; } - rb->pcm_play_lock(); rb->mixer_channel_play_pause(PCM_MIXER_CHAN_PLAYBACK, !pause); - rb->pcm_play_unlock(); } /* diff --git a/apps/plugins/xworld/sys.c b/apps/plugins/xworld/sys.c index b2e274388c..50c0c64e0b 100644 --- a/apps/plugins/xworld/sys.c +++ b/apps/plugins/xworld/sys.c @@ -1029,13 +1029,13 @@ void sys_startAudio(struct System* sys, AudioCallback callback, void *param) audio_param = param; audio_sys = sys; - rb->pcm_play_data(get_more, NULL, NULL, 0); + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); } void sys_stopAudio(struct System* sys) { (void) sys; - rb->pcm_play_stop(); + rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); } uint32_t sys_getOutputSampleRate(struct System* sys) diff --git a/apps/plugins/zxbox/spmain.c b/apps/plugins/zxbox/spmain.c index e106165eb0..6b789a84ef 100644 --- a/apps/plugins/zxbox/spmain.c +++ b/apps/plugins/zxbox/spmain.c @@ -290,9 +290,7 @@ static void options_menu(void){ no_yes, 2, NULL); if (new_setting != settings.sound ) settings.sound=new_setting; -#if !defined SIMULATOR - rb->pcm_play_stop(); -#endif + rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); break; case 5: new_setting = 9 - settings.volume; @@ -318,9 +316,6 @@ static void options_menu(void){ /* menu */ static bool zxbox_menu(void) { -#if !defined SIMULATOR - rb->pcm_play_stop(); -#endif int selected=0; int result; int menu_quit=0; @@ -332,6 +327,7 @@ static bool zxbox_menu(void) "Save Snapshot", "Toggle \"fast\" mode", "Options", "Quit"); + rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); rb->button_clear_queue(); while (!menu_quit) { @@ -524,7 +520,3 @@ void start_spectemu(const void *parameter) run_singlemode(); } - - - - diff --git a/apps/plugins/zxbox/spsound.c b/apps/plugins/zxbox/spsound.c index 9d3eefa87f..602030361f 100644 --- a/apps/plugins/zxbox/spsound.c +++ b/apps/plugins/zxbox/spsound.c @@ -5,7 +5,7 @@ * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. See the file COPYING. + * (at your option) any later version. See the file COPYING. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -67,71 +67,65 @@ unsigned short my_buf[TMNUM*2*3*2]; const byte lin8_ulaw[] = { - 31, 31, 31, 32, 32, 32, 32, 33, - 33, 33, 33, 34, 34, 34, 34, 35, - 35, 35, 35, 36, 36, 36, 36, 37, - 37, 37, 37, 38, 38, 38, 38, 39, - 39, 39, 39, 40, 40, 40, 40, 41, - 41, 41, 41, 42, 42, 42, 42, 43, - 43, 43, 43, 44, 44, 44, 44, 45, - 45, 45, 45, 46, 46, 46, 46, 47, - 47, 47, 47, 48, 48, 49, 49, 50, - 50, 51, 51, 52, 52, 53, 53, 54, - 54, 55, 55, 56, 56, 57, 57, 58, - 58, 59, 59, 60, 60, 61, 61, 62, - 62, 63, 63, 64, 65, 66, 67, 68, - 69, 70, 71, 72, 73, 74, 75, 76, - 77, 78, 79, 81, 83, 85, 87, 89, - 91, 93, 95, 99, 103, 107, 111, 119, - 255, 247, 239, 235, 231, 227, 223, 221, - 219, 217, 215, 213, 211, 209, 207, 206, - 205, 204, 203, 202, 201, 200, 199, 198, - 197, 196, 195, 194, 193, 192, 191, 191, - 190, 190, 189, 189, 188, 188, 187, 187, - 186, 186, 185, 185, 184, 184, 183, 183, - 182, 182, 181, 181, 180, 180, 179, 179, - 178, 178, 177, 177, 176, 176, 175, 175, - 175, 175, 174, 174, 174, 174, 173, 173, - 173, 173, 172, 172, 172, 172, 171, 171, - 171, 171, 170, 170, 170, 170, 169, 169, - 169, 169, 168, 168, 168, 168, 167, 167, - 167, 167, 166, 166, 166, 166, 165, 165, - 165, 165, 164, 164, 164, 164, 163, 163, - 163, 163, 162, 162, 162, 162, 161, 161, - 161, 161, 160, 160, 160, 160, 159, 159, + 31, 31, 31, 32, 32, 32, 32, 33, + 33, 33, 33, 34, 34, 34, 34, 35, + 35, 35, 35, 36, 36, 36, 36, 37, + 37, 37, 37, 38, 38, 38, 38, 39, + 39, 39, 39, 40, 40, 40, 40, 41, + 41, 41, 41, 42, 42, 42, 42, 43, + 43, 43, 43, 44, 44, 44, 44, 45, + 45, 45, 45, 46, 46, 46, 46, 47, + 47, 47, 47, 48, 48, 49, 49, 50, + 50, 51, 51, 52, 52, 53, 53, 54, + 54, 55, 55, 56, 56, 57, 57, 58, + 58, 59, 59, 60, 60, 61, 61, 62, + 62, 63, 63, 64, 65, 66, 67, 68, + 69, 70, 71, 72, 73, 74, 75, 76, + 77, 78, 79, 81, 83, 85, 87, 89, + 91, 93, 95, 99, 103, 107, 111, 119, + 255, 247, 239, 235, 231, 227, 223, 221, + 219, 217, 215, 213, 211, 209, 207, 206, + 205, 204, 203, 202, 201, 200, 199, 198, + 197, 196, 195, 194, 193, 192, 191, 191, + 190, 190, 189, 189, 188, 188, 187, 187, + 186, 186, 185, 185, 184, 184, 183, 183, + 182, 182, 181, 181, 180, 180, 179, 179, + 178, 178, 177, 177, 176, 176, 175, 175, + 175, 175, 174, 174, 174, 174, 173, 173, + 173, 173, 172, 172, 172, 172, 171, 171, + 171, 171, 170, 170, 170, 170, 169, 169, + 169, 169, 168, 168, 168, 168, 167, 167, + 167, 167, 166, 166, 166, 166, 165, 165, + 165, 165, 164, 164, 164, 164, 163, 163, + 163, 163, 162, 162, 162, 162, 161, 161, + 161, 161, 160, 160, 160, 160, 159, 159, }; static void open_snd(void) { sndstate = SPS_OPENED; sound_avail=1; - rb->pcm_play_stop(); + rb->audio_stop(); #if INPUT_SRC_CAPS != 0 /* Select playback */ rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); #endif - rb->pcm_set_frequency(SAMPR_44); + rb->mixer_set_frequency(SAMPR_44); } static void close_snd(int normal) { (void)normal; sound_avail = 0; - rb->pcm_play_stop(); - rb->pcm_set_frequency(HW_SAMPR_DEFAULT); + rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); } - - void init_spect_sound(void) { -#if 1 /* TODO: Is this OK? */ open_snd(); -#endif } - #ifndef VOLREDUCE #define VOLREDUCE 0 #endif @@ -149,7 +143,7 @@ void init_spect_sound(void) static void process_sound(void) { - static int soundhp; + static int soundhp; int i; byte *sb; register int sv; @@ -169,7 +163,7 @@ static void process_sound(void) } else { signed char *tsp; - + tsp = sp_tape_sound; for(i = TMNUM; i; sb++,tsp++,i--) { sv = *sb + TAPESOUND(tsp); @@ -218,7 +212,7 @@ static void write_buf(void){ = my_buf[j+10] = my_buf[j+11] \ = (((byte)sp_sound_buf[i])<<8) >> settings.volume; - rb->pcm_play_data(&get_more,NULL,(unsigned char*)(my_buf),TMNUM*4*3*2); + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, (unsigned char*)(my_buf),TMNUM*4*3*2); #if 0 /* can use to save and later analyze what we produce */ @@ -232,10 +226,9 @@ static void write_buf(void){ rb->close (i); #endif - while(!doneplay) rb->yield(); - + } void play_sound(int evenframe) { @@ -249,7 +242,7 @@ void play_sound(int evenframe) close_snd(1); return; } - + z80_proc.sound_change = 0; process_sound(); @@ -260,7 +253,7 @@ void play_sound(int evenframe) void setbufsize(void) { - + } @@ -286,5 +279,3 @@ void autoclose_sound(void) } #endif /* NO_SOUND */ - - diff --git a/apps/plugins/zxbox/zxbox.c b/apps/plugins/zxbox/zxbox.c index c0a939e703..0291c22ce5 100644 --- a/apps/plugins/zxbox/zxbox.c +++ b/apps/plugins/zxbox/zxbox.c @@ -103,13 +103,12 @@ enum plugin_status plugin_start(const void* parameter) #endif #ifdef USE_GREY -grey_show(false); -grey_release(); + grey_show(false); + grey_release(); #endif -#if !defined SIMULATOR - rb->pcm_play_stop(); -#endif + rb->audio_stop(); + rb->mixer_set_frequency(HW_SAMPR_DEFAULT); return PLUGIN_OK; } @@ -267,4 +266,3 @@ void press_key(int c){ spkb_kbstate[ki].state = 1; process_keys(); } - diff --git a/docs/PLUGIN_API b/docs/PLUGIN_API index 337a2c6752..af999d317b 100644 --- a/docs/PLUGIN_API +++ b/docs/PLUGIN_API @@ -163,7 +163,7 @@ int audio_status(void) void audio_stop(void) \group playback control - \description + \description Gracefully shuts down the playback (ie codec) engine. Anything else playing back (talk/voice, other mixer channels) is unaffected. void backlight_off(void) \group For OLED targets like the Sansa Clip, the backlight_* functions control * the display enable, which has essentially the same effect. @@ -1775,27 +1775,10 @@ void pcm_init_recording(void) \conditions (defined(HAVE_RECORDING)) \description -bool pcm_is_playing(void) - \group sound - \return true unless playback is paused - \description - -void pcm_play_data(pcm_play_callback_type get_more, pcm_status_callback_type status_cb, const void *start, size_t size) - \group sound - \param get_more Optional callback - \param status_cb Optional status callback - \param start is the address of raw 16-16, interleaved PCM data - \param size is the size of the data to play - \description - void pcm_play_lock(void) \group sound \description -void pcm_play_stop(void) - \group sound - \description Stops the playback and empties the audio buffer. - void pcm_play_unlock(void) \group sound \description @@ -1809,11 +1792,6 @@ void pcm_record_data(pcm_rec_callback_type more_ready, pcm_status_callback_type \param size \description -void pcm_set_frequency(unsigned int frequency) - \group sound - \param frequency - \description - void pcm_stop_recording(void) \group sound \conditions (defined(HAVE_RECORDING)) diff --git a/firmware/pcm_mixer.c b/firmware/pcm_mixer.c index 192132b841..ca48e3ba10 100644 --- a/firmware/pcm_mixer.c +++ b/firmware/pcm_mixer.c @@ -455,6 +455,10 @@ void mixer_set_frequency(unsigned int samplerate) pcm_set_frequency(samplerate); samplerate = pcm_get_frequency(); +#ifdef CONFIG_SAMPR_TYPES + samplerate &= ~SAMPR_TYPE_MASK; +#endif + if (samplerate == mixer_sampr) return;