test/testresample.c
changeset 7444 3b9b7bcee64f
parent 5535 96594ac5fd1a
child 7517 965d57022c01
equal deleted inserted replaced
7443:58c5fcba814d 7444:3b9b7bcee64f
    28     if (argc != 4) {
    28     if (argc != 4) {
    29         fprintf(stderr, "USAGE: %s in.wav out.wav newfreq\n", argv[0]);
    29         fprintf(stderr, "USAGE: %s in.wav out.wav newfreq\n", argv[0]);
    30         return 1;
    30         return 1;
    31     }
    31     }
    32 
    32 
    33     cvtfreq = atoi(argv[3]);
    33     cvtfreq = SDL_atoi(argv[3]);
    34 
    34 
    35     if (SDL_Init(SDL_INIT_AUDIO) == -1) {
    35     if (SDL_Init(SDL_INIT_AUDIO) == -1) {
    36         fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
    36         fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
    37         return 2;
    37         return 2;
    38     }
    38     }
    50         SDL_Quit();
    50         SDL_Quit();
    51         return 4;
    51         return 4;
    52     }
    52     }
    53 
    53 
    54     cvt.len = len;
    54     cvt.len = len;
    55     cvt.buf = (Uint8 *) malloc(len * cvt.len_mult);
    55     cvt.buf = (Uint8 *) SDL_malloc(len * cvt.len_mult);
    56     if (cvt.buf == NULL) {
    56     if (cvt.buf == NULL) {
    57         fprintf(stderr, "Out of memory.\n");
    57         fprintf(stderr, "Out of memory.\n");
    58         SDL_FreeWAV(data);
    58         SDL_FreeWAV(data);
    59         SDL_Quit();
    59         SDL_Quit();
    60         return 5;
    60         return 5;
    61     }
    61     }
    62     memcpy(cvt.buf, data, len);
    62     SDL_memcpy(cvt.buf, data, len);
    63 
    63 
    64     if (SDL_ConvertAudio(&cvt) == -1) {
    64     if (SDL_ConvertAudio(&cvt) == -1) {
    65         fprintf(stderr, "Conversion failed: %s\n", SDL_GetError());
    65         fprintf(stderr, "Conversion failed: %s\n", SDL_GetError());
    66         free(cvt.buf);
    66         SDL_free(cvt.buf);
    67         SDL_FreeWAV(data);
    67         SDL_FreeWAV(data);
    68         SDL_Quit();
    68         SDL_Quit();
    69         return 6;
    69         return 6;
    70     }
    70     }
    71 
    71 
    72     /* write out a WAV header... */
    72     /* write out a WAV header... */
    73     io = SDL_RWFromFile(argv[2], "wb");
    73     io = SDL_RWFromFile(argv[2], "wb");
    74     if (io == NULL) {
    74     if (io == NULL) {
    75         fprintf(stderr, "fopen('%s') failed: %s\n", argv[2], SDL_GetError());
    75         fprintf(stderr, "fopen('%s') failed: %s\n", argv[2], SDL_GetError());
    76         free(cvt.buf);
    76         SDL_free(cvt.buf);
    77         SDL_FreeWAV(data);
    77         SDL_FreeWAV(data);
    78         SDL_Quit();
    78         SDL_Quit();
    79         return 7;
    79         return 7;
    80     }
    80     }
    81 
    81 
    98     SDL_WriteLE32(io, cvt.len_cvt);     /* size */
    98     SDL_WriteLE32(io, cvt.len_cvt);     /* size */
    99     SDL_RWwrite(io, cvt.buf, cvt.len_cvt, 1);
    99     SDL_RWwrite(io, cvt.buf, cvt.len_cvt, 1);
   100 
   100 
   101     if (SDL_RWclose(io) == -1) {
   101     if (SDL_RWclose(io) == -1) {
   102         fprintf(stderr, "fclose('%s') failed: %s\n", argv[2], SDL_GetError());
   102         fprintf(stderr, "fclose('%s') failed: %s\n", argv[2], SDL_GetError());
   103         free(cvt.buf);
   103         SDL_free(cvt.buf);
   104         SDL_FreeWAV(data);
   104         SDL_FreeWAV(data);
   105         SDL_Quit();
   105         SDL_Quit();
   106         return 8;
   106         return 8;
   107     }                           // if
   107     }                           // if
   108 
   108 
   109     free(cvt.buf);
   109     SDL_free(cvt.buf);
   110     SDL_FreeWAV(data);
   110     SDL_FreeWAV(data);
   111     SDL_Quit();
   111     SDL_Quit();
   112     return 0;
   112     return 0;
   113 }                               // main
   113 }                               // main
   114 
   114