annotate test/testresample.c @ 4426:1bceff8f008f

Fixed bug #943 Ozkan Sezer 2010-02-06 12:31:06 PST Hi: Here are some small fixes for compiling SDL against mingw-w64. (see http://mingw-w64.sourceforge.net/ . Despite the name, it supports both win32 and win64.) src/audio/windx5/directx.h and src/video/windx5/directx.h (both SDL-1.2 and SDL-1.3.) I get compilation errors about some union not having a member named u1 and alike, because of other system headers being included before this one and them already defining DUMMYUNIONNAME and stuff. This header probably assumes that those stuff are defined in windef.h, but mingw-w64 headers define them in _mingw.h. Easily fixed by moving NONAMELESSUNION definition to the top of the file. src/thread/win32/SDL_systhread.c (both SDL-1.2 and SDL-1.3.) : The __GNUC__ case for pfnSDL_CurrentBeginThread is 32-bit centric because _beginthreadex returns uintptr_t, not unsigned long which is 32 bits in win64. Changing the return type to uintptr_t fixes it. video/SDL_blit.h (and configure.in) (SDL-1.3-only) : MinGW-w64 uses msvcrt version of _aligned_malloc and _aligned_free and they are defined in intrin.h (similar to VC). Adding proper ifdefs fixes it. (Notes about macros to check: __MINGW32__ is defined for both mingw.org and for mingw-w64 for both win32 and win64, __MINGW64__ is only defined for _WIN64, so __MINGW64__ can't be used to detect mingw-w64: including _mingw.h and then checking for __MINGW64_VERSION_MAJOR does the trick.) SDL_win32video.h (SDL-1.3-only) : Tweaked the VINWER definition and location in order to avoid multiple redefinition warnings. Hope these are useful. Thanks.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 10 Mar 2010 15:02:58 +0000
parents 62d4992e5a92
children
rev   line source
3017
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 #include <stdio.h>
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 #include "SDL.h"
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
4 int
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
5 main(int argc, char **argv)
3017
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 {
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 SDL_AudioSpec spec;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 SDL_AudioCVT cvt;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 Uint32 len = 0;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 Uint8 *data = NULL;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 int cvtfreq = 0;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 int bitsize = 0;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 int blockalign = 0;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 int avgbytes = 0;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 SDL_RWops *io = NULL;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
17 if (argc != 4) {
3017
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 fprintf(stderr, "USAGE: %s in.wav out.wav newfreq\n", argv[0]);
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 return 1;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 }
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 cvtfreq = atoi(argv[3]);
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
24 if (SDL_Init(SDL_INIT_AUDIO) == -1) {
3017
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 return 2;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 }
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
29 if (SDL_LoadWAV(argv[1], &spec, &data, &len) == NULL) {
3017
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 fprintf(stderr, "failed to load %s: %s\n", argv[1], SDL_GetError());
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 SDL_Quit();
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 return 3;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 }
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 if (SDL_BuildAudioCVT(&cvt, spec.format, spec.channels, spec.freq,
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
36 spec.format, spec.channels, cvtfreq) == -1) {
3017
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 fprintf(stderr, "failed to build CVT: %s\n", SDL_GetError());
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 SDL_FreeWAV(data);
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 SDL_Quit();
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 return 4;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 }
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 cvt.len = len;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 cvt.buf = (Uint8 *) malloc(len * cvt.len_mult);
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
45 if (cvt.buf == NULL) {
3017
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 fprintf(stderr, "Out of memory.\n");
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 SDL_FreeWAV(data);
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 SDL_Quit();
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 return 5;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 }
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 memcpy(cvt.buf, data, len);
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
53 if (SDL_ConvertAudio(&cvt) == -1) {
3017
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 fprintf(stderr, "Conversion failed: %s\n", SDL_GetError());
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 free(cvt.buf);
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 SDL_FreeWAV(data);
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 SDL_Quit();
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 return 6;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 }
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 /* write out a WAV header... */
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 io = SDL_RWFromFile(argv[2], "wb");
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
63 if (io == NULL) {
3017
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 fprintf(stderr, "fopen('%s') failed: %s\n", argv[2], SDL_GetError());
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 free(cvt.buf);
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 SDL_FreeWAV(data);
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 SDL_Quit();
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 return 7;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 }
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 bitsize = SDL_AUDIO_BITSIZE(spec.format);
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 blockalign = (bitsize / 8) * spec.channels;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 avgbytes = cvtfreq * blockalign;
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
75 SDL_WriteLE32(io, 0x46464952); /* RIFF */
3017
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 SDL_WriteLE32(io, len * cvt.len_mult + 36);
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
77 SDL_WriteLE32(io, 0x45564157); /* WAVE */
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
78 SDL_WriteLE32(io, 0x20746D66); /* fmt */
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
79 SDL_WriteLE32(io, 16); /* chunk size */
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
80 SDL_WriteLE16(io, 1); /* uncompressed */
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
81 SDL_WriteLE16(io, spec.channels); /* channels */
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
82 SDL_WriteLE32(io, cvtfreq); /* sample rate */
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
83 SDL_WriteLE32(io, avgbytes); /* average bytes per second */
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
84 SDL_WriteLE16(io, blockalign); /* block align */
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
85 SDL_WriteLE16(io, bitsize); /* significant bits per sample */
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
86 SDL_WriteLE32(io, 0x61746164); /* data */
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
87 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
88 SDL_RWwrite(io, cvt.buf, cvt.len_cvt, 1);
3017
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
90 if (SDL_RWclose(io) == -1) {
3017
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 fprintf(stderr, "fclose('%s') failed: %s\n", argv[2], SDL_GetError());
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 free(cvt.buf);
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 SDL_FreeWAV(data);
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 SDL_Quit();
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 return 8;
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
96 } // if
3017
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 free(cvt.buf);
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 SDL_FreeWAV(data);
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 SDL_Quit();
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 return 0;
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3018
diff changeset
102 } // main
3017
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103
3272431eeee2 Added testresample.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 // end of resample_test.c ...