Removed the little endian -> native endian conversion from the sound resampling funct...
authormolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 15 Mar 2004 08:00:02 +0000 (08:00 +0000)
committermolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 15 Mar 2004 08:00:02 +0000 (08:00 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4023 d7cf8633-e32d-0410-b094-e92efae38249

ogg.c
snd_mem.c

diff --git a/ogg.c b/ogg.c
index 293226d..c635e26 100644 (file)
--- a/ogg.c
+++ b/ogg.c
@@ -372,7 +372,7 @@ sfxcache_t *OGG_LoadVorbisFile (const char *filename, sfx_t *s)
        ogg_int64_t len;
        char *buff;
        ogg_int64_t done;
-       int bs;
+       int bs, bigendian;
        long ret;
        sfxcache_t *sc;
 
@@ -411,7 +411,12 @@ sfxcache_t *OGG_LoadVorbisFile (const char *filename, sfx_t *s)
        buff = Mem_Alloc (tempmempool, (int)len);
        done = 0;
        bs = 0;
-       while ((ret = qov_read (&vf, &buff[done], (int)(len - done), 0, 2, 1, &bs)) > 0)
+#if BYTE_ORDER == LITTLE_ENDIAN
+       bigendian = 0;
+#else
+       bigendian = 1;
+#endif
+       while ((ret = qov_read (&vf, &buff[done], (int)(len - done), bigendian, 2, 1, &bs)) > 0)
                done += ret;
 
        // Calculate resampled length
index 7535b38..1f7c75e 100644 (file)
--- a/snd_mem.c
+++ b/snd_mem.c
@@ -56,7 +56,7 @@ void ResampleSfx (sfxcache_t *sc, qbyte *data, char *name)
                                ((signed char *)sc->data)[i] = ((unsigned char *)data)[i] - 128;
                else //if (sc->width == 2) // 16bit
                        for (i = 0;i < srclength;i++)
-                               ((short *)sc->data)[i] = LittleShort (((short *)data)[i]);
+                               ((short *)sc->data)[i] = ((short *)data)[i];
        }
        else
        {
@@ -74,8 +74,8 @@ void ResampleSfx (sfxcache_t *sc, qbyte *data, char *name)
                                        fracstep <<= 1;
                                        for (i=0 ; i<outcount ; i++)
                                        {
-                                               *out++ = LittleShort (in[srcsample  ]);
-                                               *out++ = LittleShort (in[srcsample+1]);
+                                               *out++ = in[srcsample  ];
+                                               *out++ = in[srcsample+1];
                                                srcsample += fracstep;
                                        }
                                }
@@ -83,7 +83,7 @@ void ResampleSfx (sfxcache_t *sc, qbyte *data, char *name)
                                {
                                        for (i=0 ; i<outcount ; i++)
                                        {
-                                               *out++ = LittleShort (in[srcsample  ]);
+                                               *out++ = in[srcsample];
                                                srcsample += fracstep;
                                        }
                                }
@@ -259,6 +259,21 @@ sfxcache_t *S_LoadWavFile (const char *filename, sfx_t *s)
        sc->width = info.width;
        sc->stereo = info.channels == 2;
 
+#if BYTE_ORDER != LITTLE_ENDIAN
+       // We must convert the WAV data from little endian
+       // to the machine endianess before resampling it
+       if (info.width == 2)
+       {
+               int i;
+               short* ptr;
+
+               len = info.samples * info.channels;
+               ptr = (short*)(data + info.dataofs);
+               for (i = 0; i < len; i++)
+                       ptr[i] = LittleShort (ptr[i]);
+       }
+#endif
+
        ResampleSfx(sc, data + info.dataofs, s->name);
 
        Mem_Free(data);