Skip to content

Commit

Permalink
replace all SEEK_??? macros with RW_SEEK_???
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Mar 20, 2021
1 parent eb444ec commit 187ba0f
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 37 deletions.
10 changes: 4 additions & 6 deletions src/SDL_sound.c
Expand Up @@ -352,8 +352,7 @@ static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired,
#if (defined DEBUG_CHATTER)
static SDL_INLINE const char *fmt_to_str(Uint16 fmt)
{
switch(fmt)
{
switch(fmt) {
case AUDIO_U8:
return "U8";
case AUDIO_S8:
Expand All @@ -375,7 +374,6 @@ static SDL_INLINE const char *fmt_to_str(Uint16 fmt)
case AUDIO_F32MSB:
return "F32MSB";
} /* switch */

return "Unknown";
} /* fmt_to_str */
#endif
Expand All @@ -400,7 +398,7 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
internal->funcs = funcs;
if (!funcs->open(sample, ext))
{
SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
SDL_RWseek(internal->rw, pos, RW_SEEK_SET); /* set for next try... */
return 0;
} /* if */

Expand All @@ -427,7 +425,7 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
{
__Sound_SetError(SDL_GetError());
funcs->close(sample);
SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
SDL_RWseek(internal->rw, pos, RW_SEEK_SET); /* set for next try... */
return 0;
} /* if */

Expand All @@ -437,7 +435,7 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
if (rc == NULL)
{
funcs->close(sample);
SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
SDL_RWseek(internal->rw, pos, RW_SEEK_SET); /* set for next try... */
return 0;
} /* if */

Expand Down
10 changes: 5 additions & 5 deletions src/SDL_sound_aiff.c
Expand Up @@ -245,7 +245,7 @@ static int read_ssnd_chunk(SDL_RWops *rw, ssnd_t *ssnd)
ssnd->blockSize = SDL_SwapBE32(ssnd->blockSize);

/* Leave the SDL_RWops position indicator at the start of the samples */
if (SDL_RWseek(rw, (int) ssnd->offset, SEEK_CUR) == -1)
if (SDL_RWseek(rw, (int) ssnd->offset, RW_SEEK_CUR) == -1)
return 0;

return 1;
Expand Down Expand Up @@ -304,7 +304,7 @@ static int seek_sample_fmt_normal(Sound_Sample *sample, Uint32 ms)
fmt_t *fmt = &a->fmt;
int offset = __Sound_convertMsToBytePos(&sample->actual, ms);
int pos = (int) (fmt->data_starting_offset + offset);
int rc = SDL_RWseek(internal->rw, pos, SEEK_SET);
int rc = SDL_RWseek(internal->rw, pos, RW_SEEK_SET);
BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0);
a->bytesLeft = fmt->total_bytes - offset;
return 1; /* success. */
Expand Down Expand Up @@ -360,7 +360,7 @@ static int find_chunk(SDL_RWops *rw, Uint32 id)
BAIL_IF_MACRO(SDL_RWread(rw, &siz, sizeof (siz), 1) != 1, NULL, 0);
siz = SDL_SwapBE32(siz);
SDL_assert(siz > 0);
BAIL_IF_MACRO(SDL_RWseek(rw, siz, SEEK_CUR) == -1, NULL, 0);
BAIL_IF_MACRO(SDL_RWseek(rw, siz, RW_SEEK_CUR) == -1, NULL, 0);
} /* while */

return 0; /* shouldn't hit this, but just in case... */
Expand Down Expand Up @@ -450,7 +450,7 @@ static int AIFF_open(Sound_Sample *sample, const char *ext)
return 0;
} /* if */

SDL_RWseek(rw, pos, SEEK_SET); /* if the seek fails, let it go... */
SDL_RWseek(rw, pos, RW_SEEK_SET); /* if the seek fails, let it go... */

if (!find_chunk(rw, ssndID))
{
Expand Down Expand Up @@ -497,7 +497,7 @@ static int AIFF_rewind(Sound_Sample *sample)
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
aiff_t *a = (aiff_t *) internal->decoder_private;
fmt_t *fmt = &a->fmt;
int rc = SDL_RWseek(internal->rw, fmt->data_starting_offset, SEEK_SET);
int rc = SDL_RWseek(internal->rw, fmt->data_starting_offset, RW_SEEK_SET);
BAIL_IF_MACRO(rc != fmt->data_starting_offset, ERR_IO_ERROR, 0);
a->bytesLeft = fmt->total_bytes;
return fmt->rewind_sample(sample);
Expand Down
8 changes: 4 additions & 4 deletions src/SDL_sound_au.c
Expand Up @@ -173,9 +173,9 @@ static int AU_open(Sound_Sample *sample, const char *ext)

SNDDBG(("AU: Invalid header, assuming raw 8kHz µ-law.\n"));
/* if seeking fails, we lose 24 samples. big deal */
SDL_RWseek(rw, -HDR_SIZE, SEEK_CUR);
SDL_RWseek(rw, -HDR_SIZE, RW_SEEK_CUR);
dec->encoding = AU_ENC_ULAW_8;
dec->remaining = (Uint32)-1; /* no limit */
dec->remaining = (Uint32)-1; /* no limit */
sample->actual.format = AUDIO_S16SYS;
sample->actual.rate = 8000;
sample->actual.channels = 1;
Expand Down Expand Up @@ -297,7 +297,7 @@ static int AU_rewind(Sound_Sample *sample)
{
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
struct audec *dec = (struct audec *) internal->decoder_private;
int rc = SDL_RWseek(internal->rw, dec->start_offset, SEEK_SET);
int rc = SDL_RWseek(internal->rw, dec->start_offset, RW_SEEK_SET);
BAIL_IF_MACRO(rc != dec->start_offset, ERR_IO_ERROR, 0);
dec->remaining = dec->total;
return 1;
Expand All @@ -316,7 +316,7 @@ static int AU_seek(Sound_Sample *sample, Uint32 ms)
offset >>= 1; /* halve the byte offset for compression. */

pos = (int) (dec->start_offset + offset);
rc = SDL_RWseek(internal->rw, pos, SEEK_SET);
rc = SDL_RWseek(internal->rw, pos, RW_SEEK_SET);
BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0);
dec->remaining = dec->total - offset;
return 1;
Expand Down
6 changes: 3 additions & 3 deletions src/SDL_sound_coreaudio.c
Expand Up @@ -194,8 +194,8 @@ SInt64 CoreAudio_SizeCallback(void* inClientData)
{
SDL_RWops* rw_ops = (SDL_RWops*)inClientData;
SInt64 current_position = SDL_RWtell(rw_ops);
SInt64 end_position = SDL_RWseek(rw_ops, 0, SEEK_END);
SDL_RWseek(rw_ops, current_position, SEEK_SET);
SInt64 end_position = SDL_RWseek(rw_ops, 0, RW_SEEK_END);
SDL_RWseek(rw_ops, current_position, RW_SEEK_SET);
// fprintf(stderr, "CoreAudio_SizeCallback:%d\n", end_position);

return end_position;
Expand All @@ -210,7 +210,7 @@ OSStatus CoreAudio_ReadCallback(
)
{
SDL_RWops* rw_ops = (SDL_RWops*)inClientData;
SDL_RWseek(rw_ops, inPosition, SEEK_SET);
SDL_RWseek(rw_ops, inPosition, RW_SEEK_SET);
size_t bytes_actually_read = SDL_RWread(rw_ops, data_buffer, 1, requestCount);
// Not sure how to test for a read error with SDL_RWops
// fprintf(stderr, "CoreAudio_ReadCallback:%d, %d\n", requestCount, bytes_actually_read);
Expand Down
8 changes: 4 additions & 4 deletions src/SDL_sound_raw.c
Expand Up @@ -72,10 +72,10 @@ static int RAW_open(Sound_Sample *sample, const char *ext)
SDL_memcpy(&sample->actual, &sample->desired, sizeof (Sound_AudioInfo));
sample->flags = SOUND_SAMPLEFLAG_CANSEEK;

if ( (pos = SDL_RWseek(internal->rw, 0, SEEK_END) ) <= 0) {
if ((pos = SDL_RWseek(internal->rw, 0, RW_SEEK_END) ) <= 0) {
BAIL_MACRO("RAW: cannot seek the end of the file \"RAW\".", 0);
}
if ( SDL_RWseek(internal->rw, 0, SEEK_SET) ) {
if ( SDL_RWseek(internal->rw, 0, RW_SEEK_SET) ) {
BAIL_MACRO("RAW: cannot reset file \"RAW\".", 0);
}

Expand Down Expand Up @@ -124,7 +124,7 @@ static Uint32 RAW_read(Sound_Sample *sample)
static int RAW_rewind(Sound_Sample *sample)
{
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, SEEK_SET) != 0, ERR_IO_ERROR, 0);
BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, RW_SEEK_SET) != 0, ERR_IO_ERROR, 0);
return 1;
} /* RAW_rewind */

Expand All @@ -133,7 +133,7 @@ static int RAW_seek(Sound_Sample *sample, Uint32 ms)
{
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
int pos = (int) __Sound_convertMsToBytePos(&sample->actual, ms);
int err = (SDL_RWseek(internal->rw, pos, SEEK_SET) != pos);
int err = (SDL_RWseek(internal->rw, pos, RW_SEEK_SET) != pos);
BAIL_IF_MACRO(err, ERR_IO_ERROR, 0);
return 1;
} /* RAW_seek */
Expand Down
4 changes: 2 additions & 2 deletions src/SDL_sound_shn.c
Expand Up @@ -1259,7 +1259,7 @@ static int SHN_rewind(Sound_Sample *sample)

#if 0
shn_t *shn = (shn_t *) internal->decoder_private;
int rc = SDL_RWseek(internal->rw, shn->start_pos, SEEK_SET);
int rc = SDL_RWseek(internal->rw, shn->start_pos, RW_SEEK_SET);
BAIL_IF_MACRO(rc != shn->start_pos, ERR_IO_ERROR, 0);
/* !!! FIXME: set state. */
return 1;
Expand All @@ -1270,7 +1270,7 @@ static int SHN_rewind(Sound_Sample *sample)
* !!! FIXME: to decode. The below kludge adds unneeded overhead and
* !!! FIXME: risk of failure.
*/
BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, SEEK_SET) != 0, ERR_IO_ERROR, 0);
BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, RW_SEEK_SET) != 0, ERR_IO_ERROR, 0);
SHN_close(sample);
return SHN_open(sample, "SHN");
#endif
Expand Down
5 changes: 3 additions & 2 deletions src/SDL_sound_skeleton.c
Expand Up @@ -99,7 +99,7 @@ static int FMT_rewind(Sound_Sample *sample)
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;

/* seek to the appropriate place... */
BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, SEEK_SET) != 0, ERR_IO_ERROR, 0);
BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, RW_SEEK_SET) != 0, ERR_IO_ERROR, 0);

(reset state as necessary.)

Expand All @@ -112,13 +112,14 @@ static int FMT_seek(Sound_Sample *sample, Uint32 ms)
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;

/* seek to the appropriate place... */
BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, SEEK_SET) != 0, ERR_IO_ERROR, 0);
BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, RW_SEEK_SET) != 0, ERR_IO_ERROR, 0);

(set state as necessary.)

return 1; /* success. */
} /* FMT_seek */


static const char *extensions_fmt[] = { "FMT", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_FMT =
{
Expand Down
8 changes: 4 additions & 4 deletions src/SDL_sound_voc.c
Expand Up @@ -122,7 +122,7 @@ static SDL_INLINE int voc_check_header(SDL_RWops *src)

datablockofs = SDL_SwapLE16(datablockofs);

if (SDL_RWseek(src, datablockofs, SEEK_SET) != datablockofs)
if (SDL_RWseek(src, datablockofs, RW_SEEK_SET) != datablockofs)
{
BAIL_MACRO("VOC: Failed to seek to data block.", 0);
} /* if */
Expand Down Expand Up @@ -388,7 +388,7 @@ static int voc_read_waveform(Sound_Sample *sample, int fill_buf, Uint32 max)
cur = SDL_RWtell(src);
if (cur >= 0)
{
rc = SDL_RWseek(src, max, SEEK_CUR);
rc = SDL_RWseek(src, max, RW_SEEK_CUR);
if (rc >= 0)
done = rc - cur;
else
Expand Down Expand Up @@ -482,7 +482,7 @@ static int VOC_rewind(Sound_Sample *sample)
{
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
vs_t *v = (vs_t *) internal->decoder_private;
int rc = SDL_RWseek(internal->rw, v->start_pos, SEEK_SET);
int rc = SDL_RWseek(internal->rw, v->start_pos, RW_SEEK_SET);
BAIL_IF_MACRO(rc != v->start_pos, ERR_IO_ERROR, 0);
v->rest = 0;
return 1;
Expand Down Expand Up @@ -516,7 +516,7 @@ static int VOC_seek(Sound_Sample *sample, Uint32 ms)
Uint32 rc = voc_read_waveform(sample, 0, offset);
if ( (rc == 0) || (!voc_get_block(sample, v)) )
{
SDL_RWseek(internal->rw, origpos, SEEK_SET);
SDL_RWseek(internal->rw, origpos, RW_SEEK_SET);
v->rest = origrest;
return 0;
} /* if */
Expand Down
14 changes: 7 additions & 7 deletions src/SDL_sound_wav.c
Expand Up @@ -244,7 +244,7 @@ static int seek_sample_fmt_normal(Sound_Sample *sample, Uint32 ms)
fmt_t *fmt = w->fmt;
int offset = __Sound_convertMsToBytePos(&sample->actual, ms);
int pos = (int) (fmt->data_starting_offset + offset);
int rc = SDL_RWseek(internal->rw, pos, SEEK_SET);
int rc = SDL_RWseek(internal->rw, pos, RW_SEEK_SET);
BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0);
w->bytesLeft = fmt->total_bytes - offset;
return 1; /* success. */
Expand Down Expand Up @@ -495,15 +495,15 @@ static int seek_sample_fmt_adpcm(Sound_Sample *sample, Uint32 ms)
int bpb = (fmt->fmt.adpcm.wSamplesPerBlock * fmt->sample_frame_size);
int skipsize = (offset / bpb) * fmt->wBlockAlign;
int pos = skipsize + fmt->data_starting_offset;
int rc = SDL_RWseek(internal->rw, pos, SEEK_SET);
int rc = SDL_RWseek(internal->rw, pos, RW_SEEK_SET);
BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0);

/* The offset we need is in this block, so we need to decode to there. */
skipsize += (offset % bpb);
rc = (offset % bpb); /* bytes into this block we need to decode */
if (!read_adpcm_block_headers(sample))
{
SDL_RWseek(internal->rw, origpos, SEEK_SET); /* try to make sane. */
SDL_RWseek(internal->rw, origpos, RW_SEEK_SET); /* try to make sane. */
return 0;
} /* if */

Expand All @@ -514,7 +514,7 @@ static int seek_sample_fmt_adpcm(Sound_Sample *sample, Uint32 ms)
{
if (!decode_adpcm_sample_frame(sample))
{
SDL_RWseek(internal->rw, origpos, SEEK_SET);
SDL_RWseek(internal->rw, origpos, RW_SEEK_SET);
fmt->fmt.adpcm.samples_left_in_block = origsampsleft;
return 0;
} /* if */
Expand Down Expand Up @@ -630,7 +630,7 @@ static int find_chunk(SDL_RWops *rw, Uint32 id)
SDL_assert(siz >= 0);
pos += (sizeof (Uint32) * 2) + siz;
if (siz > 0)
BAIL_IF_MACRO(SDL_RWseek(rw, pos, SEEK_SET) != pos, NULL, 0);
BAIL_IF_MACRO(SDL_RWseek(rw, pos, RW_SEEK_SET) != pos, NULL, 0);
} /* while */

return 0; /* shouldn't hit this, but just in case... */
Expand Down Expand Up @@ -669,7 +669,7 @@ static int WAV_open_internal(Sound_Sample *sample, const char *ext, fmt_t *fmt)
} /* else */

BAIL_IF_MACRO(!read_fmt(rw, fmt), NULL, 0);
SDL_RWseek(rw, fmt->next_chunk_offset, SEEK_SET);
SDL_RWseek(rw, fmt->next_chunk_offset, RW_SEEK_SET);
BAIL_IF_MACRO(!find_chunk(rw, dataID), "WAV: No data chunk.", 0);
BAIL_IF_MACRO(!read_data_chunk(rw, &d), "WAV: Can't read data chunk.", 0);

Expand Down Expand Up @@ -740,7 +740,7 @@ static int WAV_rewind(Sound_Sample *sample)
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
wav_t *w = (wav_t *) internal->decoder_private;
fmt_t *fmt = w->fmt;
int rc = SDL_RWseek(internal->rw, fmt->data_starting_offset, SEEK_SET);
int rc = SDL_RWseek(internal->rw, fmt->data_starting_offset, RW_SEEK_SET);
BAIL_IF_MACRO(rc != fmt->data_starting_offset, ERR_IO_ERROR, 0);
w->bytesLeft = fmt->total_bytes;
return fmt->rewind_sample(sample);
Expand Down

0 comments on commit 187ba0f

Please sign in to comment.