SDL 1.3 is now under the zlib license.
2 Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
16 main(int argc, char **argv)
29 fprintf(stderr, "USAGE: %s in.wav out.wav newfreq\n", argv[0]);
33 cvtfreq = atoi(argv[3]);
35 if (SDL_Init(SDL_INIT_AUDIO) == -1) {
36 fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
40 if (SDL_LoadWAV(argv[1], &spec, &data, &len) == NULL) {
41 fprintf(stderr, "failed to load %s: %s\n", argv[1], SDL_GetError());
46 if (SDL_BuildAudioCVT(&cvt, spec.format, spec.channels, spec.freq,
47 spec.format, spec.channels, cvtfreq) == -1) {
48 fprintf(stderr, "failed to build CVT: %s\n", SDL_GetError());
55 cvt.buf = (Uint8 *) malloc(len * cvt.len_mult);
56 if (cvt.buf == NULL) {
57 fprintf(stderr, "Out of memory.\n");
62 memcpy(cvt.buf, data, len);
64 if (SDL_ConvertAudio(&cvt) == -1) {
65 fprintf(stderr, "Conversion failed: %s\n", SDL_GetError());
72 /* write out a WAV header... */
73 io = SDL_RWFromFile(argv[2], "wb");
75 fprintf(stderr, "fopen('%s') failed: %s\n", argv[2], SDL_GetError());
82 bitsize = SDL_AUDIO_BITSIZE(spec.format);
83 blockalign = (bitsize / 8) * spec.channels;
84 avgbytes = cvtfreq * blockalign;
86 SDL_WriteLE32(io, 0x46464952); /* RIFF */
87 SDL_WriteLE32(io, len * cvt.len_mult + 36);
88 SDL_WriteLE32(io, 0x45564157); /* WAVE */
89 SDL_WriteLE32(io, 0x20746D66); /* fmt */
90 SDL_WriteLE32(io, 16); /* chunk size */
91 SDL_WriteLE16(io, 1); /* uncompressed */
92 SDL_WriteLE16(io, spec.channels); /* channels */
93 SDL_WriteLE32(io, cvtfreq); /* sample rate */
94 SDL_WriteLE32(io, avgbytes); /* average bytes per second */
95 SDL_WriteLE16(io, blockalign); /* block align */
96 SDL_WriteLE16(io, bitsize); /* significant bits per sample */
97 SDL_WriteLE32(io, 0x61746164); /* data */
98 SDL_WriteLE32(io, cvt.len_cvt); /* size */
99 SDL_RWwrite(io, cvt.buf, cvt.len_cvt, 1);
101 if (SDL_RWclose(io) == -1) {
102 fprintf(stderr, "fclose('%s') failed: %s\n", argv[2], SDL_GetError());
115 // end of resample_test.c ...