Unified · Split
| @@ -269,8 +269,7 @@ static void voiceUpdateVolumes(int32_t i, uint8_t status) · 268 unmodified lines | |||
| 269 | // if destination volume and current volume is the same (and we have no sample trigger), don't do ramp | 269 | // if destination volume and current volume is the same (and we have no sample trigger), don't do ramp |
| 270 | if (fVolumeL == v->fVolumeL && fVolumeR == v->fVolumeR && !(status & IS_Trigger)) | 270 | if (fVolumeL == v->fVolumeL && fVolumeR == v->fVolumeR && !(status & IS_Trigger)) |
| 271 | { | 271 | { |
| 272 | // there is no volume change | 272 | v->volumeRampLength = 0; // there is no volume change |
| 273 | v->volumeRampLength = 0; | ||
| 274 | } | 273 | } |
| 275 | else | 274 | else |
| 276 | { | 275 | { |
| @@ -982,41 +981,28 @@ static void SDLCALL audioCallback(void *userdata, Uint8 *stream, int len) · 705 unmodified lines | |||
| 982 | 981 | ||
| 983 | static bool setupAudioBuffers(void) | 982 | static bool setupAudioBuffers(void) |
| 984 | { | 983 | { |
| 985 | const uint32_t sampleSize = sizeof (float); | 984 | audio.fMixBufferL = (float *)calloc(MAX_WAV_RENDER_SAMPLES_PER_TICK, sizeof (float)); |
| 986 | 985 | audio.fMixBufferR = (float *)calloc(MAX_WAV_RENDER_SAMPLES_PER_TICK, sizeof (float)); | |
| 987 | audio.fMixBufferLUnaligned = (float *)MALLOC_PAD(MAX_WAV_RENDER_SAMPLES_PER_TICK * sampleSize, 256); | ||
| 988 | audio.fMixBufferRUnaligned = (float *)MALLOC_PAD(MAX_WAV_RENDER_SAMPLES_PER_TICK * sampleSize, 256); | ||
| 989 | 986 | ||
| 990 | if (audio.fMixBufferLUnaligned == NULL || audio.fMixBufferRUnaligned == NULL) | 987 | if (audio.fMixBufferL == NULL || audio.fMixBufferR == NULL) |
| 991 | return false; | 988 | return false; |
| 992 | 989 | ||
| 993 | // make aligned main pointers | ||
| 994 | audio.fMixBufferL = (float *)ALIGN_PTR(audio.fMixBufferLUnaligned, 256); | ||
| 995 | audio.fMixBufferR = (float *)ALIGN_PTR(audio.fMixBufferRUnaligned, 256); | ||
| 996 | |||
| 997 | // clear buffers | ||
| 998 | memset(audio.fMixBufferL, 0, MAX_WAV_RENDER_SAMPLES_PER_TICK * sampleSize); | ||
| 999 | memset(audio.fMixBufferR, 0, MAX_WAV_RENDER_SAMPLES_PER_TICK * sampleSize); | ||
| 1000 | |||
| 1001 | return true; | 990 | return true; |
| 1002 | } | 991 | } |
| 1003 | 992 | ||
| 1004 | static void freeAudioBuffers(void) | 993 | static void freeAudioBuffers(void) |
| 1005 | { | 994 | { |
| 1006 | if (audio.fMixBufferLUnaligned != NULL) | 995 | if (audio.fMixBufferL != NULL) |
| 1007 | { | 996 | { |
| 1008 | free(audio.fMixBufferLUnaligned); | 997 | free(audio.fMixBufferL); |
| 1009 | audio.fMixBufferLUnaligned = NULL; | 998 | audio.fMixBufferL = NULL; |
| 1010 | } | 999 | } |
| 1011 | 1000 | ||
| 1012 | if (audio.fMixBufferRUnaligned != NULL) | 1001 | if (audio.fMixBufferR != NULL) |
| 1013 | { | 1002 | { |
| 1014 | free(audio.fMixBufferRUnaligned); | 1003 | free(audio.fMixBufferR); |
| 1015 | audio.fMixBufferRUnaligned = NULL; | 1004 | audio.fMixBufferR = NULL; |
| 1016 | } | 1005 | } |
| 1017 | |||
| 1018 | audio.fMixBufferL = NULL; | ||
| 1019 | audio.fMixBufferR = NULL; | ||
| 1020 | } | 1006 | } |
| 1021 | 1007 | ||
| 1022 | void updateSendAudSamplesRoutine(bool lockMixer) | 1008 | void updateSendAudSamplesRoutine(bool lockMixer) |
| @@ -40,7 +40,7 @@ typedef struct audio_t · 39 unmodified lines | |||
| 40 | uint32_t freq, audLatencyPerfValInt, audLatencyPerfValFrac, samplesPerTick, samplesPerTickFrac, musicTimeSpeedVal; | 40 | uint32_t freq, audLatencyPerfValInt, audLatencyPerfValFrac, samplesPerTick, samplesPerTickFrac, musicTimeSpeedVal; |
| 41 | uint64_t tickTime64, tickTime64Frac; | 41 | uint64_t tickTime64, tickTime64Frac; |
| 42 | float fRampQuickVolMul, fRampTickMul, fRampTickMulTab[(MAX_BPM-MIN_BPM)+1]; | 42 | float fRampQuickVolMul, fRampTickMul, fRampTickMulTab[(MAX_BPM-MIN_BPM)+1]; |
| 43 | float *fMixBufferL, *fMixBufferR, *fMixBufferLUnaligned, *fMixBufferRUnaligned; | 43 | float *fMixBufferL, *fMixBufferR; |
| 44 | double dHz2MixDeltaMul, dAudioLatencyMs; | 44 | double dHz2MixDeltaMul, dAudioLatencyMs; |
| 45 | 45 | ||
| 46 | SDL_AudioDeviceID dev; | 46 | SDL_AudioDeviceID dev; |
| @@ -69,9 +69,6 @@ · 68 unmodified lines | |||
| 69 | // fast 32-bit -> 16-bit clamp | 69 | // fast 32-bit -> 16-bit clamp |
| 70 | #define CLAMP16(i) if ((int16_t)(i) != i) i = 0x7FFF ^ (i >> 31) | 70 | #define CLAMP16(i) if ((int16_t)(i) != i) i = 0x7FFF ^ (i >> 31) |
| 71 | 71 | ||
| 72 | #define ALIGN_PTR(p, x) (((uintptr_t)(p) + ((x)-1)) & ~((x)-1)) | ||
| 73 | #define MALLOC_PAD(size, pad) (malloc((size) + (pad))) | ||
| 74 | |||
| 75 | #define SWAP16(x) \ | 72 | #define SWAP16(x) \ |
| 76 | ( \ | 73 | ( \ |
| 77 | (((uint16_t)((x) & 0x00FF)) << 8) | \ | 74 | (((uint16_t)((x) & 0x00FF)) << 8) | \ |
| @@ -795,13 +795,11 @@ void closeVideo(void) · 794 unmodified lines | |||
| 795 | video.window = NULL; | 795 | video.window = NULL; |
| 796 | } | 796 | } |
| 797 | 797 | ||
| 798 | if (video.frameBufferUnaligned != NULL) | 798 | if (video.frameBuffer != NULL) |
| 799 | { | 799 | { |
| 800 | free(video.frameBufferUnaligned); | 800 | free(video.frameBuffer); |
| 801 | video.frameBufferUnaligned = NULL; | 801 | video.frameBuffer = NULL; |
| 802 | } | 802 | } |
| 803 | |||
| 804 | video.frameBuffer = NULL; | ||
| 805 | } | 803 | } |
| 806 | 804 | ||
| 807 | void setWindowSizeFromConfig(bool updateRenderer) | 805 | void setWindowSizeFromConfig(bool updateRenderer) |
| @@ -1030,16 +1028,13 @@ bool setupRenderer(void) · 222 unmodified lines | |||
| 1030 | } | 1028 | } |
| 1031 | 1029 | ||
| 1032 | // framebuffer used by SDL (for texture) | 1030 | // framebuffer used by SDL (for texture) |
| 1033 | video.frameBufferUnaligned = (uint32_t *)MALLOC_PAD(SCREEN_W * SCREEN_H * sizeof (int32_t), 256); | 1031 | video.frameBuffer = (uint32_t *)malloc(SCREEN_W * SCREEN_H * sizeof (int32_t)); |
| 1034 | if (video.frameBufferUnaligned == NULL) | 1032 | if (video.frameBuffer == NULL) |
| 1035 | { | 1033 | { |
| 1036 | showErrorMsgBox("Not enough memory!"); | 1034 | showErrorMsgBox("Not enough memory!"); |
| 1037 | return false; | 1035 | return false; |
| 1038 | } | 1036 | } |
| 1039 | 1037 | ||
| 1040 | // we want an aligned pointer | ||
| 1041 | video.frameBuffer = (uint32_t *)ALIGN_PTR(video.frameBufferUnaligned, 256); | ||
| 1042 | |||
| 1043 | if (!setupSprites()) | 1038 | if (!setupSprites()) |
| 1044 | return false; | 1039 | return false; |
| 1045 | 1040 | ||
| @@ -32,7 +32,6 @@ typedef struct video_t · 31 unmodified lines | |||
| 32 | uint8_t upscaleFactor; | 32 | uint8_t upscaleFactor; |
| 33 | bool vsync60HzPresent, windowHidden; | 33 | bool vsync60HzPresent, windowHidden; |
| 34 | int32_t renderX, renderY, renderW, renderH, displayW, displayH, windowW, windowH; | 34 | int32_t renderX, renderY, renderW, renderH, displayW, displayH, windowW, windowH; |
| 35 | uint32_t *frameBufferUnaligned; | ||
| 36 | SDL_Renderer *renderer; | 35 | SDL_Renderer *renderer; |
| 37 | SDL_Texture *texture; | 36 | SDL_Texture *texture; |
| 38 | SDL_Surface *iconSurface; | 37 | SDL_Surface *iconSurface; |