diff decoders/voc.c @ 387:fb519e6028e3

Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_MACRO)
author Ryan C. Gordon <icculus@icculus.org>
date Fri, 05 Jul 2002 23:11:51 +0000
parents 9efb760c4a6b
children c42ac9ee2ce4
line wrap: on
line diff
--- a/decoders/voc.c	Fri Jul 05 22:34:55 2002 +0000
+++ b/decoders/voc.c	Fri Jul 05 23:11:51 2002 +0000
@@ -146,9 +146,8 @@
 {
     if (SDL_RWread(src, p, size, 1) != 1)
     {
-        Sound_SetError("VOC: i/o error");
         v->error = 1;
-        return 0;
+        BAIL_MACRO("VOC: i/o error", 0);
     } /* if */
 
     return(1);
@@ -167,8 +166,7 @@
 
     if (memcmp(signature, "Creative Voice File\032", sizeof (signature)) != 0)
     {
-        Sound_SetError("VOC: Wrong signature; not a VOC file.");
-        return(0);
+        BAIL_MACRO("VOC: Wrong signature; not a VOC file.", 0);
     } /* if */
 
         /* get the offset where the first datablock is located */
@@ -179,8 +177,7 @@
 
     if (SDL_RWseek(src, datablockofs, SEEK_SET) != datablockofs)
     {
-        Sound_SetError("VOC: Failed to seek to data block.");
-        return(0);
+        BAIL_MACRO("VOC: Failed to seek to data block.", 0);
     } /* if */
 
     return(1);  /* success! */
@@ -227,17 +224,10 @@
                 /* block, the DATA blocks rate value is invalid */
                 if (!v->extended)
                 {
-                    if (uc == 0)
-                    {
-                        Sound_SetError("VOC Sample rate is zero?");
-                        return 0;
-                    } /* if */
+                    BAIL_IF_MACRO(uc == 0, "VOC: Sample rate is zero?", 0);
 
                     if ((v->rate != -1) && (uc != v->rate))
-                    {
-                        Sound_SetError("VOC sample rate codes differ");
-                        return 0;
-                    } /* if */
+                        BAIL_MACRO("VOC sample rate codes differ", 0);
 
                     v->rate = uc;
                     sample->actual.rate = 1000000.0/(256 - v->rate);
@@ -245,13 +235,9 @@
                 } /* if */
 
                 if (!voc_readbytes(src, v, &uc, sizeof (uc)))
-                    return 0;
+                    return(0);
 
-                if (uc != 0)
-                {
-                    Sound_SetError("VOC decoder only interprets 8-bit data");
-                    return 0;
-                } /* if */
+                BAIL_IF_MACRO(uc != 0, "VOC: only supports 8-bit data", 0);
 
                 v->extended = 0;
                 v->rest = sblen - 2;
@@ -263,16 +249,11 @@
                     return 0;
 
                 new_rate_long = SDL_SwapLE32(new_rate_long);
-                if (new_rate_long == 0)
-                {
-                    Sound_SetError("VOC Sample rate is zero?");
-                    return 0;
-                } /* if */
+                BAIL_IF_MACRO(!new_rate_long, "VOC: Sample rate is zero?", 0);
+
                 if ((v->rate != -1) && (new_rate_long != v->rate))
-                {
-                    Sound_SetError("VOC sample rate codes differ");
-                    return 0;
-                } /* if */
+                    BAIL_MACRO("VOC: sample rate codes differ", 0);
+
                 v->rate = new_rate_long;
                 sample->actual.rate = new_rate_long;
 
@@ -284,8 +265,7 @@
                     case 8:  v->size = ST_SIZE_BYTE; break;
                     case 16: v->size = ST_SIZE_WORD; break;
                     default:
-                        Sound_SetError("VOC with unknown data size");
-                        return 0;
+                        BAIL_MACRO("VOC: unknown data size", 0);
                 } /* switch */
 
                 if (!voc_readbytes(src, v, &v->channels, sizeof (Uint8)))
@@ -310,11 +290,7 @@
                 if (!voc_readbytes(src, v, &uc, sizeof (uc)))
                     return 0;
 
-                if (uc == 0)
-                {
-                    Sound_SetError("VOC silence sample rate is zero");
-                    return 0;
-                } /* if */
+                BAIL_IF_MACRO(uc == 0, "VOC: silence sample rate is zero", 0);
 
                 /*
                  * Some silence-packed files have gratuitously
@@ -333,7 +309,7 @@
             case VOC_LOOPEND:
                 for(i = 0; i < sblen; i++)   /* skip repeat loops. */
                 {
-                    if (!voc_readbytes(src, v, trash, sizeof (Uint8)))
+                   if (!voc_readbytes(src, v, trash, sizeof (Uint8)))
                         return 0;
                 } /* for */
                 break;
@@ -348,26 +324,17 @@
                     return 0;
 
                 new_rate_short = SDL_SwapLE16(new_rate_short);
-                if (new_rate_short == 0)
-                {
-                   Sound_SetError("VOC sample rate is zero");
-                   return 0;
-                } /* if */
+                BAIL_IF_MACRO(!new_rate_short, "VOC: sample rate is zero", 0);
+
                 if ((v->rate != -1) && (new_rate_short != v->rate))
-                {
-                   Sound_SetError("VOC sample rate codes differ");
-                   return 0;
-                } /* if */
+                   BAIL_MACRO("VOC: sample rate codes differ", 0);
+
                 v->rate = new_rate_short;
 
                 if (!voc_readbytes(src, v, &uc, sizeof (uc)))
                     return 0;
 
-                if (uc != 0)
-                {
-                    Sound_SetError("VOC decoder only interprets 8-bit data");
-                    return 0;
-                } /* if */
+                BAIL_IF_MACRO(uc != 0, "VOC: only supports 8-bit data", 0);
 
                 if (!voc_readbytes(src, v, &uc, sizeof (uc)))
                     return 0;
@@ -391,8 +358,11 @@
                 /* Falling! Falling! */
 
             default:  /* text block or other krapola. */
-                if (!voc_readbytes(src, v, &trash, sizeof (Uint8) * sblen))
-                    return 0;
+                for(i = 0; i < sblen; i++)   /* skip repeat loops. */
+                {
+                   if (!voc_readbytes(src, v, trash, sizeof (Uint8)))
+                        return 0;
+                } /* for */
 
                 if (block == VOC_TEXT)
                     continue;    /* get next block */
@@ -443,7 +413,7 @@
             done = SDL_RWread(src, buf + v->bufpos, 1, max);
             if (done < max)
             {
-                Sound_SetError("VOC: i/o error");
+                __Sound_SetError("VOC: i/o error");
                 sample->flags |= SOUND_SAMPLEFLAG_ERROR;
             } /* if */
         } /* if */
@@ -459,7 +429,7 @@
                     done = rc - cur;
                 else
                 {
-                    Sound_SetError("VOC: seek error");
+                    __Sound_SetError("VOC: seek error");
                     sample->flags |= SOUND_SAMPLEFLAG_ERROR;
                 } /* else */
             } /* if */
@@ -496,9 +466,8 @@
 
     if (v->rate == -1)
     {
-        Sound_SetError("VOC data had no sound!");
         free(v);
-        return(0);
+        BAIL_MACRO("VOC: data had no sound!", 0);
     } /* if */
 
     SNDDBG(("VOC: Accepting data stream.\n"));