Blastfrog Posted October 30, 2012 In an attempt at actually being able to program in C so that I can become self-proficient to make my own code changes, I've dabbled a bit in messing with Chocolate Doom's source before. First, I tried to implement Jaguar Doom behavior (still very unfinished, but I got a bit of it started), and edited Chocolate Hexen to have Mario style jumping and 1:1 pixels instead of 5:6 pixels, but I think I want to create a just a slight edit of just plain Chocolate Doom without any absurdly ambitious goals to change a few things that I'd like to. So far, I've gotten the following done: *Fixed ouch-face bug *Quadrupled some rendering limits *Fixed GOTMEDINEED not appearing in messages *Fixed sky never changing *Restored color back to 24 bit RGB instead of DOS's 18 bit RGB Anyway, first question: Porsche Monty said:There's a gamma shift bug in vanilla Doom (that's also replicated in Chocolate) which prevents the exact original colours from being used, but it's something so subtle you don't notice unless you're kind of looking for it. What does it do wrong, and how is it supposed to work to provide absolutely correct colors? EDIT: Okay, so I found the table in v_video.c, and I noticed that there was no 0, and 128 occurred twice. I fixed that easily enough. What's the most ideal way to reconstruct the last 4 tables? My second question is how can I reimplement pitch shifting? I've tried adding it back in from previous revisions of Chocolate Doom without touching anything else in S_Sound.C, but it results in a compiler error in CygWin complaining about "too many arguments to function". This is what I have of it so far, but it's still not compiling with these changes: http://pastebin.com/DzdvCVKJ 0 Share this post Link to post
bradharding Posted October 30, 2012 Hi, The gamma shift bug refers to the fact that even when gamma correction is off, Vanilla DOOM still adjusts the palette. This means that the colours on screen are slightly different to the colours used in screenshots. If you have a look at gammatable[0], you'll see the values 1..128 and then 128..255. That means for the first 128 colours of the palette, they are made slightly lighter. Black (0,0,0) is not completely black (1,1,1) and so on. Simply changing the values in gammatable[0] to 0..255 will fix this. The other gamma levels are fine as is I guess. As for random pitch, you've done the work in s_sound.c, but there's more to do in i_sdlsound.c as well. Have a look at Strawberry DOOM's source at http://strawberry-doom.svn.sourceforge.net/ for ideas. Before coming across that source, I had a go at doing random pitch myself. The fugly function below seems to work: Mix_Chunk *ChangePitch(Mix_Chunk *sample, float factor) { Mix_Chunk *result; Uint32 samples_in = sample->alen / 4; Uint32 samples_out = (Uint32)((float)samples_in * factor); float factor_real = (float)samples_out / (float)samples_in; Uint32 i,j; result = (Mix_Chunk *)malloc(sizeof(Mix_Chunk)); result->allocated = 1; result->alen = samples_out * 4; result->abuf = (Uint8*)malloc(result->alen * sizeof(Uint8)); result->volume = sample->volume; for (i = 0; i < samples_out; i++) { Sint16 left; Sint16 right; Sint16 left_out; Sint16 right_out; Sint64 left_average = 0; Sint64 right_average = 0; Uint32 begin = (Uint32)((float)i / factor_real); Uint32 end = (Uint32)((float)(i + 1) / factor_real); for (j = begin; j <= end; j++) { left = (sample->abuf[(4 * j) + 1] << 8) | (sample->abuf[(4 * j) + 0]); right = (sample->abuf[(4 * j) + 3] << 8) | (sample->abuf[(4 * j) + 2]); left_average += left; right_average += right; } left_out = (Sint16)((float)left_average / (float)(end - begin + 1)); right_out = (Sint16)((float)right_average / (float)(end - begin + 1)); result->abuf[(4 * i) + 1] = (left_out >> 8) & 0xFF; result->abuf[(4 * i) + 0] = left_out & 0xFF; result->abuf[(4 * i) + 3] = (right_out >> 8) & 0xFF; result->abuf[(4 * i) + 2] = right_out & 0xFF; } return result; } And then before the call to Mix_PlayChannelTimed() in I_SDL_StartSound() in i_sdlsound.c, call ChangePitch(chunk, factor) where factor is a random float between 0.8 and 1.2 (1.0 being normal pitch). And after all that, I discovered I hate random pitch, and don't want it in my [unreleased] source port anyway. Hope all this helps. 0 Share this post Link to post
Maes Posted October 30, 2012 The sound mixing code in linuxdoom can handle pitch changes, but it needs serious refactoring to make it work with the rest of the sound functions. In Mocha Doom I'm using a direct port of that code. Pitch variations are achieved by using fixed_t indexes into samples, so that delayed/accelerated per-sample playback (within certain limits) is possible. Known limitations: it works at a fixed final sampling rate, and assumes that all samples are unsigned, mono, 8-bit, even though it mixes in 16 bit precision. So heterogeneous samples will need preconvesion. The pitch system isn't continuous: there is a total of 256 possible pitches (stored in a table as fixed_t numbers) which represent values from 0.25 to 4.00, so pitch variations are within +/- 400%. In practice, not all were used, but it's not clear which range was actually coded. Neutral pitch is index 128, normal variation is 128 +/- 16. I'd say it results in +/- 25% actual shifting. Due to the fixed_t system used for pitch, maximum possible sample length is 64K samples, regardless of sampling rate. Mixing isn't particularly clean or Hi-Fi. It just works by saturation arithmetic and doesn't take into account how many channels are being actually played in order to normalize the final output volume. Very easy to clip and sound harsh. The mixing loop operates on a fixed-size buffer, whose size is a compromize between smoothness (the larger it is, the less often you need to call the mixing routine via e.g. threads or interrupts), and rapidity in adapting to new sounds (if too large, you won't be able to play new sounds very often). This means that there is an "audio frame rate" as well, and the buffer's size is given by final sampling rate / desired audio frame rate. In the linux doom code, it's implied to be between 21-22 fps, and the audio buffer's size was set to 525...oversight, maybe? Not a power/multiple of 2 :-S 0 Share this post Link to post
RestlessRodent Posted October 31, 2012 doomengine2012 said:As for random pitch, you've done the work in s_sound.c, but there's more to do in i_sdlsound.c as well. Have a look at Strawberry DOOM's source at http://strawberry-doom.svn.sourceforge.net/ for ideas. Before coming across that source, I had a go at doing random pitch myself. The fugly function below seems to work: Random pitching in Strawberry Doom was a big hack on Chocolate Doom to allow it to pitch. Chocolate Doom uses SDL_mixer and has SDL_mixer do all the sound mixing rather than doing it itself. So basically my code creates multiple copies of a single sound pitched (wastes tons of memory). The reason I did this is because the code is very intertwined and would have been difficult to rip out the old SDL sound and put in my own buffering code. The sound mixing engine in ReMooD manages its own buffer, and it can do pitching any way it wants to. In the mercurial root, these would be across i_utlsfx.[ch] and s_sound.[ch]. ReMooD also supports on the fly pitch changing, which eventually I could add doppler effects, etc. 0 Share this post Link to post
Maes Posted October 31, 2012 Another limitation of the linuxdoom sound code I forgot to mention: sound samples must be padded with silence to an integer multiple of the mixing buffer's size, yet another reason not to use large mixing buffers. Here are the contents of the pitch steptable: Index fixed_t floating Pitch -128 16384 0,250000 Pitch -127 16562 0,252716 Pitch -126 16742 0,255463 Pitch -125 16925 0,258255 Pitch -124 17109 0,261063 Pitch -123 17295 0,263901 Pitch -122 17484 0,266785 Pitch -121 17674 0,269684 Pitch -120 17866 0,272614 Pitch -119 18061 0,275589 Pitch -118 18258 0,278595 Pitch -117 18456 0,281616 Pitch -116 18657 0,284683 Pitch -115 18861 0,287796 Pitch -114 19066 0,290924 Pitch -113 19274 0,294098 Pitch -112 19483 0,297287 Pitch -111 19696 0,300537 Pitch -110 19910 0,303802 Pitch -109 20127 0,307114 Pitch -108 20346 0,310455 Pitch -107 20568 0,313843 Pitch -106 20792 0,317261 Pitch -105 21018 0,320709 Pitch -104 21247 0,324203 Pitch -103 21478 0,327728 Pitch -102 21712 0,331299 Pitch -101 21949 0,334915 Pitch -100 22188 0,338562 Pitch -99 22429 0,342239 Pitch -98 22673 0,345963 Pitch -97 22920 0,349731 Pitch -96 23170 0,353546 Pitch -95 23422 0,357391 Pitch -94 23677 0,361282 Pitch -93 23935 0,365219 Pitch -92 24196 0,369202 Pitch -91 24459 0,373215 Pitch -90 24726 0,377289 Pitch -89 24995 0,381393 Pitch -88 25267 0,385544 Pitch -87 25542 0,389740 Pitch -86 25820 0,393982 Pitch -85 26102 0,398285 Pitch -84 26386 0,402618 Pitch -83 26673 0,406998 Pitch -82 26964 0,411438 Pitch -81 27257 0,415909 Pitch -80 27554 0,420441 Pitch -79 27854 0,425018 Pitch -78 28157 0,429642 Pitch -77 28464 0,434326 Pitch -76 28774 0,439056 Pitch -75 29087 0,443832 Pitch -74 29404 0,448669 Pitch -73 29724 0,453552 Pitch -72 30048 0,458496 Pitch -71 30375 0,463486 Pitch -70 30706 0,468536 Pitch -69 31040 0,473633 Pitch -68 31378 0,478790 Pitch -67 31720 0,484009 Pitch -66 32065 0,489273 Pitch -65 32415 0,494614 Pitch -64 32768 0,500000 Pitch -63 33124 0,505432 Pitch -62 33485 0,510941 Pitch -61 33850 0,516510 Pitch -60 34218 0,522125 Pitch -59 34591 0,527817 Pitch -58 34968 0,533569 Pitch -57 35348 0,539368 Pitch -56 35733 0,545242 Pitch -55 36122 0,551178 Pitch -54 36516 0,557190 Pitch -53 36913 0,563248 Pitch -52 37315 0,569382 Pitch -51 37722 0,575592 Pitch -50 38132 0,581848 Pitch -49 38548 0,588196 Pitch -48 38967 0,594589 Pitch -47 39392 0,601074 Pitch -46 39821 0,607620 Pitch -45 40254 0,614227 Pitch -44 40693 0,620926 Pitch -43 41136 0,627686 Pitch -42 41584 0,634521 Pitch -41 42037 0,641434 Pitch -40 42494 0,648407 Pitch -39 42957 0,655472 Pitch -38 43425 0,662613 Pitch -37 43898 0,669830 Pitch -36 44376 0,677124 Pitch -35 44859 0,684494 Pitch -34 45347 0,691940 Pitch -33 45841 0,699478 Pitch -32 46340 0,707092 Pitch -31 46845 0,714798 Pitch -30 47355 0,722580 Pitch -29 47871 0,730453 Pitch -28 48392 0,738403 Pitch -27 48919 0,746445 Pitch -26 49452 0,754578 Pitch -25 49990 0,762787 Pitch -24 50535 0,771103 Pitch -23 51085 0,779495 Pitch -22 51641 0,787979 Pitch -21 52204 0,796570 Pitch -20 52772 0,805237 Pitch -19 53347 0,814011 Pitch -18 53928 0,822876 Pitch -17 54515 0,831833 Pitch -16 55108 0,840881 Pitch -15 55709 0,850052 Pitch -14 56315 0,859299 Pitch -13 56928 0,868652 Pitch -12 57548 0,878113 Pitch -11 58175 0,887680 Pitch -10 58809 0,897354 Pitch -9 59449 0,907120 Pitch -8 60096 0,916992 Pitch -7 60751 0,926987 Pitch -6 61412 0,937073 Pitch -5 62081 0,947281 Pitch -4 62757 0,957596 Pitch -3 63440 0,968018 Pitch -2 64131 0,978561 Pitch -1 64830 0,989227 Pitch 0 65536 1,000000 Pitch 1 66249 1,010880 Pitch 2 66971 1,021896 Pitch 3 67700 1,033020 Pitch 4 68437 1,044266 Pitch 5 69182 1,055634 Pitch 6 69936 1,067139 Pitch 7 70697 1,078751 Pitch 8 71467 1,090500 Pitch 9 72245 1,102371 Pitch 10 73032 1,114380 Pitch 11 73827 1,126511 Pitch 12 74631 1,138779 Pitch 13 75444 1,151184 Pitch 14 76265 1,163712 Pitch 15 77096 1,176392 Pitch 16 77935 1,189194 Pitch 17 78784 1,202148 Pitch 18 79642 1,215240 Pitch 19 80509 1,228470 Pitch 20 81386 1,241852 Pitch 21 82272 1,255371 Pitch 22 83168 1,269043 Pitch 23 84074 1,282867 Pitch 24 84989 1,296829 Pitch 25 85915 1,310959 Pitch 26 86850 1,325226 Pitch 27 87796 1,339661 Pitch 28 88752 1,354248 Pitch 29 89718 1,368988 Pitch 30 90695 1,383896 Pitch 31 91683 1,398972 Pitch 32 92681 1,414200 Pitch 33 93691 1,429611 Pitch 34 94711 1,445175 Pitch 35 95742 1,460907 Pitch 36 96785 1,476822 Pitch 37 97839 1,492905 Pitch 38 98904 1,509155 Pitch 39 99981 1,525589 Pitch 40 101070 1,542206 Pitch 41 102170 1,558990 Pitch 42 103283 1,575974 Pitch 43 104408 1,593140 Pitch 44 105545 1,610489 Pitch 45 106694 1,628021 Pitch 46 107856 1,645752 Pitch 47 109030 1,663666 Pitch 48 110217 1,681778 Pitch 49 111418 1,700104 Pitch 50 112631 1,718613 Pitch 51 113857 1,737320 Pitch 52 115097 1,756241 Pitch 53 116351 1,775375 Pitch 54 117618 1,794708 Pitch 55 118898 1,814240 Pitch 56 120193 1,834000 Pitch 57 121502 1,853973 Pitch 58 122825 1,874161 Pitch 59 124162 1,894562 Pitch 60 125514 1,915192 Pitch 61 126881 1,936050 Pitch 62 128263 1,957138 Pitch 63 129660 1,978455 Pitch 64 131072 2,000000 Pitch 65 132499 2,021774 Pitch 66 133942 2,043793 Pitch 67 135400 2,066040 Pitch 68 136875 2,088547 Pitch 69 138365 2,111282 Pitch 70 139872 2,134277 Pitch 71 141395 2,157516 Pitch 72 142935 2,181015 Pitch 73 144491 2,204758 Pitch 74 146064 2,228760 Pitch 75 147655 2,253036 Pitch 76 149263 2,277573 Pitch 77 150888 2,302368 Pitch 78 152531 2,327438 Pitch 79 154192 2,352783 Pitch 80 155871 2,378403 Pitch 81 157569 2,404312 Pitch 82 159284 2,430481 Pitch 83 161019 2,456955 Pitch 84 162772 2,483704 Pitch 85 164545 2,510757 Pitch 86 166337 2,538101 Pitch 87 168148 2,565735 Pitch 88 169979 2,593674 Pitch 89 171830 2,621918 Pitch 90 173701 2,650467 Pitch 91 175592 2,679321 Pitch 92 177504 2,708496 Pitch 93 179437 2,737991 Pitch 94 181391 2,767807 Pitch 95 183367 2,797958 Pitch 96 185363 2,828415 Pitch 97 187382 2,859222 Pitch 98 189422 2,890350 Pitch 99 191485 2,921829 Pitch 100 193570 2,953644 Pitch 101 195678 2,985809 Pitch 102 197809 3,018326 Pitch 103 199963 3,051193 Pitch 104 202140 3,084412 Pitch 105 204341 3,117996 Pitch 106 206566 3,151947 Pitch 107 208816 3,186279 Pitch 108 211090 3,220978 Pitch 109 213388 3,256042 Pitch 110 215712 3,291504 Pitch 111 218061 3,327347 Pitch 112 220435 3,363571 Pitch 113 222836 3,400208 Pitch 114 225262 3,437225 Pitch 115 227715 3,474655 Pitch 116 230195 3,512497 Pitch 117 232702 3,550751 Pitch 118 235236 3,589417 Pitch 119 237797 3,628494 Pitch 120 240387 3,668015 Pitch 121 243004 3,707947 Pitch 122 245650 3,748322 Pitch 123 248325 3,789139 Pitch 124 251029 3,830399 Pitch 125 253763 3,872116 Pitch 126 256526 3,914276 Pitch 127 259320 3,956909 Pitch is normally set at S_StartSoundAtVolume: ... // hacks to vary the sfx pitches if (sfx_id >= sfxenum_t.sfx_sawup.ordinal() && sfx_id <= sfxenum_t.sfx_sawhit.ordinal()) { pitch += 8 - (DS.RND.M_Random()&15); if (pitch<0) pitch = 0; else if (pitch>255) pitch = 255; } Since only pitch indexes 0 +/- 8 are used, actual pitch variations are only -/+ 9%. It's possible to make them more extreme by making those values into constants or customizable variables.... 0 Share this post Link to post
Blastfrog Posted October 31, 2012 Maes said:Since only pitch indexes 0 +/- 8 are used, actual pitch variations are only -/+ 9%. It's possible to make them more extreme by making those values into constants or customizable variables.... Dehacked allowed you to edit default starting sound pitches, didn't it? 0 Share this post Link to post
Maes Posted October 31, 2012 Sodaholic said:Dehacked allowed you to edit default starting sound pitches, didn't it? No idea. Either way, pitches were only used in Doom v1.1, I don't even know if Dehacked ever supported that. 0 Share this post Link to post