test/testresample.c
changeset 3040 62d4992e5a92
parent 3018 d706d3170d7d
child 5535 96594ac5fd1a
     1.1 --- a/test/testresample.c	Tue Jan 13 23:27:08 2009 +0000
     1.2 +++ b/test/testresample.c	Wed Jan 14 04:25:32 2009 +0000
     1.3 @@ -1,7 +1,8 @@
     1.4  #include <stdio.h>
     1.5  #include "SDL.h"
     1.6  
     1.7 -int main(int argc, char **argv)
     1.8 +int
     1.9 +main(int argc, char **argv)
    1.10  {
    1.11      SDL_AudioSpec spec;
    1.12      SDL_AudioCVT cvt;
    1.13 @@ -13,30 +14,26 @@
    1.14      int avgbytes = 0;
    1.15      SDL_RWops *io = NULL;
    1.16  
    1.17 -    if (argc != 4)
    1.18 -    {
    1.19 +    if (argc != 4) {
    1.20          fprintf(stderr, "USAGE: %s in.wav out.wav newfreq\n", argv[0]);
    1.21          return 1;
    1.22      }
    1.23  
    1.24      cvtfreq = atoi(argv[3]);
    1.25  
    1.26 -    if (SDL_Init(SDL_INIT_AUDIO) == -1)
    1.27 -    {
    1.28 +    if (SDL_Init(SDL_INIT_AUDIO) == -1) {
    1.29          fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
    1.30          return 2;
    1.31      }
    1.32  
    1.33 -    if (SDL_LoadWAV(argv[1], &spec, &data, &len) == NULL)
    1.34 -    {
    1.35 +    if (SDL_LoadWAV(argv[1], &spec, &data, &len) == NULL) {
    1.36          fprintf(stderr, "failed to load %s: %s\n", argv[1], SDL_GetError());
    1.37          SDL_Quit();
    1.38          return 3;
    1.39      }
    1.40  
    1.41      if (SDL_BuildAudioCVT(&cvt, spec.format, spec.channels, spec.freq,
    1.42 -                          spec.format, spec.channels, cvtfreq) == -1)
    1.43 -    {
    1.44 +                          spec.format, spec.channels, cvtfreq) == -1) {
    1.45          fprintf(stderr, "failed to build CVT: %s\n", SDL_GetError());
    1.46          SDL_FreeWAV(data);
    1.47          SDL_Quit();
    1.48 @@ -45,8 +42,7 @@
    1.49  
    1.50      cvt.len = len;
    1.51      cvt.buf = (Uint8 *) malloc(len * cvt.len_mult);
    1.52 -    if (cvt.buf == NULL)
    1.53 -    {
    1.54 +    if (cvt.buf == NULL) {
    1.55          fprintf(stderr, "Out of memory.\n");
    1.56          SDL_FreeWAV(data);
    1.57          SDL_Quit();
    1.58 @@ -54,8 +50,7 @@
    1.59      }
    1.60      memcpy(cvt.buf, data, len);
    1.61  
    1.62 -    if (SDL_ConvertAudio(&cvt) == -1)
    1.63 -    {
    1.64 +    if (SDL_ConvertAudio(&cvt) == -1) {
    1.65          fprintf(stderr, "Conversion failed: %s\n", SDL_GetError());
    1.66          free(cvt.buf);
    1.67          SDL_FreeWAV(data);
    1.68 @@ -65,8 +60,7 @@
    1.69  
    1.70      /* write out a WAV header... */
    1.71      io = SDL_RWFromFile(argv[2], "wb");
    1.72 -    if (io == NULL)
    1.73 -    {
    1.74 +    if (io == NULL) {
    1.75          fprintf(stderr, "fopen('%s') failed: %s\n", argv[2], SDL_GetError());
    1.76          free(cvt.buf);
    1.77          SDL_FreeWAV(data);
    1.78 @@ -78,35 +72,33 @@
    1.79      blockalign = (bitsize / 8) * spec.channels;
    1.80      avgbytes = cvtfreq * blockalign;
    1.81  
    1.82 -    SDL_WriteLE32(io, 0x46464952);  /* RIFF */
    1.83 +    SDL_WriteLE32(io, 0x46464952);      /* RIFF */
    1.84      SDL_WriteLE32(io, len * cvt.len_mult + 36);
    1.85 -    SDL_WriteLE32(io, 0x45564157);  /* WAVE */
    1.86 -    SDL_WriteLE32(io, 0x20746D66);  /* fmt */
    1.87 -    SDL_WriteLE32(io, 16);          /* chunk size */
    1.88 -    SDL_WriteLE16(io, 1);           /* uncompressed */
    1.89 -    SDL_WriteLE16(io, spec.channels);  /* channels */
    1.90 -    SDL_WriteLE32(io, cvtfreq);  /* sample rate */
    1.91 -    SDL_WriteLE32(io, avgbytes);  /* average bytes per second */
    1.92 -    SDL_WriteLE16(io, blockalign);  /* block align */
    1.93 -    SDL_WriteLE16(io, bitsize);  /* significant bits per sample */
    1.94 -    SDL_WriteLE32(io, 0x61746164);  /* data */
    1.95 -    SDL_WriteLE32(io, cvt.len_cvt);  /* size */
    1.96 +    SDL_WriteLE32(io, 0x45564157);      /* WAVE */
    1.97 +    SDL_WriteLE32(io, 0x20746D66);      /* fmt */
    1.98 +    SDL_WriteLE32(io, 16);      /* chunk size */
    1.99 +    SDL_WriteLE16(io, 1);       /* uncompressed */
   1.100 +    SDL_WriteLE16(io, spec.channels);   /* channels */
   1.101 +    SDL_WriteLE32(io, cvtfreq); /* sample rate */
   1.102 +    SDL_WriteLE32(io, avgbytes);        /* average bytes per second */
   1.103 +    SDL_WriteLE16(io, blockalign);      /* block align */
   1.104 +    SDL_WriteLE16(io, bitsize); /* significant bits per sample */
   1.105 +    SDL_WriteLE32(io, 0x61746164);      /* data */
   1.106 +    SDL_WriteLE32(io, cvt.len_cvt);     /* size */
   1.107      SDL_RWwrite(io, cvt.buf, cvt.len_cvt, 1);
   1.108  
   1.109 -    if (SDL_RWclose(io) == -1)
   1.110 -    {
   1.111 +    if (SDL_RWclose(io) == -1) {
   1.112          fprintf(stderr, "fclose('%s') failed: %s\n", argv[2], SDL_GetError());
   1.113          free(cvt.buf);
   1.114          SDL_FreeWAV(data);
   1.115          SDL_Quit();
   1.116          return 8;
   1.117 -    } // if
   1.118 +    }                           // if
   1.119  
   1.120      free(cvt.buf);
   1.121      SDL_FreeWAV(data);
   1.122      SDL_Quit();
   1.123      return 0;
   1.124 -} // main
   1.125 +}                               // main
   1.126  
   1.127  // end of resample_test.c ...
   1.128 -