History

Remove extra mem alloc alignment (unnecessary)

Olav Sørensen committed 3 years ago

Commit cef9c3e1 parent 3af99af5 files · +16 −39Browse files

Unified · Split

5 files
  1. src/ft2_audio.c +10 −24
  2. src/ft2_audio.h +1 −1
  3. src/ft2_header.h +0 −3
  4. src/ft2_video.c +5 −10
  5. src/ft2_video.h +0 −1
src/ft2_audio.c+10−24
@@ -269,8 +269,7 @@ static void voiceUpdateVolumes(int32_t i, uint8_t status) · 268 unmodified lines
269269 // if destination volume and current volume is the same (and we have no sample trigger), don't do ramp
270270 if (fVolumeL == v->fVolumeL && fVolumeR == v->fVolumeR && !(status & IS_Trigger))
271271 {
272− // there is no volume change
273− v->volumeRampLength = 0;
272+ v->volumeRampLength = 0; // there is no volume change
274273 }
275274 else
276275 {
@@ -982,41 +981,28 @@ static void SDLCALL audioCallback(void *userdata, Uint8 *stream, int len) · 705 unmodified lines
982981
983982 static bool setupAudioBuffers(void)
984983 {
985− const uint32_t sampleSize = sizeof (float);
986−
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);
984+ audio.fMixBufferL = (float *)calloc(MAX_WAV_RENDER_SAMPLES_PER_TICK, sizeof (float));
985+ audio.fMixBufferR = (float *)calloc(MAX_WAV_RENDER_SAMPLES_PER_TICK, sizeof (float));
989986
990− if (audio.fMixBufferLUnaligned == NULL || audio.fMixBufferRUnaligned == NULL)
987+ if (audio.fMixBufferL == NULL || audio.fMixBufferR == NULL)
991988 return false;
992989
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−
1001990 return true;
1002991 }
1003992
1004993 static void freeAudioBuffers(void)
1005994 {
1006− if (audio.fMixBufferLUnaligned != NULL)
995+ if (audio.fMixBufferL != NULL)
1007996 {
1008− free(audio.fMixBufferLUnaligned);
1009− audio.fMixBufferLUnaligned = NULL;
997+ free(audio.fMixBufferL);
998+ audio.fMixBufferL = NULL;
1010999 }
10111000
1012− if (audio.fMixBufferRUnaligned != NULL)
1001+ if (audio.fMixBufferR != NULL)
10131002 {
1014− free(audio.fMixBufferRUnaligned);
1015− audio.fMixBufferRUnaligned = NULL;
1003+ free(audio.fMixBufferR);
1004+ audio.fMixBufferR = NULL;
10161005 }
1017−
1018− audio.fMixBufferL = NULL;
1019− audio.fMixBufferR = NULL;
10201006 }
10211007
10221008 void updateSendAudSamplesRoutine(bool lockMixer)
src/ft2_audio.h+1−1
@@ -40,7 +40,7 @@ typedef struct audio_t · 39 unmodified lines
4040 uint32_t freq, audLatencyPerfValInt, audLatencyPerfValFrac, samplesPerTick, samplesPerTickFrac, musicTimeSpeedVal;
4141 uint64_t tickTime64, tickTime64Frac;
4242 float fRampQuickVolMul, fRampTickMul, fRampTickMulTab[(MAX_BPM-MIN_BPM)+1];
43− float *fMixBufferL, *fMixBufferR, *fMixBufferLUnaligned, *fMixBufferRUnaligned;
43+ float *fMixBufferL, *fMixBufferR;
4444 double dHz2MixDeltaMul, dAudioLatencyMs;
4545
4646 SDL_AudioDeviceID dev;
src/ft2_header.h+0−3
@@ -69,9 +69,6 @@ · 68 unmodified lines
6969 // fast 32-bit -> 16-bit clamp
7070 #define CLAMP16(i) if ((int16_t)(i) != i) i = 0x7FFF ^ (i >> 31)
7171
72−#define ALIGN_PTR(p, x) (((uintptr_t)(p) + ((x)-1)) & ~((x)-1))
73−#define MALLOC_PAD(size, pad) (malloc((size) + (pad)))
74−
7572 #define SWAP16(x) \
7673 ( \
7774 (((uint16_t)((x) & 0x00FF)) << 8) | \
src/ft2_video.c+5−10
@@ -795,13 +795,11 @@ void closeVideo(void) · 794 unmodified lines
795795 video.window = NULL;
796796 }
797797
798− if (video.frameBufferUnaligned != NULL)
798+ if (video.frameBuffer != NULL)
799799 {
800− free(video.frameBufferUnaligned);
801− video.frameBufferUnaligned = NULL;
800+ free(video.frameBuffer);
801+ video.frameBuffer = NULL;
802802 }
803−
804− video.frameBuffer = NULL;
805803 }
806804
807805 void setWindowSizeFromConfig(bool updateRenderer)
@@ -1030,16 +1028,13 @@ bool setupRenderer(void) · 222 unmodified lines
10301028 }
10311029
10321030 // framebuffer used by SDL (for texture)
1033− video.frameBufferUnaligned = (uint32_t *)MALLOC_PAD(SCREEN_W * SCREEN_H * sizeof (int32_t), 256);
1034− if (video.frameBufferUnaligned == NULL)
1031+ video.frameBuffer = (uint32_t *)malloc(SCREEN_W * SCREEN_H * sizeof (int32_t));
1032+ if (video.frameBuffer == NULL)
10351033 {
10361034 showErrorMsgBox("Not enough memory!");
10371035 return false;
10381036 }
10391037
1040− // we want an aligned pointer
1041− video.frameBuffer = (uint32_t *)ALIGN_PTR(video.frameBufferUnaligned, 256);
1042−
10431038 if (!setupSprites())
10441039 return false;
10451040
src/ft2_video.h+0−1
@@ -32,7 +32,6 @@ typedef struct video_t · 31 unmodified lines
3232 uint8_t upscaleFactor;
3333 bool vsync60HzPresent, windowHidden;
3434 int32_t renderX, renderY, renderW, renderH, displayW, displayH, windowW, windowH;
35− uint32_t *frameBufferUnaligned;
3635 SDL_Renderer *renderer;
3736 SDL_Texture *texture;
3837 SDL_Surface *iconSurface;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t