stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus/src/sound libcda.c mad.c music.c ogg.c


From: Jimmy Salmon
Subject: [Stratagus-CVS] stratagus/src/sound libcda.c mad.c music.c ogg.c
Date: Wed, 01 Oct 2003 17:01:00 -0400

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Jimmy Salmon <address@hidden>   03/10/01 17:01:00

Modified files:
        src/sound      : libcda.c mad.c music.c ogg.c 

Log message:
        Cleanup

Patches:
Index: stratagus/src/sound/libcda.c
diff -u stratagus/src/sound/libcda.c:1.4 stratagus/src/sound/libcda.c:1.5
--- stratagus/src/sound/libcda.c:1.4    Thu Jul  3 12:35:43 2003
+++ stratagus/src/sound/libcda.c        Wed Oct  1 17:00:59 2003
@@ -29,17 +29,17 @@
 static int fd = -1;
 
 static char _cd_error[256];
-const char *cd_error = _cd_error;
+const char* cd_error = _cd_error;
 
 
 static void copy_cd_error(void)
 {
-    strncpy(_cd_error, strerror(errno), sizeof _cd_error);
+    strncpy(_cd_error, strerror(errno), sizeof(_cd_error));
     _cd_error[sizeof _cd_error - 1] = 0;
 }
 
 
-static int get_tocentry(int track, struct cdrom_tocentry *e)
+static int get_tocentry(int track, struct cdrom_tocentry* e)
 {
     memset(e, 0, sizeof(struct cdrom_tocentry));
     e->cdte_track = track;
@@ -54,7 +54,7 @@
 }
 
 
-static int get_subchnl(struct cdrom_subchnl *s)
+static int get_subchnl(struct cdrom_subchnl* s)
 {
     memset(s, 0, sizeof(struct cdrom_subchnl));
     s->cdsc_format = CDROM_MSF;
@@ -70,14 +70,18 @@
 /* cd_init:
  *  Initialise library.  Return zero on success.
  */
-int cd_init()
+int cd_init(void)
 {
     char *device;
 
     device = getenv("CDAUDIO");
-    if (!device) device = "/dev/cdrom";
+    if (!device) {
+       device = "/dev/cdrom";
+    }
 
-    if (fd != -1) close(fd);
+    if (fd != -1) {
+       close(fd);
+    }
 
     fd = open(device, O_RDONLY | O_NONBLOCK);
     if (fd < 0) {
@@ -92,7 +96,7 @@
 /* cd_exit:
  *  Shutdown.
  */
-void cd_exit()
+void cd_exit(void)
 {
     if (fd != -1) {
        close(fd);
@@ -113,14 +117,15 @@
     
     /* cdrom.h: The leadout track is always 0xAA, regardless 
      * of # of tracks on disc. */
-    if (t2 == last)
+    if (t2 == last) {
        t2 = CDROM_LEADOUT;
-    else
-       t2++;
+    } else {
+       ++t2;
+    }
     
-    if ((get_tocentry(t1, &e0) != 0) ||
-       (get_tocentry(t2, &e1) != 0))
+    if ((get_tocentry(t1, &e0) != 0) || (get_tocentry(t2, &e1) != 0)) {
        return -1;
+    }
 
     msf.cdmsf_min0 = e0.cdte_addr.msf.minute;
     msf.cdmsf_sec0 = e0.cdte_addr.msf.second;
@@ -176,8 +181,9 @@
 {
     int last;
     
-    if (cd_get_tracks(0, &last) != 0)
+    if (cd_get_tracks(0, &last) != 0) {
        return -1;
+    }
     
     return play(track, last);
 }
@@ -186,22 +192,23 @@
 /* cd_current_track:
  *  Return track currently in playback, or zero if stopped.
  */
-int cd_current_track()
+int cd_current_track(void)
 {
     struct cdrom_subchnl s;
 
     get_subchnl(&s);
-    if (s.cdsc_audiostatus == CDROM_AUDIO_PLAY)
+    if (s.cdsc_audiostatus == CDROM_AUDIO_PLAY) {
        return s.cdsc_trk;
-    else
+    } else {
        return 0;
+    }
 }
 
 
 /* cd_pause:
  *  Pause playback.
  */
-void cd_pause()
+void cd_pause(void)
 {
     ioctl(fd, CDROMPAUSE);
 }
@@ -210,17 +217,18 @@
 /* cd_resume:
  *  Resume playback.
  */
-void cd_resume()
+void cd_resume(void)
 {
-    if (cd_is_paused())
+    if (cd_is_paused()) {
        ioctl(fd, CDROMRESUME);
+    }
 }
 
 
 /* cd_is_paused:
  *  Return non-zero if playback is paused.
  */
-int cd_is_paused()
+int cd_is_paused(void)
 {
     struct cdrom_subchnl s;
 
@@ -232,7 +240,7 @@
 /* cd_stop:
  *  Stop playback.
  */
-void cd_stop()
+void cd_stop(void)
 {
     ioctl(fd, CDROMSTOP);
 }
@@ -241,19 +249,27 @@
 /* cd_get_tracks:
  *  Get first and last tracks of CD.  Return zero on success.
  */
-int cd_get_tracks(int *first, int *last)
+int cd_get_tracks(int* first, int* last)
 {
     struct cdrom_tochdr toc;
 
     if (ioctl(fd, CDROMREADTOCHDR, &toc) < 0) {
        copy_cd_error();
-       if (first) *first = 0;
-       if (last) *last = 0;
+       if (first) {
+           *first = 0;
+       }
+       if (last) {
+           *last = 0;
+       }
        return -1;
     }
 
-    if (first) *first = toc.cdth_trk0;
-    if (last)  *last  = toc.cdth_trk1;
+    if (first) {
+       *first = toc.cdth_trk0;
+    }
+    if (last) {
+       *last  = toc.cdth_trk1;
+    }
     return 0;
 }
 
@@ -266,8 +282,9 @@
 {
     struct cdrom_tocentry e;
 
-    if ((cd_get_tracks(0, 0) < 0) || (get_tocentry(track, &e) < 0))
+    if ((cd_get_tracks(0, 0) < 0) || (get_tocentry(track, &e) < 0)) {
        return -1;
+    }
     return (e.cdte_ctrl & CDROM_DATA_TRACK) ? 0 : 1;
 }
 
@@ -275,13 +292,17 @@
 /* cd_get_volume:
  *  Return volumes of left and right channels.
  */
-void cd_get_volume(int *c0, int *c1)
+void cd_get_volume(int* c0, int* c1)
 {
     struct cdrom_volctrl vol;
 
     ioctl(fd, CDROMVOLREAD, &vol);
-    if (c0) *c0 = vol.channel0;
-    if (c1) *c1 = vol.channel1;
+    if (c0) {
+       *c0 = vol.channel0;
+    }
+    if (c1) {
+       *c1 = vol.channel1;
+    }
 }
 
 
@@ -303,7 +324,7 @@
 /* cd_eject:
  *  Eject CD drive (if possible).
  */
-void cd_eject()
+void cd_eject(void)
 {
     ioctl(fd, CDROMEJECT);
 }
@@ -312,7 +333,7 @@
 /* cd_close:
  *  Close CD drive (if possible).
  */
-void cd_close()
+void cd_close(void)
 {
     ioctl(fd, CDROMCLOSETRAY);
 }
@@ -362,8 +383,9 @@
     va_end(ap);
 
     err = mciSendString(buf, ret, sizeof ret, 0);
-    if (err) 
+    if (err) {
        mciGetErrorString(err, _cd_error, sizeof _cd_error);
+    }
     return err ? -1 : 0;
 }
 
@@ -373,8 +395,9 @@
     int err;
 
     err = command("open cdaudio wait");
-    if (!err) 
+    if (!err) {
        err = command("set cdaudio time format tmsf");
+    }
 
     paused = 0;
     return err;
@@ -424,12 +447,14 @@
 
 int cd_current_track(void)
 {
-    if ((command("status cdaudio mode") != 0) || 
-       (strcmp(ret, "playing") != 0))
+    if ((command("status cdaudio mode") != 0) ||
+           (strcmp(ret, "playing") != 0)) {
        return 0;
+    }
        
-    if (command("status cdaudio current track") != 0)
+    if (command("status cdaudio current track") != 0) {
        return 0;
+    }
     return atoi(ret);
 }
 
@@ -450,10 +475,11 @@
     if (!paused)
        return;
 
-    if (end_pos[0])
+    if (end_pos[0]) {
        command("play cdaudio from %s to %s", paused_pos, end_pos);
-    else
+    } else {
        command("play cdaudio from %s", paused_pos);
+    }
     paused = 0;
 }
 
@@ -480,8 +506,12 @@
 
     i = atoi(ret);
     
-    if (first) *first = 1;
-    if (last) *last = i;
+    if (first) {
+       *first = 1;
+    }
+    if (last) {
+       *last = i;
+    }
     
     return (i) ? 0 : -1;
 }
@@ -489,16 +519,21 @@
 
 int cd_is_audio(int track)
 {
-    if (command("status cdaudio type track %u", track) != 0)
+    if (command("status cdaudio type track %u", track) != 0) {
        return -1;
+    }
     return (strcmp(ret, "audio") == 0) ? 1 : 0;
 }
 
 
 void cd_get_volume(int *c0, int *c1)
 {
-    if (c0) *c0 = 128; /* (shrug) */
-    if (c1) *c1 = 128;
+    if (c0) {
+       *c0 = 128;      /* (shrug) */
+    }
+    if (c1) {
+       *c1 = 128;
+    }
 }
 
 
Index: stratagus/src/sound/mad.c
diff -u stratagus/src/sound/mad.c:1.24 stratagus/src/sound/mad.c:1.25
--- stratagus/src/sound/mad.c:1.24      Sun Aug 17 11:57:07 2003
+++ stratagus/src/sound/mad.c   Wed Oct  1 17:01:00 2003
@@ -10,7 +10,7 @@
 //
 /address@hidden mad.c                  -       mp3 support with libmad */
 //
-//     (c) Copyright 2002 by Lutz Sammer
+//     (c) Copyright 2002-2003 by Lutz Sammer
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: mad.c,v 1.24 2003/08/17 15:57:07 n0body Exp $
+//     $Id: mad.c,v 1.25 2003/10/01 21:01:00 jsalmon3 Exp $
 
 //     FIXME: JOHNS: MP3 streaming did not yet work.
 
@@ -85,16 +85,16 @@
 **
 **     @return         MAP_FLOW_STOP if eof, MAD_FLOW_CONTINUE otherwise.
 */
-local enum mad_flow MAD_read(void *user, struct mad_stream *stream)
+local enum mad_flow MAD_read(void* user, struct mad_stream* stream)
 {
     int i;
     int l;
-    CLFile *f;
-    MyUser *u;
+    CLFile* f;
+    MyUser* u;
 
     DebugLevel3Fn("Read callback\n");
 
-    u = (MyUser *) user;
+    u = (MyUser*) user;
     f = u->File;
 
     l = 0;
@@ -124,9 +124,9 @@
 **     @param header   MAD header.
 **     @param pcm      MAD pcm data struture.
 */
-local enum mad_flow MAD_write(void *user,
-    struct mad_header const *header __attribute__((unused)),
-    struct mad_pcm *pcm)
+local enum mad_flow MAD_write(void* user,
+    struct mad_header const* header __attribute__((unused)),
+    struct mad_pcm* pcm)
 {
     int i;
     int n;
@@ -135,14 +135,14 @@
     Sample* sample;
     short* p;
 
-    n=pcm->length;
-    channels=pcm->channels;
+    n = pcm->length;
+    channels = pcm->channels;
 
     DebugLevel3Fn("%d channels %d samples\n" _C_ channels _C_ n);
 
-    sample = ((MyUser *) user)->Sample;
+    sample = ((MyUser*)user)->Sample;
 
-    if( !sample->SampleSize ) {
+    if (!sample->SampleSize) {
        sample->Frequency = pcm->samplerate;
        sample->Channels = channels;
        sample->SampleSize = 16;
@@ -150,18 +150,18 @@
 
     i = n * channels * 2;
 
-    ((MyUser *) user)->Sample = sample =
+    ((MyUser*)user)->Sample = sample =
        realloc(sample, sizeof(*sample) + sample->Length + i);
     if (!sample) {
        fprintf(stderr, "Out of memory!\n");
-       CLclose(((MyUser *) user)->File);
+       CLclose(((MyUser*) user)->File);
        ExitFatal(-1);
     }
     p = (short*)(sample->Data + sample->Length);
     sample->Length += i;
 
-    for( i=0; i<n; ++i ) {
-       for( c=0; c<channels; ++c ) {
+    for (i = 0; i < n; ++i) {
+       for (c = 0; c < channels; ++c) {
            mad_fixed_t b;
 
            b = pcm->samples[c][i];
@@ -187,9 +187,9 @@
 **     possible MAD_ERROR_* errors can be found in the mad.h (or
 **     libmad/stream.h) header file.
 */
-local enum mad_flow MAD_error(void *user __attribute__((unused)),
-    struct mad_stream *stream,
-    struct mad_frame *frame __attribute__((unused)))
+local enum mad_flow MAD_error(void* user __attribute__((unused)),
+    struct mad_stream* stream,
+    struct mad_frame* frame __attribute__((unused)))
 {
     fprintf(stderr, "decoding error 0x%04x (%s)\n",
        stream->error, mad_stream_errorstr(stream));
@@ -210,9 +210,9 @@
 */
 local int MadRead(struct mad_decoder* decoder, unsigned char* buf, int len)
 {
-    struct mad_stream *stream;
-    struct mad_frame *frame;
-    struct mad_synth *synth;
+    struct mad_stream* stream;
+    struct mad_frame* frame;
+    struct mad_synth* synth;
 
     DebugLevel0Fn("%p %p %d\n" _C_ decoder _C_ buf _C_ len);
 
@@ -334,7 +334,9 @@
 {
     Mp3Data* data;
 
-    IfDebug( AllocatedSoundMemory -= sizeof(*sample) + MP3_BUFFER_SIZE);
+#ifdef DEBUG
+    AllocatedSoundMemory -= sizeof(*sample) + MP3_BUFFER_SIZE;
+#endif
 
     data = sample->User;
 
@@ -393,7 +395,9 @@
 */
 local void Mp3Free(Sample* sample)
 {
-    IfDebug( AllocatedSoundMemory -= sample->Length; );
+#ifdef DEBUG
+    AllocatedSoundMemory -= sample->Length;
+#endif
 
     free(sample);
 }
@@ -416,7 +420,7 @@
 **
 **     @todo           Support more flags, LoadOnDemand.
 */
-global Sample *LoadMp3(const char* name, int flags)
+global Sample* LoadMp3(const char* name, int flags)
 {
     CLFile* f;
     unsigned char magic[2];
@@ -428,7 +432,7 @@
     }
     CLread(f, magic, sizeof(magic));
     // 0xFF 0xE? for mp3 stream
-    if (magic[0] != 0xFF || (magic[1]&0xE0) != 0xE0 ) {
+    if (magic[0] != 0xFF || (magic[1]&0xE0) != 0xE0) {
        CLclose(f);
        return NULL;
     }
@@ -493,14 +497,16 @@
        mad_frame_init(&data->Decoder->sync->frame);
        mad_synth_init(&data->Decoder->sync->synth);
        mad_stream_options(&data->Decoder->sync->stream,
-               data->Decoder->options);
+           data->Decoder->options);
 
        // Read first frame for channels, ...
        data->PointerInBuffer = sample->Data;
        sample->Length = MadRead(data->Decoder, sample->Data, MP3_BUFFER_SIZE);
 
        DebugLevel0Fn(" %d\n" _C_ sizeof(*sample) + MP3_BUFFER_SIZE);
-       IfDebug( AllocatedSoundMemory += sizeof(*sample) + MP3_BUFFER_SIZE);
+#ifdef DEBUG
+       AllocatedSoundMemory += sizeof(*sample) + MP3_BUFFER_SIZE;
+#endif
 
        return sample;
     } else {
@@ -527,7 +533,9 @@
        user.Sample->User = 0;
 
        DebugLevel0Fn(" %d\n" _C_ user.Sample->Length);
-       IfDebug( AllocatedSoundMemory += user.Sample->Length; );
+#ifdef DEBUG
+       AllocatedSoundMemory += user.Sample->Length;
+#endif
 
        return user.Sample;
     }
Index: stratagus/src/sound/music.c
diff -u stratagus/src/sound/music.c:1.81 stratagus/src/sound/music.c:1.82
--- stratagus/src/sound/music.c:1.81    Sun Aug 17 11:57:07 2003
+++ stratagus/src/sound/music.c Wed Oct  1 17:01:00 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: music.c,v 1.81 2003/08/17 15:57:07 n0body Exp $
+//     $Id: music.c,v 1.82 2003/10/01 21:01:00 jsalmon3 Exp $
 
 //@{
 
@@ -73,9 +73,9 @@
 global Sample* MusicSample;             /// Music samples
 #endif
 
-global char* CurrentMusicFile = NULL;
+global char* CurrentMusicFile;
 
-global PlaySection *PlaySections;              // Play Sections
+global PlaySection* PlaySections;              // Play Sections
 global int NumPlaySections;                    // Number of Play Sections
 global PlaySectionType CurrentPlaySection;     // Current Play Section
 
@@ -166,7 +166,7 @@
     int ticks;
     int n;
 
-    ticks=GetTicks();
+    ticks = GetTicks();
     DebugLevel0Fn("Trying `%s'\n" _C_ name);
     if (!(f = CLopen(name,CL_OPEN_READ))) {
        printf("Can't open file `%s'\n", name);
@@ -179,10 +179,10 @@
     buffer = malloc(n);
     while ((i = CLread(f, buffer + size, n)) == n) {
        size += n;
-       if (n < 1024*1024) {
+       if (n < 1024 * 1024) {
            n <<= 1;
        } else {
-           n = 2*1024*1024;
+           n = 2 * 1024 * 1024;
        }
        buffer = realloc(buffer, size + n);
     }
@@ -269,15 +269,15 @@
     if (CDMode == CDModeDefined) {
        track = CDTrack;
        newtrack = 0;
-       if ( (1 << track) & PlaySections[i].CDTracks ) {
+       if ((1 << track) & PlaySections[i].CDTracks) {
            newtrack = 0;
        } else {
-           if ( !((1 << CDTrack) & PlaySections[i].CDTracks) ) {
+           if (!((1 << CDTrack) & PlaySections[i].CDTracks)) {
                CDTrack = 0;
            }
            if (PlaySections[i].CDOrder == PlaySectionOrderAll) {
                for (j = CDTrack + 1; j != CDTrack; ++j) {
-                   if ( (1 << j) & PlaySections[i].CDTracks ) {
+                   if ((1 << j) & PlaySections[i].CDTracks) {
                        newtrack = j;
                        break;
                    } else if (j == 31) {
@@ -287,8 +287,8 @@
            } else if (PlaySections[i].CDOrder == PlaySectionOrderRandom) {
                do {
                    newtrack = MyRand() % NumCDTracks;
-               } while ( !((1 << newtrack) & PlaySections[i].CDTracks) || 
-                   (!IsAudioTrack(newtrack)) );
+               } while (!((1 << newtrack) & PlaySections[i].CDTracks) || 
+                   (!IsAudioTrack(newtrack)));
            }
        }
        if (newtrack) {
@@ -354,8 +354,8 @@
 
 #ifdef USE_OGG
     if ((sample = LoadOgg(name, PlayAudioStream))) {
-       if ((sample->Channels != 1 && sample->Channels != 2)
-               || sample->SampleSize != 16) {
+       if ((sample->Channels != 1 && sample->Channels != 2) ||
+               sample->SampleSize != 16) {
            DebugLevel0Fn("Not supported music format\n");
            SoundFree(sample);
            return;
Index: stratagus/src/sound/ogg.c
diff -u stratagus/src/sound/ogg.c:1.31 stratagus/src/sound/ogg.c:1.32
--- stratagus/src/sound/ogg.c:1.31      Sun Aug 17 11:57:08 2003
+++ stratagus/src/sound/ogg.c   Wed Oct  1 17:01:00 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ogg.c,v 1.31 2003/08/17 15:57:08 n0body Exp $
+//     $Id: ogg.c,v 1.32 2003/10/01 21:01:00 jsalmon3 Exp $
 
 //@{
 
@@ -103,8 +103,8 @@
 **     @return                 Seek position, -1 if failure.
 */
 local int OGG_seek(void* user __attribute__((unused)),
-       int64_t offset __attribute__((unused)),
-       int whence __attribute__((unused)))
+    int64_t offset __attribute__((unused)),
+    int whence __attribute__((unused)))
 {
     return -1;
 }
@@ -155,7 +155,7 @@
     int divide;
     char sndbuf[OGG_BUFFER_SIZE];
 
-    data = (OggData*) sample->User;
+    data = (OggData*)sample->User;
 
     // see if we have enough read already
     if (data->PointerInBuffer - sample->Data + len > sample->Length) {
@@ -173,13 +173,11 @@
 
        for (;;) {
 #ifdef WORDS_BIGENDIAN
-           i = ov_read(data->VorbisFile,
-                   sndbuf, n/divide, 1, 2, 1,
-                   &bitstream);
+           i = ov_read(data->VorbisFile, sndbuf, n / divide, 1, 2, 1,
+               &bitstream);
 #else
-           i = ov_read(data->VorbisFile,
-                   sndbuf, n/divide, 0, 2, 1,
-                   &bitstream);
+           i = ov_read(data->VorbisFile, sndbuf, n / divide, 0, 2, 1,
+               &bitstream);
 #endif
            if (i <= 0) {
                break;
@@ -213,7 +211,9 @@
 {
     OggData* data;
 
-    IfDebug( AllocatedSoundMemory -= sizeof(*sample) + OGG_BUFFER_SIZE);
+#ifdef DEBUG
+    AllocatedSoundMemory -= sizeof(*sample) + OGG_BUFFER_SIZE;
+#endif
 
     data = (OggData*)sample->User;
     ov_clear(data->VorbisFile);
@@ -260,7 +260,9 @@
 */
 local void OggFree(Sample* sample)
 {
-    IfDebug( AllocatedSoundMemory -= sample->Length; );
+#ifdef DEBUG
+    AllocatedSoundMemory -= sample->Length;
+#endif
 
     free(sample);
 }
@@ -316,7 +318,7 @@
     }
     */
     info = ov_info(vf, -1);
-    if( !info ) {
+    if (!info) {
        fprintf(stderr, "no ogg stream\n");
        ov_clear(vf);
        return NULL;
@@ -337,7 +339,7 @@
     sample->Frequency = info->rate;
     sample->Length = 0;
 
-    if (flags&PlayAudioStream) {
+    if (flags & PlayAudioStream) {
        OggData* data;
 
        data = malloc(sizeof(OggData));
@@ -354,7 +356,9 @@
        sample->User = data;
 
        DebugLevel0Fn(" %d\n" _C_ sizeof(*sample) + OGG_BUFFER_SIZE);
-       IfDebug( AllocatedSoundMemory += sizeof(*sample) + OGG_BUFFER_SIZE);
+#ifdef DEBUG
+       AllocatedSoundMemory += sizeof(*sample) + OGG_BUFFER_SIZE;
+#endif
     } else {
        int n;
        char* p;
@@ -374,7 +378,7 @@
            if (n < 4096) {
                Sample* s;
 
-               if( sample->Length < 1024*1024 ) {
+               if( sample->Length < 1024 * 1024 ) {
                    n = sample->Length << 1;
                } else {
                    n = 2 * 1024 * 1024;        // Big junks needed for windows
@@ -453,7 +457,7 @@
 
     length = AviReadNextAudioFrame(avi, &frame);
     DebugLevel3Fn("Bytes %d - %d\n" _C_ length _C_ avi->AudioBuffer->Length);
-    if ((int)length<0) {
+    if ((int)length < 0) {
        return 0;
     }
     if (length > nmemb * size) {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]