Added the ability to set sound to use STEREO16 format instead of STEREO_FLOAT32 (defaults to STEREO_FLOAT32);

Moved network-related files to their own subdirectory.
This commit is contained in:
OBattler
2017-06-14 07:21:01 +02:00
parent 13f769ec09
commit 62dea57270
64 changed files with 255 additions and 193 deletions

View File

@@ -73,10 +73,15 @@ void inital(ALvoid)
{
#ifdef USE_OPENAL
int c;
float buf[BUFLEN*2];
float cd_buf[CD_BUFLEN*2];
int16_t buf_int16[BUFLEN*2];
int16_t cd_buf_int16[CD_BUFLEN*2];
alGenBuffers(4, buffers);
alGenBuffers(4, buffers_cd);
@@ -98,8 +103,16 @@ void inital(ALvoid)
for (c = 0; c < 4; c++)
{
alBufferData(buffers[c], AL_FORMAT_STEREO_FLOAT32, buf, BUFLEN*2*sizeof(float), FREQ);
alBufferData(buffers_cd[c], AL_FORMAT_STEREO_FLOAT32, cd_buf, CD_BUFLEN*2*sizeof(float), CD_FREQ);
if (sound_is_float)
{
alBufferData(buffers[c], AL_FORMAT_STEREO_FLOAT32, buf, BUFLEN*2*sizeof(float), FREQ);
alBufferData(buffers_cd[c], AL_FORMAT_STEREO_FLOAT32, cd_buf, CD_BUFLEN*2*sizeof(float), CD_FREQ);
}
else
{
alBufferData(buffers[c], AL_FORMAT_STEREO16, buf_int16, BUFLEN*2*sizeof(int16_t), FREQ);
alBufferData(buffers_cd[c], AL_FORMAT_STEREO16, cd_buf_int16, CD_BUFLEN*2*sizeof(int16_t), CD_FREQ);
}
}
alSourceQueueBuffers(source[0], 4, buffers);
@@ -135,6 +148,32 @@ void givealbuffer(float *buf)
#endif
}
void givealbuffer_int16(int16_t *buf)
{
#ifdef USE_OPENAL
int processed;
int state;
ALuint buffer;
alGetSourcei(source[0], AL_SOURCE_STATE, &state);
if (state==0x1014)
{
alSourcePlay(source[0]);
}
alGetSourcei(source[0], AL_BUFFERS_PROCESSED, &processed);
if (processed>=1)
{
alSourceUnqueueBuffers(source[0], 1, &buffer);
alBufferData(buffer, AL_FORMAT_STEREO16, buf, BUFLEN*2*sizeof(int16_t), FREQ);
alSourceQueueBuffers(source[0], 1, &buffer);
}
#endif
}
void givealbuffer_cd(float *buf)
{
#ifdef USE_OPENAL
@@ -161,3 +200,30 @@ void givealbuffer_cd(float *buf)
}
#endif
}
void givealbuffer_cd_int16(int16_t *buf)
{
#ifdef USE_OPENAL
int processed;
int state;
alGetSourcei(source[1], AL_SOURCE_STATE, &state);
if (state==0x1014)
{
alSourcePlay(source[1]);
}
alGetSourcei(source[1], AL_BUFFERS_PROCESSED, &processed);
if (processed>=1)
{
ALuint buffer;
alSourceUnqueueBuffers(source[1], 1, &buffer);
alBufferData(buffer, AL_FORMAT_STEREO16, buf, CD_BUFLEN*2*sizeof(int16_t), CD_FREQ);
alSourceQueueBuffers(source[1], 1, &buffer);
}
#endif
}

View File

@@ -8,7 +8,7 @@
*
* Sound emulation core.
*
* Version: @(#)sound.c 1.0.1 2017/06/04
* Version: @(#)sound.c 1.0.2 2017/06/14
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
@@ -136,11 +136,14 @@ int soundon = 1;
static int16_t cd_buffer[CDROM_NUM][CD_BUFLEN * 2];
static float cd_out_buffer[CD_BUFLEN * 2];
static int16_t cd_out_buffer_int16[CD_BUFLEN * 2];
static thread_t *sound_cd_thread_h;
static event_t *sound_cd_event;
static unsigned int cd_vol_l, cd_vol_r;
static int cd_buf_update = CD_BUFLEN / SOUNDBUFLEN;
int sound_is_float = 1;
void sound_set_cd_volume(unsigned int vol_l, unsigned int vol_r)
{
cd_vol_l = vol_l;
@@ -151,10 +154,13 @@ static void sound_cd_thread(void *param)
{
int i = 0;
float cd_buffer_temp[2] = {0.0, 0.0};
float cd_buffer_temp2[2] = {0.0, 0.0};
int c, has_audio;
while (1)
{
int c, has_audio;
thread_wait_event(sound_cd_event, -1);
if (!soundon)
{
@@ -162,8 +168,16 @@ static void sound_cd_thread(void *param)
}
for (c = 0; c < CD_BUFLEN*2; c += 2)
{
cd_out_buffer[c] = 0.0;
cd_out_buffer[c+1] = 0.0;
if (sound_is_float)
{
cd_out_buffer[c] = 0.0;
cd_out_buffer[c+1] = 0.0;
}
else
{
cd_out_buffer_int16[c] = 0;
cd_out_buffer_int16[c+1] = 0;
}
}
for (i = 0; i < CDROM_NUM; i++)
{
@@ -184,9 +198,6 @@ static void sound_cd_thread(void *param)
for (c = 0; c < CD_BUFLEN*2; c += 2)
{
float cd_buffer_temp[2] = {0.0, 0.0};
float cd_buffer_temp2[2] = {0.0, 0.0};
/* First, transfer the CD audio data to the temporary buffer. */
cd_buffer_temp[0] = (float) cd_buffer[i][c];
cd_buffer_temp[1] = (float) cd_buffer[i][c+1];
@@ -223,20 +234,71 @@ static void sound_cd_thread(void *param)
cd_buffer_temp2[1] *= (float) cd_vol_r;
cd_buffer_temp2[1] /= 65535.0;
cd_out_buffer[c] += (cd_buffer_temp2[0] / 32768.0);
cd_out_buffer[c+1] += (cd_buffer_temp2[1] / 32768.0);
if (sound_is_float)
{
cd_out_buffer[c] += (cd_buffer_temp2[0] / 32768.0);
cd_out_buffer[c+1] += (cd_buffer_temp2[1] / 32768.0);
}
else
{
if (cd_buffer_temp2[0] > 32767)
cd_buffer_temp2[0] = 32767;
if (cd_buffer_temp2[0] < -32768)
cd_buffer_temp2[0] = -32768;
if (cd_buffer_temp2[1] > 32767)
cd_buffer_temp2[1] = 32767;
if (cd_buffer_temp2[1] < -32768)
cd_buffer_temp2[1] = -32768;
cd_out_buffer_int16[c] += cd_buffer_temp2[0];
cd_out_buffer_int16[c+1] += cd_buffer_temp2[1];
}
}
}
}
givealbuffer_cd(cd_out_buffer);
if (sound_is_float)
{
givealbuffer_cd(cd_out_buffer);
}
else
{
givealbuffer_cd_int16(cd_out_buffer_int16);
}
}
}
static int32_t *outbuffer;
static float *outbuffer_ex;
static int16_t *outbuffer_ex_int16;
static int cd_thread_enable = 0;
void sound_realloc_buffers(void)
{
closeal();
initalmain(0,NULL);
inital();
if (outbuffer_ex != NULL)
{
free(outbuffer_ex);
}
if (outbuffer_ex_int16 != NULL)
{
free(outbuffer_ex_int16);
}
if (sound_is_float)
{
outbuffer_ex = malloc(SOUNDBUFLEN * 2 * sizeof(float));
}
else
{
outbuffer_ex_int16 = malloc(SOUNDBUFLEN * 2 * sizeof(int16_t));
}
}
void sound_init(void)
{
int i = 0;
@@ -245,8 +307,12 @@ void sound_init(void)
initalmain(0,NULL);
inital();
outbuffer_ex = NULL;
outbuffer_ex_int16 = NULL;
outbuffer = malloc(SOUNDBUFLEN * 2 * sizeof(int32_t));
outbuffer_ex = malloc(SOUNDBUFLEN * 2 * sizeof(float));
sound_realloc_buffers();
for (i = 0; i < CDROM_NUM; i++)
{
@@ -289,10 +355,32 @@ void sound_poll(void *priv)
for (c = 0; c < SOUNDBUFLEN * 2; c++)
{
outbuffer_ex[c] = ((float) outbuffer[c]) / 32768.0;
if (sound_is_float)
{
outbuffer_ex[c] = ((float) outbuffer[c]) / 32768.0;
}
else
{
if (outbuffer[c] > 32767)
outbuffer[c] = 32767;
if (outbuffer[c] < -32768)
outbuffer[c] = -32768;
outbuffer_ex_int16[c] = outbuffer[c];
}
}
if (soundon) givealbuffer(outbuffer_ex);
if (soundon)
{
if (sound_is_float)
{
givealbuffer(outbuffer_ex);
}
else
{
givealbuffer_int16(outbuffer_ex_int16);
}
}
if (cd_thread_enable)
{

View File

@@ -8,7 +8,7 @@
*
* Sound emulation core.
*
* Version: @(#)sound.h 1.0.0 2017/05/30
* Version: @(#)sound.h 1.0.1 2017/06/14
*
* Author: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
@@ -35,12 +35,18 @@ void sound_set_cd_volume(unsigned int vol_l, unsigned int vol_r);
extern int sound_pos_global;
void sound_speed_changed();
extern int sound_is_float;
void sound_realloc_buffers(void);
void sound_init();
void sound_reset();
void sound_cd_thread_reset();
void closeal(ALvoid);
void initalmain(int argc, char *argv[]);
void inital();
void givealbuffer(float *buf);
void givealbuffer_int16(int16_t *buf);
void givealbuffer_cd(float *buf);
void givealbuffer_cd_int16(int16_t *buf);