diff options
author | Steve Bavin <pondlife@pondlife.me> | 2008-04-03 14:24:37 +0000 |
---|---|---|
committer | Steve Bavin <pondlife@pondlife.me> | 2008-04-03 14:24:37 +0000 |
commit | b24ed65fafd98b272e883f5c222dbb2c21a66c0c (patch) | |
tree | 156a219a8db4bff4cc419c165bf7d784bd1b77cf /apps | |
parent | 0ab1a3b801153cc349d31a97831c68aab301587e (diff) | |
download | rockbox-b24ed65fafd98b272e883f5c222dbb2c21a66c0c.tar.gz rockbox-b24ed65fafd98b272e883f5c222dbb2c21a66c0c.zip |
Simplify pcmbuf_beep() a little, should be no functional change but it seems to mysteriously change the PortalPlayer 'keyclick beep of death' problem into a 'barely-there keyclick' problem.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16947 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/pcmbuf.c | 109 |
1 files changed, 49 insertions, 60 deletions
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c index 99a440ad6b..eb2c135064 100644 --- a/apps/pcmbuf.c +++ b/apps/pcmbuf.c | |||
@@ -351,7 +351,7 @@ bool pcmbuf_crossfade_init(bool manual_skip) | |||
351 | } | 351 | } |
352 | 352 | ||
353 | trigger_cpu_boost(); | 353 | trigger_cpu_boost(); |
354 | 354 | ||
355 | /* Not enough data, or crossfade disabled, flush the old data instead */ | 355 | /* Not enough data, or crossfade disabled, flush the old data instead */ |
356 | if (LOW_DATA(2) || !pcmbuf_is_crossfade_enabled() || low_latency_mode) | 356 | if (LOW_DATA(2) || !pcmbuf_is_crossfade_enabled() || low_latency_mode) |
357 | { | 357 | { |
@@ -365,7 +365,7 @@ bool pcmbuf_crossfade_init(bool manual_skip) | |||
365 | crossfade_mixmode = false; | 365 | crossfade_mixmode = false; |
366 | else | 366 | else |
367 | crossfade_mixmode = global_settings.crossfade_fade_out_mixmode; | 367 | crossfade_mixmode = global_settings.crossfade_fade_out_mixmode; |
368 | 368 | ||
369 | crossfade_init = true; | 369 | crossfade_init = true; |
370 | 370 | ||
371 | return true; | 371 | return true; |
@@ -569,7 +569,7 @@ static void crossfade_process_buffer(size_t fade_in_delay, | |||
569 | } | 569 | } |
570 | /* The start sample within the chunk */ | 570 | /* The start sample within the chunk */ |
571 | fade_out_sample = fade_out_delay / 2; | 571 | fade_out_sample = fade_out_delay / 2; |
572 | 572 | ||
573 | while (fade_out_rem > 0) | 573 | while (fade_out_rem > 0) |
574 | { | 574 | { |
575 | /* Each 1/10 second of audio will have the same fade applied */ | 575 | /* Each 1/10 second of audio will have the same fade applied */ |
@@ -695,11 +695,11 @@ static size_t crossfade_fade_mix(int factor, const char *buf, size_t fade_rem) | |||
695 | sample = *input_buf++; | 695 | sample = *input_buf++; |
696 | sample = ((sample * factor) >> 8) + *output_buf; | 696 | sample = ((sample * factor) >> 8) + *output_buf; |
697 | *output_buf++ = clip_sample_16(sample); | 697 | *output_buf++ = clip_sample_16(sample); |
698 | 698 | ||
699 | sample = *input_buf++; | 699 | sample = *input_buf++; |
700 | sample = ((sample * factor) >> 8) + *output_buf; | 700 | sample = ((sample * factor) >> 8) + *output_buf; |
701 | *output_buf++ = clip_sample_16(sample); | 701 | *output_buf++ = clip_sample_16(sample); |
702 | 702 | ||
703 | fade_rem -= 4; /* 2 samples, each 16 bit -> 4 bytes */ | 703 | fade_rem -= 4; /* 2 samples, each 16 bit -> 4 bytes */ |
704 | 704 | ||
705 | if (output_buf >= chunk_end) | 705 | if (output_buf >= chunk_end) |
@@ -729,10 +729,10 @@ static size_t crossfade_mix(const char *buf, size_t length) | |||
729 | /* fade left and right channel at once to keep buffer alignment */ | 729 | /* fade left and right channel at once to keep buffer alignment */ |
730 | sample = *input_buf++ + *output_buf; | 730 | sample = *input_buf++ + *output_buf; |
731 | *output_buf++ = clip_sample_16(sample); | 731 | *output_buf++ = clip_sample_16(sample); |
732 | 732 | ||
733 | sample = *input_buf++ + *output_buf; | 733 | sample = *input_buf++ + *output_buf; |
734 | *output_buf++ = clip_sample_16(sample); | 734 | *output_buf++ = clip_sample_16(sample); |
735 | 735 | ||
736 | length -= 4; /* 2 samples, each 16 bit -> 4 bytes */ | 736 | length -= 4; /* 2 samples, each 16 bit -> 4 bytes */ |
737 | 737 | ||
738 | if (output_buf >= chunk_end) | 738 | if (output_buf >= chunk_end) |
@@ -846,7 +846,7 @@ static bool prepare_insert(size_t length) | |||
846 | if (!pcm_is_playing()) | 846 | if (!pcm_is_playing()) |
847 | { | 847 | { |
848 | trigger_cpu_boost(); | 848 | trigger_cpu_boost(); |
849 | 849 | ||
850 | /* Pre-buffer 1s. */ | 850 | /* Pre-buffer 1s. */ |
851 | #if MEM <= 1 | 851 | #if MEM <= 1 |
852 | if (!LOW_DATA(1)) | 852 | if (!LOW_DATA(1)) |
@@ -858,7 +858,7 @@ static bool prepare_insert(size_t length) | |||
858 | if (!(audio_status() & AUDIO_STATUS_PAUSE)) | 858 | if (!(audio_status() & AUDIO_STATUS_PAUSE)) |
859 | pcmbuf_play_start(); | 859 | pcmbuf_play_start(); |
860 | } | 860 | } |
861 | } | 861 | } |
862 | else if (pcmbuf_unplayed_bytes <= pcmbuf_watermark) | 862 | else if (pcmbuf_unplayed_bytes <= pcmbuf_watermark) |
863 | pcmbuf_under_watermark(); | 863 | pcmbuf_under_watermark(); |
864 | 864 | ||
@@ -975,70 +975,59 @@ bool pcmbuf_insert_buffer(char *buf, int count) | |||
975 | in Hertz for a duration in milliseconds. */ | 975 | in Hertz for a duration in milliseconds. */ |
976 | void pcmbuf_beep(unsigned int frequency, size_t duration, int amplitude) | 976 | void pcmbuf_beep(unsigned int frequency, size_t duration, int amplitude) |
977 | { | 977 | { |
978 | unsigned int count = 0, i = 0; | 978 | unsigned int count = 0; |
979 | unsigned int i; | ||
979 | unsigned int interval = NATIVE_FREQUENCY / frequency; | 980 | unsigned int interval = NATIVE_FREQUENCY / frequency; |
981 | unsigned int samples = NATIVE_FREQUENCY / 1000 * duration; | ||
980 | int32_t sample; | 982 | int32_t sample; |
981 | int16_t *buf; | 983 | int16_t *bufstart; |
984 | int16_t *bufptr; | ||
982 | int16_t *pcmbuf_end = (int16_t *)fadebuf; | 985 | int16_t *pcmbuf_end = (int16_t *)fadebuf; |
983 | size_t samples = NATIVE_FREQUENCY / 1000 * duration; | 986 | bool mix = pcmbuf_read != NULL && pcmbuf_read->link != NULL; |
984 | 987 | ||
985 | if (pcm_is_playing() && pcmbuf_read != NULL) | 988 | /* Find the insertion point and set bufstart to the start of it */ |
989 | if (mix) | ||
986 | { | 990 | { |
987 | if (pcmbuf_read->link) | 991 | /* Get the next chunk */ |
988 | { | 992 | char *pcmbuf_mix_buf = pcmbuf_read->link->addr; |
989 | /* Get the next chunk */ | 993 | /* Give 1/8s clearance. */ |
990 | char *pcmbuf_mix_buf = pcmbuf_read->link->addr; | 994 | bufstart = (int16_t *)&pcmbuf_mix_buf[NATIVE_FREQUENCY * 4 / 8]; |
991 | /* Give at least 1/8s clearance. */ | ||
992 | buf = (int16_t *)&pcmbuf_mix_buf[NATIVE_FREQUENCY * 4 / 8]; | ||
993 | } | ||
994 | else | ||
995 | { | ||
996 | logf("No place to beep"); | ||
997 | return; | ||
998 | } | ||
999 | |||
1000 | while (i++ < samples) | ||
1001 | { | ||
1002 | sample = *buf; | ||
1003 | *buf++ = clip_sample_16(sample + amplitude); | ||
1004 | if (buf > pcmbuf_end) | ||
1005 | buf = (int16_t *)audiobuffer; | ||
1006 | sample = *buf; | ||
1007 | *buf++ = clip_sample_16(sample + amplitude); | ||
1008 | |||
1009 | /* Toggle square wav side */ | ||
1010 | if (++count >= interval) | ||
1011 | { | ||
1012 | count = 0; | ||
1013 | amplitude = -amplitude; | ||
1014 | } | ||
1015 | if (buf > pcmbuf_end) | ||
1016 | buf = (int16_t *)audiobuffer; | ||
1017 | } | ||
1018 | } | 995 | } |
1019 | else | 996 | else |
1020 | { | 997 | { |
1021 | buf = (int16_t *)audiobuffer; | 998 | /* Use audiobuffer */ |
1022 | while (i++ < samples) | 999 | bufstart = (int16_t *)audiobuffer; |
1023 | { | 1000 | } |
1024 | *buf++ = amplitude; | ||
1025 | if (buf > pcmbuf_end) | ||
1026 | buf = (int16_t *)audiobuffer; | ||
1027 | *buf++ = amplitude; | ||
1028 | 1001 | ||
1029 | /* Toggle square wav side */ | 1002 | /* Mix square wave into buffer */ |
1030 | if (++count >= interval) | 1003 | bufptr = bufstart; |
1031 | { | 1004 | for (i = 0; i < samples; ++i) |
1032 | count = 0; | 1005 | { |
1033 | amplitude = -amplitude; | 1006 | sample = mix ? *bufptr : 0; |
1034 | } | 1007 | *bufptr++ = clip_sample_16(sample + amplitude); |
1035 | if (buf > pcmbuf_end) | 1008 | if (bufptr > pcmbuf_end) |
1036 | buf = (int16_t *)audiobuffer; | 1009 | bufptr = (int16_t *)audiobuffer; |
1010 | sample = mix ? *bufptr : 0; | ||
1011 | *bufptr++ = clip_sample_16(sample + amplitude); | ||
1012 | if (bufptr > pcmbuf_end) | ||
1013 | bufptr = (int16_t *)audiobuffer; | ||
1014 | |||
1015 | /* Toggle square wave edge */ | ||
1016 | if (++count >= interval) | ||
1017 | { | ||
1018 | count = 0; | ||
1019 | amplitude = -amplitude; | ||
1037 | } | 1020 | } |
1038 | pcm_play_data(NULL, (unsigned char *)audiobuffer, samples * 4); | 1021 | } |
1022 | |||
1023 | /* Kick off playback if required */ | ||
1024 | if (!pcm_is_playing()) | ||
1025 | { | ||
1026 | pcm_play_data(NULL, (unsigned char *)bufstart, samples * 4); | ||
1039 | } | 1027 | } |
1040 | } | 1028 | } |
1041 | 1029 | ||
1030 | |||
1042 | /* Returns pcm buffer usage in percents (0 to 100). */ | 1031 | /* Returns pcm buffer usage in percents (0 to 100). */ |
1043 | int pcmbuf_usage(void) | 1032 | int pcmbuf_usage(void) |
1044 | { | 1033 | { |