diff options
author | Brandon Low <lostlogic@rockbox.org> | 2006-03-07 23:10:24 +0000 |
---|---|---|
committer | Brandon Low <lostlogic@rockbox.org> | 2006-03-07 23:10:24 +0000 |
commit | 06d085a952f35b58a0660696be39335a3f8a19e1 (patch) | |
tree | a511cf65dcb55878019a375bc0067e447907deaf | |
parent | 838a7020c7a4b623ac11e8aa4588c815d3641b43 (diff) | |
download | rockbox-06d085a952f35b58a0660696be39335a3f8a19e1.tar.gz rockbox-06d085a952f35b58a0660696be39335a3f8a19e1.zip |
_Slight_ optimization of peak calculation
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8949 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/pcm_playback.c | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/firmware/pcm_playback.c b/firmware/pcm_playback.c index 75b3de4f90..0ae87f4310 100644 --- a/firmware/pcm_playback.c +++ b/firmware/pcm_playback.c | |||
@@ -333,7 +333,7 @@ static int pcm_freq = 0x6; /* 44.1 is default */ | |||
333 | /* NOTE: The order of these two variables is important if you use the iPod | 333 | /* NOTE: The order of these two variables is important if you use the iPod |
334 | assembler optimised fiq handler, so don't change it. */ | 334 | assembler optimised fiq handler, so don't change it. */ |
335 | unsigned short* p IBSS_ATTR; | 335 | unsigned short* p IBSS_ATTR; |
336 | long p_size IBSS_ATTR; | 336 | size_t p_size IBSS_ATTR; |
337 | 337 | ||
338 | static void dma_start(const void *addr, size_t size) | 338 | static void dma_start(const void *addr, size_t size) |
339 | { | 339 | { |
@@ -751,31 +751,41 @@ size_t pcm_get_bytes_waiting(void) | |||
751 | * every tenth sample would still be pretty accurate). | 751 | * every tenth sample would still be pretty accurate). |
752 | */ | 752 | */ |
753 | 753 | ||
754 | #define PEAK_SAMPLES (44100*2/HZ) /* 44100 samples * 2 / 100 Hz tick */ | 754 | /* Check for a peak every PEAK_STRIDE samples */ |
755 | #define PEAK_STRIDE 3 /* every 3rd sample is plenty... */ | 755 | #define PEAK_STRIDE 3 |
756 | /* Up to 1/50th of a second of audio for peak calculation */ | ||
757 | /* This should use NATIVE_FREQUENCY, or eventually an adjustable freq. value */ | ||
758 | #define PEAK_SAMPLES (44100/50) | ||
756 | 759 | ||
757 | void pcm_calculate_peaks(int *left, int *right) | 760 | void pcm_calculate_peaks(int *left, int *right) |
758 | { | 761 | { |
762 | short *addr; | ||
763 | short *end; | ||
764 | { | ||
759 | #ifdef HAVE_UDA1380 | 765 | #ifdef HAVE_UDA1380 |
760 | long samples = (BCR0 & 0xffffff) / 4; | 766 | size_t samples = (BCR0 & 0xffffff) / 4; |
761 | short *addr = (short *) (SAR0 & ~3); | 767 | addr = (short *) (SAR0 & ~3); |
762 | #elif defined(HAVE_WM8975) || defined(HAVE_WM8758) || defined(HAVE_WM8731) | 768 | #elif defined(HAVE_WM8975) || defined(HAVE_WM8758) || defined(HAVE_WM8731) |
763 | long samples = p_size / 4; | 769 | size_t samples = p_size / 4; |
764 | short *addr = p; | 770 | addr = p; |
765 | #elif defined(HAVE_TLV320) | 771 | #elif defined(HAVE_TLV320) |
766 | long samples = 4; /* TODO X5 */ | 772 | size_t samples = 4; /* TODO X5 */ |
767 | short *addr = NULL; | 773 | addr = NULL; |
768 | #endif | 774 | #endif |
769 | 775 | ||
770 | if (samples > PEAK_SAMPLES) | 776 | if (samples > PEAK_SAMPLES) |
771 | samples = PEAK_SAMPLES; | 777 | samples = PEAK_SAMPLES - (PEAK_STRIDE - 1); |
778 | else | ||
779 | samples -= MIN((PEAK_STRIDE - 1), samples); | ||
772 | 780 | ||
773 | samples /= PEAK_STRIDE; | 781 | end = addr + samples * 4; |
782 | } | ||
774 | 783 | ||
775 | if (left && right) { | 784 | if (left && right) { |
776 | int left_peak = 0, right_peak = 0, value; | 785 | int left_peak = 0, right_peak = 0; |
777 | 786 | ||
778 | while (samples--) { | 787 | while (addr < end) { |
788 | int value; | ||
779 | if ((value = addr [0]) > left_peak) | 789 | if ((value = addr [0]) > left_peak) |
780 | left_peak = value; | 790 | left_peak = value; |
781 | else if (-value > left_peak) | 791 | else if (-value > left_peak) |
@@ -798,7 +808,7 @@ void pcm_calculate_peaks(int *left, int *right) | |||
798 | if (right) | 808 | if (right) |
799 | addr += (PEAK_STRIDE | 1); | 809 | addr += (PEAK_STRIDE | 1); |
800 | 810 | ||
801 | while (samples--) { | 811 | while (addr < end) { |
802 | if ((value = addr [0]) > peak_value) | 812 | if ((value = addr [0]) > peak_value) |
803 | peak_value = value; | 813 | peak_value = value; |
804 | else if (-value > peak_value) | 814 | else if (-value > peak_value) |