Get rid of VLAs. (#199)

* Rename global variable, so it doesn't look like a macro.

* Replace macro with global variable.

* Get rid of VLA in adlibgold.

* Get rid of VLA in dbopl.

* Get rid of VLA in soundopenal.

* Get rid of VLA in voodoo banshee.

* Get rid of VLA in voodoo display.
This commit is contained in:
Marek Knápek
2023-02-06 23:02:24 +01:00
committed by GitHub
parent e1e3475bd4
commit a911e3644b
7 changed files with 88 additions and 39 deletions

View File

@@ -36,7 +36,7 @@ void sound_update_buf_length();
extern int sound_gain;
extern int SOUNDBUFLEN;
extern int sound_buf_len_al;
#define MAXSOUNDBUFLEN (48000 / 10)
#endif /* _SOUND_H_ */

View File

@@ -128,7 +128,7 @@ void sound_update_buf_length() {
if (new_buf_len > MAXSOUNDBUFLEN)
new_buf_len = MAXSOUNDBUFLEN;
SOUNDBUFLEN = new_buf_len;
sound_buf_len_al = new_buf_len;
}
void sound_set_cd_volume(unsigned int vol_l, unsigned int vol_r) {
@@ -221,16 +221,16 @@ void sound_poll(void *priv) {
}
sound_pos_global++;
if (sound_pos_global == SOUNDBUFLEN) {
if (sound_pos_global == sound_buf_len_al) {
int c;
/* int16_t buf16[SOUNDBUFLEN * 2 ];*/
/* int16_t buf16[sound_buf_len_al * 2 ];*/
memset(outbuffer, 0, SOUNDBUFLEN * 2 * sizeof(int32_t));
memset(outbuffer, 0, sound_buf_len_al * 2 * sizeof(int32_t));
for (c = 0; c < sound_handlers_num; c++)
sound_handlers[c].get_buffer(outbuffer, SOUNDBUFLEN, sound_handlers[c].priv);
sound_handlers[c].get_buffer(outbuffer, sound_buf_len_al, sound_handlers[c].priv);
/* for (c=0;c<SOUNDBUFLEN*2;c++)
/* for (c=0;c<sound_buf_len_al*2;c++)
{
if (outbuffer[c] < -32768)
buf16[c] = -32768;
@@ -241,7 +241,7 @@ void sound_poll(void *priv) {
}
if (!soundf) soundf=fopen("sound.pcm","wb");
fwrite(buf16,(SOUNDBUFLEN)*2*2,1,soundf);*/
fwrite(buf16,(sound_buf_len_al)*2*2,1,soundf);*/
if (soundon)
givealbuffer(outbuffer);

View File

@@ -1,3 +1,4 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "ibm.h"
@@ -629,10 +630,11 @@ void adgold_timer_poll(void *p) {
static void adgold_get_buffer(int32_t *buffer, int len, void *p) {
adgold_t *adgold = (adgold_t *)p;
int16_t adgold_buffer[len * 2];
int16_t adgold_buffer[MAXSOUNDBUFLEN * 2];
int c;
assert(len <= MAXSOUNDBUFLEN);
opl3_update2(&adgold->opl);
adgold_update(adgold);

View File

@@ -116,9 +116,8 @@ uint8_t opl_read(int nr, uint16_t addr) {
return opl[nr].is_opl3 ? 0 : 0xff;
}
void opl2_update(int nr, int16_t *buffer, int samples) {
static void opl2_update_impl(int nr, int16_t *buffer, Bit32s *buffer_32, int samples) {
int c;
Bit32s buffer_32[samples];
opl[nr].chip.GenerateBlock2(samples, buffer_32);
@@ -126,9 +125,26 @@ void opl2_update(int nr, int16_t *buffer, int samples) {
buffer[c * 2] = (int16_t)buffer_32[c];
}
void opl3_update(int nr, int16_t *buffer, int samples) {
void opl2_update(int nr, int16_t *buffer, int samples) {
#define chunk_size 1024
int n_chunks;
int rest;
int i_chunks;
Bit32s buffer_32[chunk_size];
n_chunks = samples / chunk_size;
rest = samples - n_chunks * chunk_size;
for(i_chunks = 0; i_chunks != n_chunks; ++i_chunks)
opl2_update_impl(nr, buffer + i_chunks * chunk_size * 2, buffer_32, chunk_size);
if(rest != 0)
opl2_update_impl(nr, buffer + n_chunks * chunk_size * 2, buffer_32, rest);
#undef chunk_size
}
static void opl3_update_impl(int nr, int16_t *buffer, Bit32s *buffer_32, int samples) {
int c;
Bit32s buffer_32[samples * 2];
if (opl[nr].opl_emu) {
OPL3_GenerateStream(&opl[nr].opl3chip, buffer, samples);
@@ -139,3 +155,21 @@ void opl3_update(int nr, int16_t *buffer, int samples) {
buffer[c] = (int16_t)buffer_32[c];
}
}
void opl3_update(int nr, int16_t *buffer, int samples) {
#define chunk_size 1024
int n_chunks;
int rest;
int i_chunk;
Bit32s buffer_32[chunk_size * 2];
n_chunks = samples / chunk_size;
rest = samples - n_chunks * chunk_size;
for(i_chunk = 0; i_chunk != n_chunks; ++i_chunk)
opl3_update_impl(nr, buffer + i_chunk * chunk_size * 2, buffer_32, chunk_size);
if(rest != 0)
opl3_update_impl(nr, buffer + n_chunks * chunk_size * 2, buffer_32, rest);
#undef chunk_size
}

View File

@@ -1,4 +1,5 @@
#define USE_OPENAL
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -23,9 +24,7 @@ static ALuint source[2]; // audio source
#endif
#define FREQ 48000
int SOUNDBUFLEN = 48000 / 20;
#define BUFLEN SOUNDBUFLEN
int sound_buf_len_al = 48000 / 20;
void closeal();
ALvoid alutInit(ALint *argc, ALbyte **argv) {
@@ -87,9 +86,11 @@ void check() {
void inital() {
#ifdef USE_OPENAL
int c;
int16_t buf[BUFLEN * 2];
int16_t buf[MAXSOUNDBUFLEN * 2];
int16_t cd_buf[CD_BUFLEN * 2];
assert(sound_buf_len_al <= MAXSOUNDBUFLEN);
// printf("1\n");
check();
@@ -117,12 +118,12 @@ void inital() {
alSourcei(source[1], AL_SOURCE_RELATIVE, AL_TRUE);
check();
memset(buf, 0, BUFLEN * 4);
memset(buf, 0, sound_buf_len_al * 4);
memset(cd_buf, 0, CD_BUFLEN * 4);
// printf("5\n");
for (c = 0; c < 4; c++) {
alBufferData(buffers[c], AL_FORMAT_STEREO16, buf, BUFLEN * 2 * 2, FREQ);
alBufferData(buffers[c], AL_FORMAT_STEREO16, buf, sound_buf_len_al * 2 * 2, FREQ);
alBufferData(buffers_cd[c], AL_FORMAT_STEREO16, cd_buf, CD_BUFLEN * 2 * 2, CD_FREQ);
}
@@ -141,10 +142,12 @@ void inital() {
void givealbuffer(int32_t *buf) {
#ifdef USE_OPENAL
int16_t buf16[BUFLEN * 2];
int16_t buf16[MAXSOUNDBUFLEN * 2];
int processed;
int state;
assert(sound_buf_len_al <= MAXSOUNDBUFLEN);
// return;
// printf("Start\n");
@@ -178,7 +181,7 @@ void givealbuffer(int32_t *buf) {
// printf("U ");
check();
for (c = 0; c < BUFLEN * 2; c++) {
for (c = 0; c < sound_buf_len_al * 2; c++) {
if (buf[c] < -32768)
buf16[c] = -32768;
else if (buf[c] > 32767)
@@ -186,8 +189,8 @@ void givealbuffer(int32_t *buf) {
else
buf16[c] = buf[c];
}
// for (c=0;c<BUFLEN*2;c++) buf[c]^=0x8000;
alBufferData(buffer, AL_FORMAT_STEREO16, buf16, BUFLEN * 2 * 2, FREQ);
// for (c=0;c<sound_buf_len_al*2;c++) buf[c]^=0x8000;
alBufferData(buffer, AL_FORMAT_STEREO16, buf16, sound_buf_len_al * 2 * 2, FREQ);
// printf("B ");
check();
@@ -198,7 +201,7 @@ void givealbuffer(int32_t *buf) {
// printf("\n");
// if (!allog) allog=fopen("al.pcm","wb");
// fwrite(buf,BUFLEN*2,1,allog);
// fwrite(buf,sound_buf_len_al*2,1,allog);
}
// printf("\n");
#endif
@@ -241,7 +244,7 @@ void givealbuffer_cd(int16_t *buf) {
// printf("U ");
check();
// for (c=0;c<BUFLEN*2;c++) buf[c]^=0x8000;
// for (c=0;c<sound_buf_len_al*2;c++) buf[c]^=0x8000;
alBufferData(buffer, AL_FORMAT_STEREO16, buf, CD_BUFLEN * 2 * 2, CD_FREQ);
// printf("B ");
check();
@@ -253,7 +256,7 @@ void givealbuffer_cd(int16_t *buf) {
// printf("\n");
// if (!allog) allog=fopen("al.pcm","wb");
// fwrite(buf,BUFLEN*2,1,allog);
// fwrite(buf,sound_buf_len_al*2,1,allog);
}
// printf("\n");
#endif

View File

@@ -1,3 +1,4 @@
#include <assert.h>
#include <stdlib.h>
#include "ibm.h"
#include "device.h"
@@ -2073,9 +2074,10 @@ static void banshee_overlay_draw(svga_t *svga, int displine) {
case VIDPROCCFG_FILTER_MODE_DITHER_4X4:
if (banshee->voodoo->scrfilter && banshee->voodoo->scrfilterEnabled) {
uint8_t fil[(svga->overlay_latch.xsize) * 3];
uint8_t fil3[(svga->overlay_latch.xsize) * 3];
uint8_t fil[64 * 3];
uint8_t fil3[64 * 3];
assert(svga->overlay_latch.xsize <= 64);
if (banshee->vidProcCfg & VIDPROCCFG_H_SCALE_ENABLE) /* leilei HACK - don't know of real 4x1
hscaled behavior yet, double for now */
{
@@ -2143,15 +2145,16 @@ static void banshee_overlay_draw(svga_t *svga, int displine) {
case VIDPROCCFG_FILTER_MODE_DITHER_2X2:
if (banshee->voodoo->scrfilter && banshee->voodoo->scrfilterEnabled) {
uint8_t fil[(svga->overlay_latch.xsize) * 3];
uint8_t soak[(svga->overlay_latch.xsize) * 3];
uint8_t soak2[(svga->overlay_latch.xsize) * 3];
uint8_t fil[64 * 3];
uint8_t soak[64 * 3];
uint8_t soak2[64 * 3];
uint8_t samp1[(svga->overlay_latch.xsize) * 3];
uint8_t samp2[(svga->overlay_latch.xsize) * 3];
uint8_t samp3[(svga->overlay_latch.xsize) * 3];
uint8_t samp4[(svga->overlay_latch.xsize) * 3];
uint8_t samp1[64 * 3];
uint8_t samp2[64 * 3];
uint8_t samp3[64 * 3];
uint8_t samp4[64 * 3];
assert(svga->overlay_latch.xsize <= 64);
src = &svga->vram[src_addr2 & svga->vram_mask];
OVERLAY_SAMPLE(banshee->overlay_buffer[1]);
for (x = 0; x < svga->overlay_latch.xsize; x++) {

View File

@@ -1,3 +1,4 @@
#include <assert.h>
#include "ibm.h"
#include "device.h"
#include "mem.h"
@@ -317,7 +318,9 @@ static void voodoo_filterline_v1(voodoo_t *voodoo, uint8_t *fil, int column, uin
int x;
// Scratchpad for avoiding feedback streaks
uint8_t fil3[(voodoo->h_disp) * 3];
uint8_t fil3[4096 * 3];
assert(voodoo->h_disp <= 4096);
/* 16 to 32-bit */
for (x = 0; x < column; x++) {
@@ -372,7 +375,9 @@ static void voodoo_filterline_v2(voodoo_t *voodoo, uint8_t *fil, int column, uin
int x;
// Scratchpad for blending filter
uint8_t fil3[(voodoo->h_disp) * 3];
uint8_t fil3[4096 * 3];
assert(voodoo->h_disp <= 4096);
/* 16 to 32-bit */
for (x = 0; x < column; x++) {
@@ -469,7 +474,9 @@ void voodoo_callback(void *p) {
voodoo->dirty_line_high = voodoo->line;
if (voodoo->scrfilter && voodoo->scrfilterEnabled) {
uint8_t fil[(voodoo->h_disp) * 3]; /* interleaved 24-bit RGB */
uint8_t fil[4096 * 3]; /* interleaved 24-bit RGB */
assert(voodoo->h_disp <= 4096);
if (voodoo->type == VOODOO_2)
voodoo_filterline_v2(voodoo, fil, voodoo->h_disp, src, voodoo->line);