Skip to content

Commit

Permalink
fix: rzumer/sdl2_fix_audio and warning
Browse files Browse the repository at this point in the history
  • Loading branch information
iss committed Jan 29, 2019
1 parent 008c455 commit 992746e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion 6551_modem.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ static int socket_accept(int sock, int* sck)
#endif
socklen_t cli_addr_len = sizeof(cli_addr);

*sck = accept(sock, (struct sockaddr*) &cli_addr, (long*) &cli_addr_len);
*sck = accept(sock, (struct sockaddr*) &cli_addr, (socklen_t*) &cli_addr_len);
if(*sck == -1)
return 0;
else
Expand Down
22 changes: 7 additions & 15 deletions 8912.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@
SDL_AudioSpec obtained;
Uint32 cyclespersample;

#if SDL_MAJOR_VERSION == 1
#else
static SDL_AudioCVT cvt;
#endif

static Sint16 audiocapbuf[AUDIO_BUFLEN];
extern struct avi_handle *vidcap;

Expand Down Expand Up @@ -366,6 +362,7 @@ void ay_callback( void *dummy, Sint8 *stream, int length )
struct ay8912 *ay = (struct ay8912 *)dummy;
Sint32 dcadjustave, dcadjustmax;
SDL_bool tapenoise;
int actual_length;

logc = 0;
tlogc = 0;
Expand All @@ -376,12 +373,13 @@ void ay_callback( void *dummy, Sint8 *stream, int length )
if( !tapenoise ) ay->tapeout = 0;

out = (Uint16 *)stream;
#if SDL_MAJOR_VERSION == 1
#else
cvt.buf = (Uint8 *)stream;
#endif

for( i=0,j=0; i<AUDIO_BUFLEN && i<length/(2*sizeof(Uint16)); i++ )
actual_length = length/(2*sizeof(Uint16));
actual_length = (actual_length < AUDIO_BUFLEN)? actual_length : AUDIO_BUFLEN;
actual_length = (actual_length < obtained.samples)? actual_length : obtained.samples;

for( i=0,j=0; i<actual_length; i++ )
{
ay->ccyc = ay->ccycle>>FPBITS;

Expand Down Expand Up @@ -418,7 +416,7 @@ void ay_callback( void *dummy, Sint8 *stream, int length )

if( dcadjustave )
{
for( i=0, j=0; i<AUDIO_BUFLEN && i<length/(2*sizeof(Uint16)); i++ )
for( i=0, j=0; i<actual_length; i++ )
{
out[j++] -= dcadjustave;
out[j++] -= dcadjustave;
Expand Down Expand Up @@ -457,10 +455,7 @@ void ay_callback( void *dummy, Sint8 *stream, int length )
ay->tapeout = ay->tapelog[tlogc++].val * 8192;
}

#if SDL_MAJOR_VERSION == 1
#else
SDL_ConvertAudio(&cvt);
#endif

ay->ccycle -= (ay->lastcyc<<FPBITS);
ay->lastcyc = 0;
Expand Down Expand Up @@ -650,13 +645,10 @@ SDL_bool ay_init( struct ay8912 *ay, struct machine *oric )
if( soundavailable )
SDL_PauseAudio( 0 );

#if SDL_MAJOR_VERSION == 1
#else
// initialize audio conversion system for SDL2
SDL_BuildAudioCVT(&cvt, AUDIO_S16SYS, 2, AUDIO_FREQ, obtained.format, obtained.channels, obtained.freq);
cvt.len = obtained.samples * sizeof(Sint16) * obtained.channels;
// Do not allocate a buffer, write directly into the callback stream
#endif

return SDL_TRUE;
}
Expand Down

1 comment on commit 992746e

@iss000
Copy link
Collaborator

@iss000 iss000 commented on 992746e Jan 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'SDL_AudioCVT cvt' works fine by me for SDL 1.2 and 2.0, so I left it for both.
Thanks @rzumer.

Please sign in to comment.