From 286a4c5caa1945c8d1cb365a3d90fb09d5700cb2 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Thu, 23 Feb 2012 08:14:46 -0500 Subject: Revise the PCM callback system after adding multichannel audio. Additional status callback is added to pcm_play/rec_data instead of using a special function to set it. Status includes DMA error reporting to the status callback. Playback and recording callback become more alike except playback uses "const void **addr" (because the data should not be altered) and recording uses "void **addr". "const" is put in place throughout where appropriate. Most changes are fairly trivial. One that should be checked in particular because it isn't so much is telechips, if anyone cares to bother. PP5002 is not so trivial either but that tested as working. Change-Id: I4928d69b3b3be7fb93e259f81635232df9bd1df2 Reviewed-on: http://gerrit.rockbox.org/166 Reviewed-by: Michael Sevakis Tested-by: Michael Sevakis --- apps/plugins/beatbox/beatbox.c | 8 ++++---- apps/plugins/doom/i_sound.c | 6 +++--- apps/plugins/fft/fft.c | 4 ++-- apps/plugins/metronome.c | 2 +- apps/plugins/midi/midiplay.c | 14 +++++++------- apps/plugins/mikmod/mikmod.c | 10 +++++----- apps/plugins/mpegplayer/pcm_output.c | 2 +- apps/plugins/pacbox/pacbox.c | 6 +++--- apps/plugins/pdbox/PDa/src/s_audio_rockbox.c | 10 ++++------ apps/plugins/pitch_detector.c | 7 +++---- apps/plugins/rockboy/rbsound.c | 6 +++--- apps/plugins/test_sampr.c | 6 +++--- apps/plugins/zxbox/spsound.c | 9 ++++----- 13 files changed, 43 insertions(+), 47 deletions(-) (limited to 'apps/plugins') diff --git a/apps/plugins/beatbox/beatbox.c b/apps/plugins/beatbox/beatbox.c index 8ecbabd1e5..8c7413cc99 100644 --- a/apps/plugins/beatbox/beatbox.c +++ b/apps/plugins/beatbox/beatbox.c @@ -509,7 +509,7 @@ void redrawScreen(unsigned char force) rb->lcd_update(); } -void get_more(unsigned char** start, size_t* size) +void get_more(const void** start, size_t* size) { #ifndef SYNC if(lastswap!=swap) @@ -523,10 +523,10 @@ void get_more(unsigned char** start, size_t* size) *size = BUF_SIZE*sizeof(short); #ifndef SYNC - *start = (unsigned char*)((swap ? gmbuf : gmbuf + BUF_SIZE)); + *start = swap ? gmbuf : gmbuf + BUF_SIZE; swap=!swap; #else - *start = (unsigned char*)(gmbuf); + *start = gmbuf; #endif } @@ -537,7 +537,7 @@ int beatboxmain() numberOfSamples=44100/10; synthbuf(); - rb->pcm_play_data(&get_more, NULL, 0); + rb->pcm_play_data(&get_more, NULL, NULL, 0); rb->lcd_set_background(0x000000); rb->lcd_clear_display(); diff --git a/apps/plugins/doom/i_sound.c b/apps/plugins/doom/i_sound.c index 2d7b592818..bdf70c1215 100644 --- a/apps/plugins/doom/i_sound.c +++ b/apps/plugins/doom/i_sound.c @@ -457,11 +457,11 @@ void I_UpdateSound( void ) // only output be done asynchronous? // -void get_more(unsigned char** start, size_t* size) +void get_more(const void** start, size_t* size) { I_UpdateSound(); // Force sound update - *start = (unsigned char*)(mixbuffer); + *start = mixbuffer; *size = SAMPLECOUNT*2*sizeof(short); } @@ -471,7 +471,7 @@ void I_SubmitSound(void) if (!enable_sound) return; - rb->pcm_play_data(&get_more, NULL, 0); + rb->pcm_play_data(&get_more, NULL, NULL, 0); } void I_ShutdownSound(void) diff --git a/apps/plugins/fft/fft.c b/apps/plugins/fft/fft.c index 1c4e1b4c20..f7d8943576 100644 --- a/apps/plugins/fft/fft.c +++ b/apps/plugins/fft/fft.c @@ -1186,8 +1186,8 @@ static inline bool fft_init_fft_lib(void) static inline bool fft_get_fft(void) { int count; - int16_t *value = - (int16_t *) rb->mixer_channel_get_buffer(PCM_MIXER_CHAN_PLAYBACK, &count); + const int16_t *value = + rb->mixer_channel_get_buffer(PCM_MIXER_CHAN_PLAYBACK, &count); /* This block can introduce discontinuities in our data. Meaning, the * FFT will not be done a continuous segment of the signal. Which can * be bad. Or not. diff --git a/apps/plugins/metronome.c b/apps/plugins/metronome.c index da035a7688..297405571f 100644 --- a/apps/plugins/metronome.c +++ b/apps/plugins/metronome.c @@ -721,7 +721,7 @@ static void prepare_tock(void) static void play_tock(void) { - rb->pcm_play_data(NULL,(unsigned char *)sndbuf,sizeof(sndbuf)); + rb->pcm_play_data(NULL, NULL, sndbuf, sizeof(sndbuf)); } #endif /* CONFIG_CODEC != SWCODEC */ diff --git a/apps/plugins/midi/midiplay.c b/apps/plugins/midi/midiplay.c index 40b4f1c83c..1412d4c742 100644 --- a/apps/plugins/midi/midiplay.c +++ b/apps/plugins/midi/midiplay.c @@ -319,7 +319,7 @@ static inline void synthbuf(void) samples_in_buf = BUF_SIZE-i; } -static void get_more(unsigned char** start, size_t* size) +static void get_more(const void** start, size_t* size) { #ifndef SYNC if(lastswap != swap) @@ -333,10 +333,10 @@ static void get_more(unsigned char** start, size_t* size) *size = samples_in_buf*sizeof(int32_t); #ifndef SYNC - *start = (unsigned char*)((swap ? gmbuf : gmbuf + BUF_SIZE)); + *start = swap ? gmbuf : gmbuf + BUF_SIZE; swap = !swap; #else - *start = (unsigned char*)(gmbuf); + *start = gmbuf; #endif } @@ -396,7 +396,7 @@ static int midimain(const void * filename) samples_this_second = 0; synthbuf(); - rb->pcm_play_data(&get_more, NULL, 0); + rb->pcm_play_data(&get_more, NULL, NULL, 0); while (!quit) { @@ -445,7 +445,7 @@ static int midimain(const void * filename) seekBackward(5); midi_debug("Rewind to %d:%02d\n", playing_time/60, playing_time%60); if (is_playing) - rb->pcm_play_data(&get_more, NULL, 0); + rb->pcm_play_data(&get_more, NULL, NULL, 0); break; } @@ -455,7 +455,7 @@ static int midimain(const void * filename) seekForward(5); midi_debug("Skip to %d:%02d\n", playing_time/60, playing_time%60); if (is_playing) - rb->pcm_play_data(&get_more, NULL, 0); + rb->pcm_play_data(&get_more, NULL, NULL, 0); break; } @@ -470,7 +470,7 @@ static int midimain(const void * filename) { midi_debug("Playing from %d:%02d\n", playing_time/60, playing_time%60); is_playing = true; - rb->pcm_play_data(&get_more, NULL, 0); + rb->pcm_play_data(&get_more, NULL, NULL, 0); } break; } diff --git a/apps/plugins/mikmod/mikmod.c b/apps/plugins/mikmod/mikmod.c index a7eeb5019f..eb3be13140 100644 --- a/apps/plugins/mikmod/mikmod.c +++ b/apps/plugins/mikmod/mikmod.c @@ -268,7 +268,7 @@ static inline void synthbuf(void) VC_WriteBytes(outptr, BUF_SIZE); } -void get_more(unsigned char** start, size_t* size) +void get_more(const void** start, size_t* size) { #ifndef SYNC if (lastswap != swap) @@ -282,10 +282,10 @@ void get_more(unsigned char** start, size_t* size) *size = BUF_SIZE; #ifndef SYNC - *start = (unsigned char*)((swap ? gmbuf : gmbuf + BUF_SIZE)); + *start = swap ? gmbuf : gmbuf + BUF_SIZE; swap = !swap; #else - *start = (unsigned char*)(gmbuf); + *start = gmbuf; #endif } @@ -660,7 +660,7 @@ int playfile(char* filename) { display = DISPLAY_INFO; Player_Start(module); - rb->pcm_play_data(&get_more, NULL, 0); + rb->pcm_play_data(&get_more, NULL, NULL, 0); } #ifdef HAVE_ADJUSTABLE_CPU_FREQ @@ -804,7 +804,7 @@ int playfile(char* filename) } else { - rb->pcm_play_data(&get_more, NULL, 0); + rb->pcm_play_data(&get_more, NULL, NULL, 0); } Player_TogglePause(); break; diff --git a/apps/plugins/mpegplayer/pcm_output.c b/apps/plugins/mpegplayer/pcm_output.c index 8db9531049..8694ae4a69 100644 --- a/apps/plugins/mpegplayer/pcm_output.c +++ b/apps/plugins/mpegplayer/pcm_output.c @@ -85,7 +85,7 @@ static inline ssize_t pcm_output_bytes_free(void) } /* Audio DMA handler */ -static void get_more(unsigned char **start, size_t *size) +static void get_more(const void **start, size_t *size) { ssize_t sz; diff --git a/apps/plugins/pacbox/pacbox.c b/apps/plugins/pacbox/pacbox.c index 5165ff3047..efba47b576 100644 --- a/apps/plugins/pacbox/pacbox.c +++ b/apps/plugins/pacbox/pacbox.c @@ -286,7 +286,7 @@ static int16_t raw_buf[NBSAMPLES] IBSS_ATTR; /* Audio callback */ -static void get_more(unsigned char **start, size_t *size) +static void get_more(const void **start, size_t *size) { int32_t *out, *outend; int16_t *raw; @@ -306,7 +306,7 @@ static void get_more(unsigned char **start, size_t *size) } while (out < outend); - *start = (unsigned char *)sound_buf; + *start = sound_buf; *size = NBSAMPLES*sizeof(sound_buf[0]); } @@ -339,7 +339,7 @@ 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, 0); + rb->pcm_play_data(get_more, NULL, NULL, 0); sound_playing = true; } diff --git a/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c b/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c index 76a50fa075..6571f74edf 100644 --- a/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c +++ b/apps/plugins/pdbox/PDa/src/s_audio_rockbox.c @@ -26,7 +26,7 @@ #include "s_stuff.h" /* Declare functions that go to IRAM. */ -void pdbox_get_more(unsigned char** start, size_t* size) ICODE_ATTR; +void pdbox_get_more(const void** start, size_t* size) ICODE_ATTR; int rockbox_send_dacs(void) ICODE_ATTR; /* Extern variables. */ @@ -90,12 +90,12 @@ void rockbox_close_audio(void) } /* Rockbox audio callback. */ -void pdbox_get_more(unsigned char** start, size_t* size) +void pdbox_get_more(const void** start, size_t* size) { if(outbuf_fill > 0) { /* Store output data address and size. */ - *start = (unsigned char*) outbuf[outbuf_tail].data; + *start = outbuf[outbuf_tail].data; *size = sizeof(outbuf[outbuf_tail].data); /* Free this part of output buffer. */ @@ -116,8 +116,6 @@ void pdbox_get_more(unsigned char** start, size_t* size) playing = false; /* Nothing to play. */ - *start = NULL; - *size = 0; } } @@ -185,7 +183,7 @@ int rockbox_send_dacs(void) if(!playing && outbuf_fill > 0) { /* Start playing. */ - rb->pcm_play_data(pdbox_get_more, NULL, 0); + rb->pcm_play_data(pdbox_get_more, NULL, NULL, 0); /* Set status flag. */ playing = true; diff --git a/apps/plugins/pitch_detector.c b/apps/plugins/pitch_detector.c index c30d48a025..4ae43b3236 100644 --- a/apps/plugins/pitch_detector.c +++ b/apps/plugins/pitch_detector.c @@ -952,7 +952,7 @@ static uint32_t ICODE_ATTR buffer_magnitude(int16_t *input) } /* Stop the recording when the buffer is full */ -static void recording_callback(int status, void **start, size_t *size) +static void recording_callback(void **start, size_t *size) { int tail = audio_tail ^ 1; @@ -963,8 +963,6 @@ static void recording_callback(int status, void **start, size_t *size) /* Always record full buffer, even if not required */ *start = audio_data[tail]; *size = BUFFER_SIZE * sizeof (int16_t); - - (void)status; } #endif /* SIMULATOR */ @@ -973,7 +971,8 @@ static void record_data(void) { #ifndef SIMULATOR /* Always record full buffer, even if not required */ - rb->pcm_record_data(recording_callback, audio_data[audio_tail], + rb->pcm_record_data(recording_callback, NULL, + audio_data[audio_tail], BUFFER_SIZE * sizeof (int16_t)); #endif } diff --git a/apps/plugins/rockboy/rbsound.c b/apps/plugins/rockboy/rbsound.c index c0d0277915..628879b4b7 100644 --- a/apps/plugins/rockboy/rbsound.c +++ b/apps/plugins/rockboy/rbsound.c @@ -16,10 +16,10 @@ static unsigned short *buf=0, *hwbuf=0; static bool newly_started; -static void get_more(unsigned char** start, size_t* size) +static void get_more(const void** start, size_t* size) { memcpy(hwbuf, &buf[pcm.len*doneplay], BUF_SIZE*sizeof(short)); - *start = (unsigned char*)(hwbuf); + *start = hwbuf; *size = BUF_SIZE*sizeof(short); doneplay=1; } @@ -76,7 +76,7 @@ int rockboy_pcm_submit(void) if(newly_started) { - rb->pcm_play_data(&get_more,NULL,0); + rb->pcm_play_data(&get_more, NULL, NULL,0); newly_started = false; } diff --git a/apps/plugins/test_sampr.c b/apps/plugins/test_sampr.c index db8301bba6..fc2f695c70 100644 --- a/apps/plugins/test_sampr.c +++ b/apps/plugins/test_sampr.c @@ -90,13 +90,13 @@ static int16_t ICODE_ATTR fsin(uint32_t phase) } /* ISR handler to get next block of data */ -static void get_more(unsigned char **start, size_t *size) +static void get_more(const void **start, size_t *size) { /* Free previous buffer */ output_head += output_step; output_step = 0; - *start = (unsigned char *)output_buf[output_head & OUTPUT_CHUNK_MASK]; + *start = output_buf[output_head & OUTPUT_CHUNK_MASK]; *size = OUTPUT_CHUNK_SIZE; /* Keep repeating previous if source runs low */ @@ -236,7 +236,7 @@ static void play_tone(bool volume_set) IF_PRIO(, PRIORITY_PLAYBACK) IF_COP(, CPU)); - rb->pcm_play_data(get_more, NULL, 0); + rb->pcm_play_data(get_more, NULL, NULL, 0); #ifndef HAVE_VOLUME_IN_LIST if (volume_set) diff --git a/apps/plugins/zxbox/spsound.c b/apps/plugins/zxbox/spsound.c index 8b3aa3d84f..9d3eefa87f 100644 --- a/apps/plugins/zxbox/spsound.c +++ b/apps/plugins/zxbox/spsound.c @@ -189,12 +189,11 @@ void autoclose_sound(void) } #endif } -static void get_more(unsigned char** start, size_t* size) +static void get_more(const void** start, size_t* size) { doneplay = 1; - rb->pcm_play_stop(); - (void)*start; - (void)*size; + (void)start; + (void)size; } /* sp_sound_buf is Unsigned 8 bit, Rate 8000 Hz, Mono */ @@ -219,7 +218,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,(unsigned char*)(my_buf),TMNUM*4*3*2); + rb->pcm_play_data(&get_more,NULL,(unsigned char*)(my_buf),TMNUM*4*3*2); #if 0 /* can use to save and later analyze what we produce */ -- cgit v1.2.3