Mercurial > sdl-ios-xcode
annotate test/testresample.c @ 5275:7aba0406c273
Frank Zago to sdl
The following patch fixes some of the bitrot for the Nintendo DS port.
The support is still basic at the moment, but it allows to run the "general"
test under the current head of tree (parent: 5269:11bd1585efb5 tip).
Most of the patch is mine, but I integrated a couple changes that John
Magnotti posted on Feb 1st.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 12 Feb 2011 11:36:56 -0800 |
parents | 62d4992e5a92 |
children |
rev | line source |
---|---|
3017 | 1 #include <stdio.h> |
2 #include "SDL.h" | |
3 | |
3040 | 4 int |
5 main(int argc, char **argv) | |
3017 | 6 { |
7 SDL_AudioSpec spec; | |
8 SDL_AudioCVT cvt; | |
9 Uint32 len = 0; | |
10 Uint8 *data = NULL; | |
11 int cvtfreq = 0; | |
12 int bitsize = 0; | |
13 int blockalign = 0; | |
14 int avgbytes = 0; | |
15 SDL_RWops *io = NULL; | |
16 | |
3040 | 17 if (argc != 4) { |
3017 | 18 fprintf(stderr, "USAGE: %s in.wav out.wav newfreq\n", argv[0]); |
19 return 1; | |
20 } | |
21 | |
22 cvtfreq = atoi(argv[3]); | |
23 | |
3040 | 24 if (SDL_Init(SDL_INIT_AUDIO) == -1) { |
3017 | 25 fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError()); |
26 return 2; | |
27 } | |
28 | |
3040 | 29 if (SDL_LoadWAV(argv[1], &spec, &data, &len) == NULL) { |
3017 | 30 fprintf(stderr, "failed to load %s: %s\n", argv[1], SDL_GetError()); |
31 SDL_Quit(); | |
32 return 3; | |
33 } | |
34 | |
35 if (SDL_BuildAudioCVT(&cvt, spec.format, spec.channels, spec.freq, | |
3040 | 36 spec.format, spec.channels, cvtfreq) == -1) { |
3017 | 37 fprintf(stderr, "failed to build CVT: %s\n", SDL_GetError()); |
38 SDL_FreeWAV(data); | |
39 SDL_Quit(); | |
40 return 4; | |
41 } | |
42 | |
43 cvt.len = len; | |
44 cvt.buf = (Uint8 *) malloc(len * cvt.len_mult); | |
3040 | 45 if (cvt.buf == NULL) { |
3017 | 46 fprintf(stderr, "Out of memory.\n"); |
47 SDL_FreeWAV(data); | |
48 SDL_Quit(); | |
49 return 5; | |
50 } | |
51 memcpy(cvt.buf, data, len); | |
52 | |
3040 | 53 if (SDL_ConvertAudio(&cvt) == -1) { |
3017 | 54 fprintf(stderr, "Conversion failed: %s\n", SDL_GetError()); |
55 free(cvt.buf); | |
56 SDL_FreeWAV(data); | |
57 SDL_Quit(); | |
58 return 6; | |
59 } | |
60 | |
61 /* write out a WAV header... */ | |
62 io = SDL_RWFromFile(argv[2], "wb"); | |
3040 | 63 if (io == NULL) { |
3017 | 64 fprintf(stderr, "fopen('%s') failed: %s\n", argv[2], SDL_GetError()); |
65 free(cvt.buf); | |
66 SDL_FreeWAV(data); | |
67 SDL_Quit(); | |
68 return 7; | |
69 } | |
70 | |
71 bitsize = SDL_AUDIO_BITSIZE(spec.format); | |
72 blockalign = (bitsize / 8) * spec.channels; | |
73 avgbytes = cvtfreq * blockalign; | |
74 | |
3040 | 75 SDL_WriteLE32(io, 0x46464952); /* RIFF */ |
3017 | 76 SDL_WriteLE32(io, len * cvt.len_mult + 36); |
3040 | 77 SDL_WriteLE32(io, 0x45564157); /* WAVE */ |
78 SDL_WriteLE32(io, 0x20746D66); /* fmt */ | |
79 SDL_WriteLE32(io, 16); /* chunk size */ | |
80 SDL_WriteLE16(io, 1); /* uncompressed */ | |
81 SDL_WriteLE16(io, spec.channels); /* channels */ | |
82 SDL_WriteLE32(io, cvtfreq); /* sample rate */ | |
83 SDL_WriteLE32(io, avgbytes); /* average bytes per second */ | |
84 SDL_WriteLE16(io, blockalign); /* block align */ | |
85 SDL_WriteLE16(io, bitsize); /* significant bits per sample */ | |
86 SDL_WriteLE32(io, 0x61746164); /* data */ | |
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 | 89 |
3040 | 90 if (SDL_RWclose(io) == -1) { |
3017 | 91 fprintf(stderr, "fclose('%s') failed: %s\n", argv[2], SDL_GetError()); |
92 free(cvt.buf); | |
93 SDL_FreeWAV(data); | |
94 SDL_Quit(); | |
95 return 8; | |
3040 | 96 } // if |
3017 | 97 |
98 free(cvt.buf); | |
99 SDL_FreeWAV(data); | |
100 SDL_Quit(); | |
101 return 0; | |
3040 | 102 } // main |
3017 | 103 |
104 // end of resample_test.c ... |