Last active
January 8, 2021 06:59
-
-
Save nomissbowling/04997fa52fdd54a42bbc22982158e0db to your computer and use it in GitHub Desktop.
test_pico_waveout.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
test_pico_waveout.c | |
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\cl.exe" -source-charset:utf-8 -execution-charset:utf-8 -EHsc -Fe.\test_pico_waveout.exe .\test_pico_waveout.c -I. -I.\curl-7.74.0_2-win64-mingw\include -I..\SDL2-2.0.14-dev\include -I..\SDL2_mixer-2.0.4-dev\include -link /SUBSYSTEM:CONSOLE /LIBPATH:.\ /LIBPATH:..\SDL2-2.0.14-dev\lib\x64 /LIBPATH:..\SDL2_mixer-2.0.4-dev\lib\x64 /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\ucrt\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x64" libcurl-x64.lib lame_enc.lib libmpg123-0.lib SDL2_mixer.lib SDL2main.lib SDL2.lib shell32.lib winmm.lib | |
del test_pico_waveout.obj | |
test_pico_waveout | |
------------------------------------------------------------------------ | |
see also test_libcurl.c | |
------------------------------------------------------------------------ | |
https://soundeffect-lab.info/sound/button/mp3/decision3.mp3 | |
../sound_btn_yuppy.mp3 36,988 | |
../sound_btn_yuppy.wav 253,484 | |
../sound_btn_yuppy.au 253,464 | |
../sound_btn_yuppy_high_16.mp3 11,160 | |
------------------------------------------------------------------------ | |
play mp3 wav etc | |
SDL2-devel-2.0.14-VC.zip | |
move to ../SDL2-2.0.14-dev/ | |
copy lib/x64/SDL2.dll . | |
SDL2_mixer-devel-2.0.4-VC.zip | |
move to ../SDL2_mixer-2.0.4-dev/ | |
copy lib/x64/SDL2_mixer.dll | |
libFLAC-8.dll | |
libmodplug-1.dll | |
libmpg123-0.dll 2018-11-01 337,408 | |
libogg-0.dll | |
libopus-0.dll | |
libopusfile-0.dll | |
libvorbis-0.dll | |
libvorbisfile-3.dll | |
------------------------------------------------------------------------ | |
convert mp3 to wav | |
libmpg123 http://mpg123.org/download.shtml | |
mpg123-1.26.4-x86-64.zip | |
includes mpg123.h fmt123.h (use partial definition from external functions) | |
includes libmpg123-0.dll 2020-12-25 379,392 (newest original) | |
but use libmpg123-0.dll 2018-11-01 337,408 from SDL2_mixer-2.0.4-dev | |
create def | |
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\dumpbin.exe" /exports libmpg123-0.dll > libmpg123-0_tmp.def -> edit -> libmpg123-0.def | |
create lib | |
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\lib.exe" /def:libmpg123-0.def /machine:x64 /out:libmpg123-0.lib | |
ready to use | |
libmpg123-0.lib 2021-01-07 14:27 30,588 | |
libmpg123-0.exp 2021-01-07 14:27 17,967 | |
------------------------------------------------------------------------ | |
*** not for x64 *** error 0xc000007b with lame_enc.dll | |
convert mp3 to wav | |
Audacity_LAME/lame_v3.100.zip | |
lame_enc.dll 2018-04-13 20:20 342,528 | |
Audacity_LAME/lame-3.100.tar.gz /lame-3.100/include | |
lame.h 2017-09-07 04:33 50,053 | |
create def | |
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\dumpbin.exe" /exports lame_enc.dll > lame_enc_tmp.def -> edit -> lame_enc.def | |
create lib | |
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\lib.exe" /def:lame_enc.def /machine:x64 /out:lame_enc.lib | |
ready to use | |
lame_enc.lib 2021-01-07 12:04 51,558 | |
lame_enc.exp 2021-01-07 12:04 30,949 | |
*** not for x64 *** error 0xc000007b with lame_enc.dll | |
------------------------------------------------------------------------ | |
convert mp3 to wav for x64 (from rarewares) | |
Audacity_LAME/lame3.100-64-20200409.zip | |
lame.exe 2020-04-09 20:43 1,760,256 | |
lame_enc.dll 2020-04-09 20:43 1,473,024 | |
Audacity_LAME/lame-3.100.tar.gz /lame-3.100/include | |
lame.h 2017-09-07 04:33 50,053 | |
create def | |
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\dumpbin.exe" /exports lame_enc.dll > lame_enc_tmp.def -> edit -> lame_enc.def | |
create lib | |
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\lib.exe" /def:lame_enc.def /machine:x64 /out:lame_enc.lib | |
ready to use | |
lame_enc.lib 2021-01-08 12:01 4,442 | |
lame_enc.exp 2021-01-08 12:01 7,730 | |
*** some functions are NOT exported *** | |
lame_set_VBR | |
lame_decoder (in lame_main.c ?) | |
in lame.h | |
OBSOLETE: | |
lame_decode... functions are there to keep old code working | |
but it is strongly recommended to replace calls by hip_decode... | |
function calls, see above. | |
------------------------------------------------------------------------ | |
*/ | |
#include <windows.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <curl/curl.h> | |
// lame_enc.dll | |
#include <lame.h> | |
// libmpg123-0.dll (use partial definition from external functions) | |
#if 0 | |
#include <mpg123.h> | |
#include <fmt123.h> | |
#else | |
struct mpg123_handle_struct; | |
typedef struct mpg123_handle_struct mpg123_handle; | |
struct mpg123_handle_struct{ int fake; }; // fake | |
enum mpg123_errors { | |
MPG123_DONE = -12, MPG123_NEW_FORMAT = -11, MPG123_NEED_MORE = -10, | |
MPG123_ERR = -1, MPG123_OK = 0, | |
MPG123_BAD_OUTFORMAT, MPG123_BAD_CHANNEL, MPG123_BAD_RATE, | |
MPG123_ERR_16TO8TABLE, MPG123_BAD_PARAM, MPG123_BAD_BUFFER, | |
MPG123_OUT_OF_MEM, MPG123_NOT_INITIALIZED, | |
MPG123_BAD_DECODER, MPG123_BAD_HANDLE, | |
MPG123_NO_BUFFERS, MPG123_BAD_RVA, MPG123_NO_GAPLESS, MPG123_NO_SPACE, | |
MPG123_BAD_TYPES, MPG123_BAD_BAND, MPG123_ERR_NULL, MPG123_ERR_READER, | |
MPG123_NO_SEEK_FROM_END, MPG123_BAD_WHENCE, MPG123_NO_TIMEOUT, | |
MPG123_BAD_FILE, MPG123_NO_SEEK, MPG123_NO_READER, MPG123_BAD_PARS, | |
MPG123_BAD_INDEX_PAR, MPG123_OUT_OF_SYNC, MPG123_RESYNC_FAIL, MPG123_NO_8BIT, | |
MPG123_BAD_ALIGN, MPG123_NULL_BUFFER, MPG123_NO_RELSEEK, MPG123_NULL_POINTER, | |
MPG123_BAD_KEY, MPG123_NO_INDEX, MPG123_INDEX_FAIL, MPG123_BAD_DECODER_SETUP, | |
MPG123_MISSING_FEATURE, MPG123_BAD_VALUE, MPG123_LSEEK_FAILED, | |
MPG123_BAD_CUSTOM_IO, MPG123_LFS_OVERFLOW, MPG123_INT_OVERFLOW | |
}; | |
const char *mpg123_plain_strerror(int err); | |
const char *mpg123_strerror(mpg123_handle *mh); | |
int mpg123_errcode(mpg123_handle *mh); | |
const char **mpg123_decoders(void); | |
const char **mpg123_supported_decoders(void); | |
int mpg123_decoder(mpg123_handle *mh, const char *decoder_name); | |
const char *mpg123_current_decoder(mpg123_handle *mh); | |
int mpg123_init(void); | |
void mpg123_exit(void); | |
mpg123_handle *mpg123_new(const char *dec, int *err); | |
void mpg123_delete(mpg123_handle *mh); | |
void mpg123_free(void *p); | |
enum mpg123_parms { | |
MPG123_VERBOSE = 0, MPG123_FLAGS, MPG123_ADD_FLAGS, MPG123_FORCE_RATE, | |
MPG123_DOWN_SAMPLE, MPG123_RVA, MPG123_DOWNSPEED, MPG123_UPSPEED, | |
MPG123_START_FRAME, MPG123_DECODE_FRAMES, | |
MPG123_ICY_INTERVAL, MPG123_OUTSCALE, | |
MPG123_TIMEOUT, MPG123_REMOVE_FLAGS, MPG123_RESYNC_LIMIT, MPG123_INDEX_SIZE, | |
MPG123_PREFRAMES, MPG123_FEEDPOOL, MPG123_FEEDBUFFER, MPG123_FREEFORMAT_SIZE | |
}; | |
enum mpg123_param_flags { | |
MPG123_FORCE_MONO = 0x7, MPG123_MONO_LEFT = 0x1, MPG123_MONO_RIGHT = 0x2, | |
MPG123_MONO_MIX = 0x4, MPG123_FORCE_STEREO = 0x8, MPG123_FORCE_8BIT = 0x10, | |
MPG123_QUIET = 0x20, MPG123_GAPLESS = 0x40, MPG123_NO_RESYNC = 0x80, | |
MPG123_SEEKBUFFER = 0x100, MPG123_FUZZY = 0x200, MPG123_FORCE_FLOAT = 0x400, | |
MPG123_PLAIN_ID3TEXT = 0x800, MPG123_IGNORE_STREAMLENGTH = 0x1000, | |
MPG123_SKIP_ID3V2 = 0x2000, MPG123_IGNORE_INFOFRAME = 0x4000, | |
MPG123_AUTO_RESAMPLE = 0x8000, MPG123_PICTURE = 0x10000, | |
MPG123_NO_PEEK_END = 0x20000, MPG123_FORCE_SEEKABLE = 0x40000, | |
MPG123_STORE_RAW_ID3 = 0x80000, MPG123_FORCE_ENDIAN = 0x100000, | |
MPG123_BIG_ENDIAN = 0x200000, MPG123_NO_READAHEAD = 0x400000, | |
MPG123_FLOAT_FALLBACK = 0x800000, MPG123_NO_FRANKENSTEIN = 0x1000000 | |
}; | |
int mpg123_param(mpg123_handle *mh, enum mpg123_parms type, long v, double fv); | |
size_t mpg123_outblock(mpg123_handle *mh); | |
int mpg123_open(mpg123_handle *mh, const char *path); | |
int mpg123_close(mpg123_handle *mh); | |
int mpg123_getformat(mpg123_handle *mh, long *rate, int *ch, int *enc); | |
int mpg123_getformat2(mpg123_handle *mh, long *rate, int *ch, int *enc, int f); | |
int mpg123_read(mpg123_handle *mh, void *omem, size_t omemsz, size_t *done); | |
int mpg123_feed(mpg123_handle *mh, const unsigned char *in, size_t sz); | |
int mpg123_decode(mpg123_handle *mh, const unsigned char *imem, size_t imemsz, | |
void *omem, size_t omemsz, size_t *done); | |
int mpg123_decode_frame(mpg123_handle *mh, | |
off_t *num, unsigned char **audio, size_t *bytes); | |
int mpg123_framebyframe_decode(mpg123_handle *mh, | |
off_t *num, unsigned char **audio, size_t *bytes); | |
int mpg123_framebyframe_next(mpg123_handle *mh); | |
int mpg123_framedata(mpg123_handle *mh, | |
unsigned long *header, unsigned char **bodydata, size_t *bodybytes); | |
off_t mpg123_framepos(mpg123_handle *mh); | |
#endif | |
// SDL *steals* the main function | |
// so with -link /SUBSYSTEM:CONSOLE SDL2main.lib SDL2.lib shell32.lib | |
#define SDL_MAIN_HANDLED | |
#include <SDL.h> | |
#include <SDL_mixer.h> | |
#define FAKE_AGENT "curl/7.74.0" | |
#define COOKIEJAR_FILE "test_pico_waveout_cookiejar.txt" | |
#define CRT_FILE "curl-ca-bundle.crt" | |
#define REF_FILE_WAV "test_pico_waveout_out.wav" | |
#define REF_FILE_MP3 REF_FILE_WAV".mp3" | |
#define MP3_FILE "test_pico_waveout_out.mp3" | |
#define WAV_FILE MP3_FILE".wav" | |
#define TEST_SERVER "https://soundeffect-lab.info" | |
#define TEST_URL TEST_SERVER"/sound/button/mp3/decision3.mp3" | |
#if 1 | |
#define PCM_SIZE 8192 | |
#define MP3_SIZE 8192 | |
int test_lame_encode(char *mp3fn, char *wavfn) | |
{ | |
lame_t lm = lame_init(); | |
lame_set_in_samplerate(lm, 44100); | |
// lame_set_VBR(lm, vbr_default); // lame_set_VBR is NOT exported on x64 ? | |
lame_init_params(lm); | |
short int pcm_buffer[PCM_SIZE * 2]; | |
unsigned char mp3_buffer[MP3_SIZE]; | |
FILE *pcm = fopen(wavfn, "rb"); | |
FILE *mp3 = fopen(mp3fn, "wb"); | |
fread(pcm_buffer, 44, 1, pcm); // skip wav header | |
while(1){ | |
int rd = fread(pcm_buffer, 2 * sizeof(short int), PCM_SIZE, pcm); | |
int wr = rd == 0 ? lame_encode_flush(lm, mp3_buffer, MP3_SIZE) : | |
lame_encode_buffer_interleaved(lm, pcm_buffer, rd, mp3_buffer, MP3_SIZE); | |
fwrite(mp3_buffer, wr, 1, mp3); | |
if(!rd) break; | |
} | |
fclose(mp3); | |
fclose(pcm); | |
lame_close(lm); | |
return 0; | |
} | |
int test_lame_decode(char *wavfn, char *mp3fn) | |
{ | |
// lame_decoder is NOT exported ? | |
//lame_decoder(lame_t gfp, FILE * outf, char *inPath, char *outPath) | |
return 0; | |
} | |
#endif | |
#if 1 | |
typedef struct _test_mpg123_io { | |
char *ofn, *ifn; | |
} test_mpg123_io; | |
int test_mpg123_convertor(mpg123_handle *mh, void *p) | |
{ | |
test_mpg123_io *q = (test_mpg123_io *)p; | |
char *wavfn = q->ofn, *mp3fn = q->ifn; | |
fprintf(stdout, "converting: %s\n", mp3fn); | |
mpg123_open(mh, mp3fn); | |
long rate; // 44100 | |
int ch, enc; // 2, 208 = 0xD0 = MPG123_ENC_SIGNED_16 | |
mpg123_getformat(mh, &rate, &ch, &enc); | |
fprintf(stdout, "rate: %ld, ch: %d, enc: %d\n", rate, ch, enc); | |
size_t buffer_size = mpg123_outblock(mh); // 4608 (= 4096 + 512 ?) | |
unsigned char *buffer = (unsigned char *)malloc(buffer_size); | |
if(buffer){ | |
fprintf(stdout, "buffer_size: %zu\n", buffer_size); | |
fprintf(stdout, "write: %s\n", wavfn); | |
FILE *fp = fopen(wavfn, "wb"); | |
if(fp){ | |
unsigned char wav_header[] = { | |
0x52, 0x49, 0x46, 0x46, // 'RIFF' | |
0x24, 0x00, 0x00, 0x00, // * total + 12 + 16 + 8 = wavefilesize - 8 | |
0x57, 0x41, 0x56, 0x45, // 'WAVE' | |
0x66, 0x6d, 0x74, 0x20, // 'fmt ' | |
0x10, 0x00, 0x00, 0x00, // fmt chunk 16 bytes (linear PCM) | |
0x01, 0x00, // fmt 0x0001 = no compressed PCM | |
0x02, 0x00, // ch 0x0002 | |
0x44, 0xac, 0x00, 0x00, // sampling frequency 0x0000AC44 = 44100 | |
0x10, 0xb1, 0x02, 0x00, // bytes per sec 0x0002b110 = freq * 2 * 2 | |
0x04, 0x00, // block size 0x0004 = (16 bit / 8 bit) x 2 | |
0x10, 0x00, // bits per sample 0x0010 | |
0x64, 0x61, 0x74, 0x61, // 'data' | |
0x00, 0x00, 0x00, 0x00 // * total bytes | |
}; | |
fwrite(wav_header, sizeof(wav_header), 1, fp); | |
size_t done, total = 0; | |
while(mpg123_read(mh, buffer, buffer_size, &done) == MPG123_OK){ | |
fwrite(buffer, done, 1, fp); | |
total += done; | |
} | |
fprintf(stdout, "total: %zu\n", total); | |
fflush(fp); | |
int32_t bytes = (int32_t)total; // *** CAUTION *** | |
fseek(fp, 40, SEEK_SET); // data size (total bytes) | |
fwrite((char *)&bytes, sizeof(int32_t), 1, fp); | |
bytes += 12 + 16 + 8; | |
fseek(fp, 4, SEEK_SET); // RIFF size (wavefilesize - 8) | |
fwrite((char *)&bytes, sizeof(int32_t), 1, fp); | |
fclose(fp); | |
} | |
free(buffer); | |
} | |
mpg123_close(mh); | |
return 0; | |
} | |
// http://mpg123.org/api/extract__frames_8c_source.shtml | |
int test_mpg123_header(mpg123_handle *mh, void *p) | |
{ | |
test_mpg123_io *q = (test_mpg123_io *)p; | |
char *wavfn = q->ofn, *mp3fn = q->ifn; | |
fprintf(stdout, "mp3 header: %s\n", mp3fn); | |
int ret = mpg123_open(mh, mp3fn); | |
if(ret != MPG123_OK) return 1; | |
size_t cnt = 0; | |
while(1){ | |
ret = mpg123_framebyframe_next(mh); | |
if(ret != MPG123_OK && ret != MPG123_NEW_FORMAT) break; | |
unsigned long header; | |
unsigned char *buf; | |
size_t bytes; | |
if(mpg123_framedata(mh, &header, &buf, &bytes) == MPG123_OK){ | |
unsigned char hbuf[4]; | |
for(int i = 0; i < 4; ++i) | |
hbuf[i] = (unsigned char)((header >> ((3-i)*8)) & 0x0FF); | |
fprintf(stdout, "%02x%02x%02x%02x:", hbuf[0], hbuf[1], hbuf[2], hbuf[3]); | |
fprintf(stdout, "%02x %02x %02x %02x\n", buf[0], buf[1], buf[2], buf[3]); | |
fprintf(stdout, "%zu: header %08lx (%zu bytes)\n", ++cnt, header, bytes); | |
} | |
} | |
if(ret != MPG123_DONE) fprintf(stdout, "-error: %s\n", mpg123_strerror(mh)); | |
fprintf(stdout, "-done: %zu MPEG frames\n", cnt); | |
mpg123_close(mh); | |
return 0; | |
} | |
int test_mpg123_decode(int (*worker)(mpg123_handle *, void *), void *p) | |
{ | |
int ret = 0; | |
mpg123_init(); | |
const char **declist = mpg123_decoders(); | |
if(declist) | |
for(const char **p = declist; *p; ++p) | |
fprintf(stdout, " decorder: [%s]\n", *p); | |
const char **decsup = mpg123_supported_decoders(); | |
if(decsup) | |
for(const char **p = decsup; *p; ++p) | |
fprintf(stdout, " decorder supported: [%s]\n", *p); | |
// test data output by decorder ... | |
// NULL same as "AVX" same as "x86-64" | |
// NULL not same "generic" | |
// NULL not same "generic_dither" | |
// "generic" not same "generic_dither" | |
const char *decoder_new = NULL; // "AVX" "x86-64" "generic" "generic_dither" | |
mpg123_handle *mh = mpg123_new(decoder_new, &ret); | |
if(!mh){ | |
fprintf(stdout, "new mpg123_handle: %s\n", mpg123_plain_strerror(ret)); | |
}else{ | |
const char *decname = mpg123_current_decoder(mh); | |
if(decname){ | |
fprintf(stdout, "current decorder: [%s]\n", decname); | |
if(mpg123_decoder(mh, decname) != MPG123_OK) | |
fprintf(stdout, " setting current decoder: %s\n", mpg123_strerror(mh)); | |
} | |
ret = mpg123_param(mh, MPG123_REMOVE_FLAGS, MPG123_IGNORE_INFOFRAME, 0); | |
if(ret){ | |
fprintf(stdout, "error: %s\n", mpg123_strerror(mh)); | |
}else{ | |
worker(mh, p); | |
} | |
mpg123_delete(mh); | |
} | |
mpg123_exit(); | |
return 0; | |
} | |
#endif | |
#if 1 | |
int test_SDL2_play_mp3(char *fn) | |
{ | |
SDL_SetMainReady(); | |
if(SDL_Init(SDL_INIT_AUDIO)){ // SDL_INIT_EVERYTHING | |
SDL_Log("Unable to initialize SDL: %s", SDL_GetError()); | |
return 1; | |
} | |
#if 0 | |
SDL_Window *w = SDL_CreateWindow("SDL2 test", | |
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, | |
SDL_WINDOW_FULLSCREEN); | |
SDL_Renderer *renderer = SDL_CreateRenderer(w, -1, 0); | |
#endif | |
if(SDL_InitSubSystem(SDL_INIT_AUDIO)){ | |
SDL_Log("Unable to initialize SDL SybSystem: %s", SDL_GetError()); | |
SDL_Quit(); | |
return 2; | |
} | |
#if 0 | |
SDL_AudioCVT cvt; | |
SDL_BuildAudioCVT(&cvt, AUDIO_S16, 2, 48000, AUDIO_S16, 2, 48000); | |
SDL_assert(cvt.needed); | |
cvt.len = 1024 * 2 * 4; | |
fprintf(stdout, "%d, %d\n", cvt.len, cvt.len_mult); | |
cvt.buf = (Uint8 *)SDL_malloc(cvt.len * cvt.len_mult); | |
for(int i = 0; i < cvt.len; ++i) | |
cvt.buf[i] = 0; | |
SDL_ConvertAudio(&cvt); // cvt.buf has cvt.len_cvt bytes | |
#endif | |
int mixflag = MIX_INIT_MP3; | |
if(Mix_Init(mixflag) != mixflag){ | |
SDL_Log("Unable to initialize SDL_mixer: %s", Mix_GetError()); | |
}else{ | |
if(Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 4096) < 0){ | |
SDL_Log("Failure Mix_OpenAudio: %s", Mix_GetError()); | |
}else{ | |
fprintf(stdout, "playing: %s\n", fn); | |
Mix_Music *mus = Mix_LoadMUS(fn); | |
if(!mus){ | |
SDL_Log("Failure Mix_LoadMUS: %s", Mix_GetError()); | |
}else{ | |
Mix_VolumeMusic(128); // 128: max | |
Mix_PlayMusic(mus, 1); // -1: infinite | |
// while(!SDL_QuitRequested()){ SDL_Delay(250); } | |
while(Mix_PlayingMusic()){ SDL_Delay(250); } | |
Mix_FreeMusic(mus); | |
} | |
Mix_CloseAudio(); | |
} | |
Mix_Quit(); | |
} | |
SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
SDL_Quit(); | |
return 0; | |
} | |
#endif | |
#if 1 | |
size_t cb_write(char *buf, size_t sz, size_t n, void *p) | |
{ | |
size_t wb = sz * n; | |
fwrite(buf, sz, n, (FILE *)p); | |
return wb; | |
} | |
int test_curl_get_mp3(char *fn, char *url, char *cookiejar) | |
{ | |
curl_global_init(CURL_GLOBAL_ALL); | |
CURL *hc = curl_easy_init(); | |
FILE *fp = fopen(fn, "wb"); | |
curl_easy_setopt(hc, CURLOPT_WRITEDATA, fp); | |
curl_easy_setopt(hc, CURLOPT_WRITEFUNCTION, cb_write); | |
// curl_easy_setopt(hc, CURLOPT_VERBOSE, 1); | |
// curl_easy_setopt(hc, CURLOPT_HEADER, 1); | |
curl_easy_setopt(hc, CURLOPT_NOPROGRESS, 1); | |
curl_easy_setopt(hc, CURLOPT_TCP_KEEPALIVE, 1); | |
curl_easy_setopt(hc, CURLOPT_MAXREDIRS, 50); | |
// curl_easy_setopt(hc, CURLOPT_FOLLOWLOCATION, 1); | |
curl_easy_setopt(hc, CURLOPT_USERAGENT, FAKE_AGENT); | |
curl_easy_setopt(hc, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS); | |
curl_easy_setopt(hc, CURLOPT_CAINFO, CRT_FILE); | |
curl_easy_setopt(hc, CURLOPT_COOKIEJAR, cookiejar); | |
curl_easy_setopt(hc, CURLOPT_URL, url); | |
CURLcode r = curl_easy_perform(hc); | |
fclose(fp); | |
curl_easy_cleanup(hc); | |
curl_global_cleanup(); | |
return 0; | |
} | |
#endif | |
int main(int ac, char **av) | |
{ | |
fprintf(stdout, "sizeof(size_t): %zu\n", sizeof(size_t)); | |
#if 1 | |
fprintf(stdout, "version: [%s]\n", curl_version()); // dont free | |
test_curl_get_mp3(MP3_FILE, TEST_URL, COOKIEJAR_FILE); | |
#endif | |
#if 1 | |
fprintf(stdout, "use SDL2 Audio\n"); | |
test_SDL2_play_mp3(MP3_FILE); | |
#endif | |
#if 1 | |
fprintf(stdout, "use libmpg123-0.dll\n"); | |
test_mpg123_io p = {WAV_FILE, MP3_FILE}; | |
test_mpg123_decode(test_mpg123_header, &p); | |
test_mpg123_decode(test_mpg123_convertor, &p); | |
fprintf(stdout, "playing: %s\n", WAV_FILE); | |
PlaySound(WAV_FILE, NULL, SND_FILENAME); // SND_LOOP | |
#endif | |
#if 1 | |
fprintf(stdout, "use lame 3.100\n"); | |
test_lame_encode(REF_FILE_MP3, REF_FILE_WAV); | |
test_SDL2_play_mp3(REF_FILE_MP3); | |
test_lame_decode(WAV_FILE, MP3_FILE); | |
fprintf(stdout, "playing: %s\n", WAV_FILE); | |
PlaySound(WAV_FILE, NULL, SND_FILENAME); // SND_LOOP | |
#endif | |
fprintf(stdout, "playing: %s\n", REF_FILE_WAV); | |
PlaySound(REF_FILE_WAV, NULL, SND_FILENAME); // SND_LOOP | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment