author | Philipp Wiesemann <philipp.wiesemann@arcor.de> |
Sun, 14 Jul 2013 13:33:54 +0200 | |
changeset 7444 | 3b9b7bcee64f |
parent 5535 | 96594ac5fd1a |
child 7517 | 965d57022c01 |
permissions | -rw-r--r-- |
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
3040
diff
changeset
|
1 |
/* |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
3040
diff
changeset
|
2 |
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org> |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
3040
diff
changeset
|
3 |
|
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
3040
diff
changeset
|
4 |
This software is provided 'as-is', without any express or implied |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
3040
diff
changeset
|
5 |
warranty. In no event will the authors be held liable for any damages |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
3040
diff
changeset
|
6 |
arising from the use of this software. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
3040
diff
changeset
|
7 |
|
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
3040
diff
changeset
|
8 |
Permission is granted to anyone to use this software for any purpose, |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
3040
diff
changeset
|
9 |
including commercial applications, and to alter it and redistribute it |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
3040
diff
changeset
|
10 |
freely. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
3040
diff
changeset
|
11 |
*/ |
3017 | 12 |
#include <stdio.h> |
13 |
#include "SDL.h" |
|
14 |
||
3040 | 15 |
int |
16 |
main(int argc, char **argv) |
|
3017 | 17 |
{ |
18 |
SDL_AudioSpec spec; |
|
19 |
SDL_AudioCVT cvt; |
|
20 |
Uint32 len = 0; |
|
21 |
Uint8 *data = NULL; |
|
22 |
int cvtfreq = 0; |
|
23 |
int bitsize = 0; |
|
24 |
int blockalign = 0; |
|
25 |
int avgbytes = 0; |
|
26 |
SDL_RWops *io = NULL; |
|
27 |
||
3040 | 28 |
if (argc != 4) { |
3017 | 29 |
fprintf(stderr, "USAGE: %s in.wav out.wav newfreq\n", argv[0]); |
30 |
return 1; |
|
31 |
} |
|
32 |
||
7444
3b9b7bcee64f
Fixed compiler warnings in test program by using wrapped functions.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
5535
diff
changeset
|
33 |
cvtfreq = SDL_atoi(argv[3]); |
3017 | 34 |
|
3040 | 35 |
if (SDL_Init(SDL_INIT_AUDIO) == -1) { |
3017 | 36 |
fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError()); |
37 |
return 2; |
|
38 |
} |
|
39 |
||
3040 | 40 |
if (SDL_LoadWAV(argv[1], &spec, &data, &len) == NULL) { |
3017 | 41 |
fprintf(stderr, "failed to load %s: %s\n", argv[1], SDL_GetError()); |
42 |
SDL_Quit(); |
|
43 |
return 3; |
|
44 |
} |
|
45 |
||
46 |
if (SDL_BuildAudioCVT(&cvt, spec.format, spec.channels, spec.freq, |
|
3040 | 47 |
spec.format, spec.channels, cvtfreq) == -1) { |
3017 | 48 |
fprintf(stderr, "failed to build CVT: %s\n", SDL_GetError()); |
49 |
SDL_FreeWAV(data); |
|
50 |
SDL_Quit(); |
|
51 |
return 4; |
|
52 |
} |
|
53 |
||
54 |
cvt.len = len; |
|
7444
3b9b7bcee64f
Fixed compiler warnings in test program by using wrapped functions.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
5535
diff
changeset
|
55 |
cvt.buf = (Uint8 *) SDL_malloc(len * cvt.len_mult); |
3040 | 56 |
if (cvt.buf == NULL) { |
3017 | 57 |
fprintf(stderr, "Out of memory.\n"); |
58 |
SDL_FreeWAV(data); |
|
59 |
SDL_Quit(); |
|
60 |
return 5; |
|
61 |
} |
|
7444
3b9b7bcee64f
Fixed compiler warnings in test program by using wrapped functions.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
5535
diff
changeset
|
62 |
SDL_memcpy(cvt.buf, data, len); |
3017 | 63 |
|
3040 | 64 |
if (SDL_ConvertAudio(&cvt) == -1) { |
3017 | 65 |
fprintf(stderr, "Conversion failed: %s\n", SDL_GetError()); |
7444
3b9b7bcee64f
Fixed compiler warnings in test program by using wrapped functions.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
5535
diff
changeset
|
66 |
SDL_free(cvt.buf); |
3017 | 67 |
SDL_FreeWAV(data); |
68 |
SDL_Quit(); |
|
69 |
return 6; |
|
70 |
} |
|
71 |
||
72 |
/* write out a WAV header... */ |
|
73 |
io = SDL_RWFromFile(argv[2], "wb"); |
|
3040 | 74 |
if (io == NULL) { |
3017 | 75 |
fprintf(stderr, "fopen('%s') failed: %s\n", argv[2], SDL_GetError()); |
7444
3b9b7bcee64f
Fixed compiler warnings in test program by using wrapped functions.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
5535
diff
changeset
|
76 |
SDL_free(cvt.buf); |
3017 | 77 |
SDL_FreeWAV(data); |
78 |
SDL_Quit(); |
|
79 |
return 7; |
|
80 |
} |
|
81 |
||
82 |
bitsize = SDL_AUDIO_BITSIZE(spec.format); |
|
83 |
blockalign = (bitsize / 8) * spec.channels; |
|
84 |
avgbytes = cvtfreq * blockalign; |
|
85 |
||
3040 | 86 |
SDL_WriteLE32(io, 0x46464952); /* RIFF */ |
3017 | 87 |
SDL_WriteLE32(io, len * cvt.len_mult + 36); |
3040 | 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 */ |
|
3018
d706d3170d7d
testresample.c: Write out correct size for resampled buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
3017
diff
changeset
|
99 |
SDL_RWwrite(io, cvt.buf, cvt.len_cvt, 1); |
3017 | 100 |
|
3040 | 101 |
if (SDL_RWclose(io) == -1) { |
3017 | 102 |
fprintf(stderr, "fclose('%s') failed: %s\n", argv[2], SDL_GetError()); |
7444
3b9b7bcee64f
Fixed compiler warnings in test program by using wrapped functions.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
5535
diff
changeset
|
103 |
SDL_free(cvt.buf); |
3017 | 104 |
SDL_FreeWAV(data); |
105 |
SDL_Quit(); |
|
106 |
return 8; |
|
3040 | 107 |
} // if |
3017 | 108 |
|
7444
3b9b7bcee64f
Fixed compiler warnings in test program by using wrapped functions.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
5535
diff
changeset
|
109 |
SDL_free(cvt.buf); |
3017 | 110 |
SDL_FreeWAV(data); |
111 |
SDL_Quit(); |
|
112 |
return 0; |
|
3040 | 113 |
} // main |
3017 | 114 |
|
115 |
// end of resample_test.c ... |