author | Andreas Schiffler <aschiffler@ferzkopp.net> |
Wed, 14 Aug 2013 23:30:10 -0700 | |
changeset 7639 | 9406b7dd2f2d |
parent 7517 | 965d57022c01 |
child 7663 | 53fe1b64eb2d |
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 |
/* |
7517
965d57022c01
Updated the copyright year for the test programs
Sam Lantinga <slouken@libsdl.org>
parents:
7444
diff
changeset
|
2 |
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> |
5535
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 |
*/ |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
12 |
|
3017 | 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 |
||
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
28 |
/* Enable standard application logging */ |
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
29 |
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); |
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
30 |
|
3040 | 31 |
if (argc != 4) { |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
32 |
SDL_Log("USAGE: %s in.wav out.wav newfreq\n", argv[0]); |
3017 | 33 |
return 1; |
34 |
} |
|
35 |
||
7444
3b9b7bcee64f
Fixed compiler warnings in test program by using wrapped functions.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
5535
diff
changeset
|
36 |
cvtfreq = SDL_atoi(argv[3]); |
3017 | 37 |
|
3040 | 38 |
if (SDL_Init(SDL_INIT_AUDIO) == -1) { |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
39 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError()); |
3017 | 40 |
return 2; |
41 |
} |
|
42 |
||
3040 | 43 |
if (SDL_LoadWAV(argv[1], &spec, &data, &len) == NULL) { |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
44 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to load %s: %s\n", argv[1], SDL_GetError()); |
3017 | 45 |
SDL_Quit(); |
46 |
return 3; |
|
47 |
} |
|
48 |
||
49 |
if (SDL_BuildAudioCVT(&cvt, spec.format, spec.channels, spec.freq, |
|
3040 | 50 |
spec.format, spec.channels, cvtfreq) == -1) { |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
51 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to build CVT: %s\n", SDL_GetError()); |
3017 | 52 |
SDL_FreeWAV(data); |
53 |
SDL_Quit(); |
|
54 |
return 4; |
|
55 |
} |
|
56 |
||
57 |
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
|
58 |
cvt.buf = (Uint8 *) SDL_malloc(len * cvt.len_mult); |
3040 | 59 |
if (cvt.buf == NULL) { |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
60 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory.\n"); |
3017 | 61 |
SDL_FreeWAV(data); |
62 |
SDL_Quit(); |
|
63 |
return 5; |
|
64 |
} |
|
7444
3b9b7bcee64f
Fixed compiler warnings in test program by using wrapped functions.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
5535
diff
changeset
|
65 |
SDL_memcpy(cvt.buf, data, len); |
3017 | 66 |
|
3040 | 67 |
if (SDL_ConvertAudio(&cvt) == -1) { |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
68 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "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
|
69 |
SDL_free(cvt.buf); |
3017 | 70 |
SDL_FreeWAV(data); |
71 |
SDL_Quit(); |
|
72 |
return 6; |
|
73 |
} |
|
74 |
||
75 |
/* write out a WAV header... */ |
|
76 |
io = SDL_RWFromFile(argv[2], "wb"); |
|
3040 | 77 |
if (io == NULL) { |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
78 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "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
|
79 |
SDL_free(cvt.buf); |
3017 | 80 |
SDL_FreeWAV(data); |
81 |
SDL_Quit(); |
|
82 |
return 7; |
|
83 |
} |
|
84 |
||
85 |
bitsize = SDL_AUDIO_BITSIZE(spec.format); |
|
86 |
blockalign = (bitsize / 8) * spec.channels; |
|
87 |
avgbytes = cvtfreq * blockalign; |
|
88 |
||
3040 | 89 |
SDL_WriteLE32(io, 0x46464952); /* RIFF */ |
3017 | 90 |
SDL_WriteLE32(io, len * cvt.len_mult + 36); |
3040 | 91 |
SDL_WriteLE32(io, 0x45564157); /* WAVE */ |
92 |
SDL_WriteLE32(io, 0x20746D66); /* fmt */ |
|
93 |
SDL_WriteLE32(io, 16); /* chunk size */ |
|
94 |
SDL_WriteLE16(io, 1); /* uncompressed */ |
|
95 |
SDL_WriteLE16(io, spec.channels); /* channels */ |
|
96 |
SDL_WriteLE32(io, cvtfreq); /* sample rate */ |
|
97 |
SDL_WriteLE32(io, avgbytes); /* average bytes per second */ |
|
98 |
SDL_WriteLE16(io, blockalign); /* block align */ |
|
99 |
SDL_WriteLE16(io, bitsize); /* significant bits per sample */ |
|
100 |
SDL_WriteLE32(io, 0x61746164); /* data */ |
|
101 |
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
|
102 |
SDL_RWwrite(io, cvt.buf, cvt.len_cvt, 1); |
3017 | 103 |
|
3040 | 104 |
if (SDL_RWclose(io) == -1) { |
7639
9406b7dd2f2d
Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
7517
diff
changeset
|
105 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "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
|
106 |
SDL_free(cvt.buf); |
3017 | 107 |
SDL_FreeWAV(data); |
108 |
SDL_Quit(); |
|
109 |
return 8; |
|
3040 | 110 |
} // if |
3017 | 111 |
|
7444
3b9b7bcee64f
Fixed compiler warnings in test program by using wrapped functions.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
5535
diff
changeset
|
112 |
SDL_free(cvt.buf); |
3017 | 113 |
SDL_FreeWAV(data); |
114 |
SDL_Quit(); |
|
115 |
return 0; |
|
3040 | 116 |
} // main |
3017 | 117 |
|
118 |
// end of resample_test.c ... |