fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

sound: Move filter functions to a new source file

Hampa Hug ca447828 8fca292d

+240 -145
+32
Makefile.dep
··· 34 34 src/devices/serport.h \ 35 35 src/devices/video/video.h \ 36 36 src/drivers/char/char.h \ 37 + src/drivers/sound/filter.h \ 37 38 src/drivers/sound/sound.h \ 38 39 src/lib/brkpt.h \ 39 40 src/lib/cmd.h \ ··· 83 84 src/devices/serport.h \ 84 85 src/devices/video/video.h \ 85 86 src/drivers/char/char.h \ 87 + src/drivers/sound/filter.h \ 86 88 src/drivers/sound/sound.h \ 87 89 src/lib/brkpt.h \ 88 90 src/lib/cmd.h \ ··· 125 127 src/devices/video/video.h \ 126 128 src/devices/video/wy700.h \ 127 129 src/drivers/char/char.h \ 130 + src/drivers/sound/filter.h \ 128 131 src/drivers/sound/sound.h \ 129 132 src/lib/brkpt.h \ 130 133 src/lib/cmd.h \ ··· 166 169 src/devices/serport.h \ 167 170 src/devices/video/video.h \ 168 171 src/drivers/char/char.h \ 172 + src/drivers/sound/filter.h \ 169 173 src/drivers/sound/sound.h \ 170 174 src/lib/brkpt.h \ 171 175 src/lib/cmd.h \ ··· 210 214 src/devices/serport.h \ 211 215 src/devices/video/video.h \ 212 216 src/drivers/char/char.h \ 217 + src/drivers/sound/filter.h \ 213 218 src/drivers/sound/sound.h \ 214 219 src/lib/brkpt.h \ 215 220 src/lib/cmd.h \ ··· 257 262 src/devices/serport.h \ 258 263 src/devices/video/video.h \ 259 264 src/drivers/char/char.h \ 265 + src/drivers/sound/filter.h \ 260 266 src/drivers/sound/sound.h \ 261 267 src/lib/brkpt.h \ 262 268 src/lib/cmd.h \ ··· 273 279 src/arch/ibmpc/main.h \ 274 280 src/arch/ibmpc/speaker.h \ 275 281 src/config.h \ 282 + src/drivers/sound/filter.h \ 276 283 src/drivers/sound/sound.h 277 284 278 285 src/arch/ibmpc/xms.o: src/arch/ibmpc/xms.c \ ··· 309 316 src/devices/memory.h \ 310 317 src/devices/nvram.h \ 311 318 src/drivers/char/char.h \ 319 + src/drivers/sound/filter.h \ 312 320 src/drivers/sound/sound.h \ 313 321 src/lib/brkpt.h \ 314 322 src/lib/cmd.h \ ··· 351 359 src/devices/memory.h \ 352 360 src/devices/nvram.h \ 353 361 src/drivers/char/char.h \ 362 + src/drivers/sound/filter.h \ 354 363 src/drivers/sound/sound.h \ 355 364 src/lib/brkpt.h \ 356 365 src/lib/cmd.h \ ··· 394 403 src/devices/memory.h \ 395 404 src/devices/nvram.h \ 396 405 src/drivers/char/char.h \ 406 + src/drivers/sound/filter.h \ 397 407 src/drivers/sound/sound.h \ 398 408 src/lib/brkpt.h \ 399 409 src/lib/cmd.h \ ··· 436 446 src/devices/memory.h \ 437 447 src/devices/nvram.h \ 438 448 src/drivers/char/char.h \ 449 + src/drivers/sound/filter.h \ 439 450 src/drivers/sound/sound.h \ 440 451 src/lib/brkpt.h \ 441 452 src/lib/cmd.h \ ··· 478 489 src/devices/memory.h \ 479 490 src/devices/nvram.h \ 480 491 src/drivers/char/char.h \ 492 + src/drivers/sound/filter.h \ 481 493 src/drivers/sound/sound.h \ 482 494 src/lib/brkpt.h \ 483 495 src/lib/cmd.h \ ··· 521 533 src/devices/memory.h \ 522 534 src/devices/nvram.h \ 523 535 src/drivers/char/char.h \ 536 + src/drivers/sound/filter.h \ 524 537 src/drivers/sound/sound.h \ 525 538 src/lib/brkpt.h \ 526 539 src/lib/cmd.h \ ··· 563 576 src/devices/memory.h \ 564 577 src/devices/nvram.h \ 565 578 src/drivers/char/char.h \ 579 + src/drivers/sound/filter.h \ 566 580 src/drivers/sound/sound.h \ 567 581 src/lib/brkpt.h \ 568 582 src/lib/cmd.h \ ··· 606 620 src/devices/memory.h \ 607 621 src/devices/nvram.h \ 608 622 src/drivers/char/char.h \ 623 + src/drivers/sound/filter.h \ 609 624 src/drivers/sound/sound.h \ 610 625 src/lib/brkpt.h \ 611 626 src/lib/cmd.h \ ··· 648 663 src/devices/memory.h \ 649 664 src/devices/nvram.h \ 650 665 src/drivers/char/char.h \ 666 + src/drivers/sound/filter.h \ 651 667 src/drivers/sound/sound.h \ 652 668 src/lib/brkpt.h \ 653 669 src/lib/cmd.h \ ··· 690 706 src/devices/memory.h \ 691 707 src/devices/nvram.h \ 692 708 src/drivers/char/char.h \ 709 + src/drivers/sound/filter.h \ 693 710 src/drivers/sound/sound.h \ 694 711 src/lib/brkpt.h \ 695 712 src/lib/cmd.h \ ··· 732 749 src/devices/memory.h \ 733 750 src/devices/nvram.h \ 734 751 src/drivers/char/char.h \ 752 + src/drivers/sound/filter.h \ 735 753 src/drivers/sound/sound.h \ 736 754 src/lib/brkpt.h \ 737 755 src/lib/cmd.h \ ··· 774 792 src/devices/memory.h \ 775 793 src/devices/nvram.h \ 776 794 src/drivers/char/char.h \ 795 + src/drivers/sound/filter.h \ 777 796 src/drivers/sound/sound.h \ 778 797 src/lib/brkpt.h \ 779 798 src/lib/cmd.h \ ··· 816 835 src/devices/memory.h \ 817 836 src/devices/nvram.h \ 818 837 src/drivers/char/char.h \ 838 + src/drivers/sound/filter.h \ 819 839 src/drivers/sound/sound.h \ 820 840 src/lib/brkpt.h \ 821 841 src/lib/cmd.h \ ··· 858 878 src/devices/memory.h \ 859 879 src/devices/nvram.h \ 860 880 src/drivers/char/char.h \ 881 + src/drivers/sound/filter.h \ 861 882 src/drivers/sound/sound.h \ 862 883 src/lib/brkpt.h \ 863 884 src/lib/cmd.h \ ··· 900 921 src/devices/memory.h \ 901 922 src/devices/nvram.h \ 902 923 src/drivers/char/char.h \ 924 + src/drivers/sound/filter.h \ 903 925 src/drivers/sound/sound.h \ 904 926 src/lib/brkpt.h \ 905 927 src/lib/cmd.h \ ··· 942 964 src/devices/memory.h \ 943 965 src/devices/nvram.h \ 944 966 src/drivers/char/char.h \ 967 + src/drivers/sound/filter.h \ 945 968 src/drivers/sound/sound.h \ 946 969 src/lib/brkpt.h \ 947 970 src/lib/cmd.h \ ··· 1935 1958 src/config.h \ 1936 1959 src/drivers/options.h 1937 1960 1961 + src/drivers/sound/filter.o: src/drivers/sound/filter.c \ 1962 + src/config.h \ 1963 + src/drivers/sound/filter.h 1964 + 1938 1965 src/drivers/sound/sound-null.o: src/drivers/sound/sound-null.c \ 1966 + src/drivers/sound/filter.h \ 1939 1967 src/drivers/sound/sound-null.h \ 1940 1968 src/drivers/sound/sound.h 1941 1969 1942 1970 src/drivers/sound/sound-oss.o: src/drivers/sound/sound-oss.c \ 1943 1971 src/drivers/options.h \ 1972 + src/drivers/sound/filter.h \ 1944 1973 src/drivers/sound/sound-oss.h \ 1945 1974 src/drivers/sound/sound.h 1946 1975 1947 1976 src/drivers/sound/sound-sdl.o: src/drivers/sound/sound-sdl.c \ 1948 1977 src/drivers/options.h \ 1978 + src/drivers/sound/filter.h \ 1949 1979 src/drivers/sound/sound-sdl.h \ 1950 1980 src/drivers/sound/sound.h 1951 1981 1952 1982 src/drivers/sound/sound-wav.o: src/drivers/sound/sound-wav.c \ 1953 1983 src/drivers/options.h \ 1984 + src/drivers/sound/filter.h \ 1954 1985 src/drivers/sound/sound-wav.h \ 1955 1986 src/drivers/sound/sound.h 1956 1987 1957 1988 src/drivers/sound/sound.o: src/drivers/sound/sound.c \ 1958 1989 src/config.h \ 1959 1990 src/drivers/options.h \ 1991 + src/drivers/sound/filter.h \ 1960 1992 src/drivers/sound/sound-wav.h \ 1961 1993 src/drivers/sound/sound.h 1962 1994
+2 -1
src/drivers/sound/Makefile.inc
··· 5 5 DIRS += $(rel) 6 6 DIST += $(rel)/Makefile.inc 7 7 8 - DRV_SND_BAS := sound sound-null sound-wav 8 + DRV_SND_BAS := filter sound sound-null sound-wav 9 9 DRV_SND_NBAS := 10 10 11 11 ifeq "$(PCE_ENABLE_SOUND_OSS)" "1" ··· 35 35 $(QP)echo " CC $@" 36 36 $(QR)$(CC) -c $(CFLAGS_DEFAULT) $(PCE_SDL_CFLAGS) -o $@ $< 37 37 38 + $(rel)/filter.o: $(rel)/filter.c 38 39 $(rel)/sound.o: $(rel)/sound.c 39 40 $(rel)/sound-null.o: $(rel)/sound-null.c 40 41 $(rel)/sound-oss.o: $(rel)/sound-oss.c
+129
src/drivers/sound/filter.c
··· 1 + /***************************************************************************** 2 + * pce * 3 + *****************************************************************************/ 4 + 5 + /***************************************************************************** 6 + * File name: src/drivers/sound/filter.c * 7 + * Created: 2010-08-27 by Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2010 Hampa Hug <hampa@hampa.ch> * 9 + *****************************************************************************/ 10 + 11 + /***************************************************************************** 12 + * This program is free software. You can redistribute it and / or modify it * 13 + * under the terms of the GNU General Public License version 2 as published * 14 + * by the Free Software Foundation. * 15 + * * 16 + * This program is distributed in the hope that it will be useful, but * 17 + * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 + * Public License for more details. * 20 + *****************************************************************************/ 21 + 22 + 23 + #include <config.h> 24 + 25 + #include <stdint.h> 26 + #include <math.h> 27 + 28 + #include <drivers/sound/filter.h> 29 + 30 + 31 + #define SND_IIR_MUL 8192 32 + 33 + 34 + void snd_iir2_init (sound_iir2_t *iir) 35 + { 36 + unsigned i; 37 + 38 + for (i = 0; i < 3; i++) { 39 + iir->a[i] = 0; 40 + iir->b[i] = 0; 41 + iir->x[i] = 0; 42 + iir->y[i] = 0; 43 + } 44 + 45 + iir->a[0] = SND_IIR_MUL; 46 + } 47 + 48 + void snd_iir2_reset (sound_iir2_t *iir) 49 + { 50 + iir->x[0] = 0; 51 + iir->x[1] = 0; 52 + iir->x[2] = 0; 53 + 54 + iir->y[0] = 0; 55 + iir->y[1] = 0; 56 + iir->y[2] = 0; 57 + } 58 + 59 + void snd_iir2_set_lowpass (sound_iir2_t *iir, unsigned long freq, unsigned long srate) 60 + { 61 + double om, b0; 62 + 63 + snd_iir2_init (iir); 64 + 65 + if ((freq == 0) || (srate == 0)) { 66 + return; 67 + } 68 + 69 + if ((2 * freq) >= srate) { 70 + freq = (srate / 2) - 1; 71 + } 72 + 73 + om = 1.0 / tan ((3.14159265358979312 * freq) / srate); 74 + b0 = om * (om + sqrt(2.0)) + 1.0; 75 + 76 + iir->a[0] = (long) (SND_IIR_MUL * 1.0 / b0); 77 + iir->a[1] = (long) (SND_IIR_MUL * 2.0 / b0); 78 + iir->a[2] = (long) (SND_IIR_MUL * 1.0 / b0); 79 + 80 + iir->b[0] = (long) (SND_IIR_MUL * 1.0); 81 + iir->b[1] = (long) (SND_IIR_MUL * 2.0 * (1.0 - om * om) / b0); 82 + iir->b[2] = (long) (SND_IIR_MUL * (om * (om - sqrt(2.0)) + 1.0) / b0); 83 + } 84 + 85 + void snd_iir2_filter (sound_iir2_t *iir, uint16_t *dst, const uint16_t *src, 86 + unsigned cnt, unsigned ofs, int sign) 87 + { 88 + long v; 89 + uint16_t sig; 90 + 91 + sig = sign ? 0x8000 : 0; 92 + 93 + while (cnt > 0) { 94 + v = *src ^ sig; 95 + v -= 32768; 96 + 97 + iir->x[2] = iir->x[1]; 98 + iir->x[1] = iir->x[0]; 99 + iir->x[0] = v; 100 + 101 + iir->y[2] = iir->y[1]; 102 + iir->y[1] = iir->y[0]; 103 + 104 + iir->y[0] = iir->a[0] * iir->x[0]; 105 + iir->y[0] += iir->a[1] * iir->x[1] + iir->a[2] * iir->x[2]; 106 + iir->y[0] -= iir->b[1] * iir->y[1] + iir->b[2] * iir->y[2]; 107 + 108 + iir->y[0] = iir->y[0] / SND_IIR_MUL; 109 + 110 + v = iir->y[0]; 111 + v += 32768; 112 + 113 + if (v < 0) { 114 + v = 0; 115 + } 116 + else if (v > 65535) { 117 + v = 0xffff; 118 + } 119 + else { 120 + v &= 0xffff; 121 + } 122 + 123 + *dst = ((uint16_t) v) ^ sig; 124 + 125 + src += ofs; 126 + dst += ofs; 127 + cnt -= 1; 128 + } 129 + }
+75
src/drivers/sound/filter.h
··· 1 + /***************************************************************************** 2 + * pce * 3 + *****************************************************************************/ 4 + 5 + /***************************************************************************** 6 + * File name: src/drivers/sound/sound.h * 7 + * Created: 2010-08-27 by Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2010 Hampa Hug <hampa@hampa.ch> * 9 + *****************************************************************************/ 10 + 11 + /***************************************************************************** 12 + * This program is free software. You can redistribute it and / or modify it * 13 + * under the terms of the GNU General Public License version 2 as published * 14 + * by the Free Software Foundation. * 15 + * * 16 + * This program is distributed in the hope that it will be useful, but * 17 + * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 + * Public License for more details. * 20 + *****************************************************************************/ 21 + 22 + 23 + #ifndef PCE_DRIVERS_SOUND_FILTER_H 24 + #define PCE_DRIVERS_SOUND_FILTER_H 1 25 + 26 + 27 + #include <stdint.h> 28 + 29 + 30 + /*!*************************************************************************** 31 + * @short A second order IIR filter 32 + *****************************************************************************/ 33 + typedef struct { 34 + long a[3]; 35 + long b[3]; 36 + long x[3]; 37 + long y[3]; 38 + } sound_iir2_t; 39 + 40 + 41 + /*!*************************************************************************** 42 + * @short Initialize an IIR2 filter 43 + *****************************************************************************/ 44 + void snd_iir2_init (sound_iir2_t *iir); 45 + 46 + /*!*************************************************************************** 47 + * @short Reset an IIR2 filter 48 + *****************************************************************************/ 49 + void snd_iir2_reset (sound_iir2_t *iir); 50 + 51 + /*!*************************************************************************** 52 + * @short Initialize a low-pass IIR filter 53 + * @param freq The cut-off frequency 54 + * @param srate The sample rate 55 + *****************************************************************************/ 56 + void snd_iir2_set_lowpass (sound_iir2_t *iir, 57 + unsigned long freq, unsigned long srate 58 + ); 59 + 60 + /*!*************************************************************************** 61 + * @short Filter samples with an IIR2 filter 62 + * @param dst The destination buffer 63 + * @param src The source buffer 64 + * @param cnt The sample count 65 + * @param ofs The sample offset in both src and dst 66 + * @param sign The sample signedness in both src and dst 67 + * 68 + * The source and destination buffer can be the same. 69 + *****************************************************************************/ 70 + void snd_iir2_filter (sound_iir2_t *iir, 71 + uint16_t *dst, const uint16_t *src, unsigned cnt, unsigned ofs, int sign 72 + ); 73 + 74 + 75 + #endif
-101
src/drivers/sound/sound.c
··· 24 24 25 25 #include <stdlib.h> 26 26 #include <string.h> 27 - #include <math.h> 28 27 29 28 #include <drivers/options.h> 30 29 #include <drivers/sound/sound.h> 31 30 #include <drivers/sound/sound-wav.h> 32 - 33 - 34 - #define SND_IIR_MUL 8192 35 31 36 32 37 33 struct snd_drv_list { ··· 55 51 { NULL, NULL } 56 52 }; 57 53 58 - 59 - void snd_iir2_init (sound_iir2_t *iir) 60 - { 61 - unsigned i; 62 - 63 - for (i = 0; i < 3; i++) { 64 - iir->a[i] = 0; 65 - iir->b[i] = 0; 66 - iir->x[i] = 0; 67 - iir->y[i] = 0; 68 - } 69 - 70 - iir->a[0] = SND_IIR_MUL; 71 - } 72 - 73 - void snd_iir2_reset (sound_iir2_t *iir) 74 - { 75 - iir->x[0] = 0; 76 - iir->x[1] = 0; 77 - iir->x[2] = 0; 78 - 79 - iir->y[0] = 0; 80 - iir->y[1] = 0; 81 - iir->y[2] = 0; 82 - } 83 - 84 - void snd_iir2_set_lowpass (sound_iir2_t *iir, unsigned long freq, unsigned long srate) 85 - { 86 - double om, b0; 87 - 88 - snd_iir2_init (iir); 89 - 90 - if ((freq == 0) || (srate == 0)) { 91 - return; 92 - } 93 - 94 - if ((2 * freq) >= srate) { 95 - freq = (srate / 2) - 1; 96 - } 97 - 98 - om = 1.0 / tan ((3.14159265358979312 * freq) / srate); 99 - b0 = om * (om + sqrt(2.0)) + 1.0; 100 - 101 - iir->a[0] = (long) (SND_IIR_MUL * 1.0 / b0); 102 - iir->a[1] = (long) (SND_IIR_MUL * 2.0 / b0); 103 - iir->a[2] = (long) (SND_IIR_MUL * 1.0 / b0); 104 - 105 - iir->b[0] = (long) (SND_IIR_MUL * 1.0); 106 - iir->b[1] = (long) (SND_IIR_MUL * 2.0 * (1.0 - om * om) / b0); 107 - iir->b[2] = (long) (SND_IIR_MUL * (om * (om - sqrt(2.0)) + 1.0) / b0); 108 - } 109 - 110 - void snd_iir2_filter (sound_iir2_t *iir, uint16_t *dst, const uint16_t *src, 111 - unsigned cnt, unsigned ofs, int sign) 112 - { 113 - long v; 114 - uint16_t sig; 115 - 116 - sig = sign ? 0x8000 : 0; 117 - 118 - while (cnt > 0) { 119 - v = *src ^ sig; 120 - v -= 32768; 121 - 122 - iir->x[2] = iir->x[1]; 123 - iir->x[1] = iir->x[0]; 124 - iir->x[0] = v; 125 - 126 - iir->y[2] = iir->y[1]; 127 - iir->y[1] = iir->y[0]; 128 - 129 - iir->y[0] = iir->a[0] * iir->x[0]; 130 - iir->y[0] += iir->a[1] * iir->x[1] + iir->a[2] * iir->x[2]; 131 - iir->y[0] -= iir->b[1] * iir->y[1] + iir->b[2] * iir->y[2]; 132 - 133 - iir->y[0] = iir->y[0] / SND_IIR_MUL; 134 - 135 - v = iir->y[0]; 136 - v += 32768; 137 - 138 - if (v < 0) { 139 - v = 0; 140 - } 141 - else if (v > 65535) { 142 - v = 0xffff; 143 - } 144 - else { 145 - v &= 0xffff; 146 - } 147 - 148 - *dst = ((uint16_t) v) ^ sig; 149 - 150 - src += ofs; 151 - dst += ofs; 152 - cnt -= 1; 153 - } 154 - } 155 54 156 55 /* 157 56 * Initialize the low-pass filter in sdrv->lowpass_iir2 with a cut-off
+2 -43
src/drivers/sound/sound.h
··· 27 27 #include <stdio.h> 28 28 #include <stdint.h> 29 29 30 + #include <drivers/sound/filter.h> 31 + 30 32 31 33 #define SND_CHN_MAX 16 32 - 33 - 34 - /*!*************************************************************************** 35 - * @short A second order IIR filter 36 - *****************************************************************************/ 37 - typedef struct { 38 - long a[3]; 39 - long b[3]; 40 - long x[3]; 41 - long y[3]; 42 - } sound_iir2_t; 43 34 44 35 45 36 /*!*************************************************************************** ··· 73 64 unsigned chn, unsigned long srate, int sign 74 65 ); 75 66 } sound_drv_t; 76 - 77 - 78 - /*!*************************************************************************** 79 - * @short Initialize an IIR2 filter 80 - *****************************************************************************/ 81 - void snd_iir2_init (sound_iir2_t *iir); 82 - 83 - /*!*************************************************************************** 84 - * @short Reset an IIR2 filter 85 - *****************************************************************************/ 86 - void snd_iir2_reset (sound_iir2_t *iir); 87 - 88 - /*!*************************************************************************** 89 - * @short Initialize a low-pass IIR filter 90 - * @param freq The cut-off frequency 91 - * @param srate The sample rate 92 - *****************************************************************************/ 93 - void snd_iir2_set_lowpass (sound_iir2_t *iir, 94 - unsigned long freq, unsigned long srate 95 - ); 96 - 97 - /*!*************************************************************************** 98 - * @short Filter samples with an IIR2 filter 99 - * @param dst The destination buffer 100 - * @param src The source buffer 101 - * @param cnt The sample count 102 - * @param ofs The sample offset in both src and dst 103 - * @param sign The sample signedness in both src and dst 104 - *****************************************************************************/ 105 - void snd_iir2_filter (sound_iir2_t *iir, 106 - uint16_t *dst, const uint16_t *src, unsigned cnt, unsigned ofs, int sign 107 - ); 108 67 109 68 110 69 /*!***************************************************************************