| | |
| | | /* |
| | | Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> |
| | | Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> |
| | | |
| | | This software is provided 'as-is', without any express or implied |
| | | warranty. In no event will the authors be held liable for any damages |
| | |
| | | Uint32 len = 0; |
| | | Uint8 *data = NULL; |
| | | int cvtfreq = 0; |
| | | int cvtchans = 0; |
| | | int bitsize = 0; |
| | | int blockalign = 0; |
| | | int avgbytes = 0; |
| | | SDL_RWops *io = NULL; |
| | | |
| | | /* Enable standard application logging */ |
| | | /* Enable standard application logging */ |
| | | SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); |
| | | |
| | | if (argc != 4) { |
| | | SDL_Log("USAGE: %s in.wav out.wav newfreq\n", argv[0]); |
| | | if (argc != 5) { |
| | | SDL_Log("USAGE: %s in.wav out.wav newfreq newchans\n", argv[0]); |
| | | return 1; |
| | | } |
| | | |
| | | cvtfreq = SDL_atoi(argv[3]); |
| | | cvtchans = SDL_atoi(argv[4]); |
| | | |
| | | if (SDL_Init(SDL_INIT_AUDIO) == -1) { |
| | | SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError()); |
| | |
| | | } |
| | | |
| | | if (SDL_BuildAudioCVT(&cvt, spec.format, spec.channels, spec.freq, |
| | | spec.format, spec.channels, cvtfreq) == -1) { |
| | | spec.format, cvtchans, cvtfreq) == -1) { |
| | | SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to build CVT: %s\n", SDL_GetError()); |
| | | SDL_FreeWAV(data); |
| | | SDL_Quit(); |
| | |
| | | } |
| | | |
| | | bitsize = SDL_AUDIO_BITSIZE(spec.format); |
| | | blockalign = (bitsize / 8) * spec.channels; |
| | | blockalign = (bitsize / 8) * cvtchans; |
| | | avgbytes = cvtfreq * blockalign; |
| | | |
| | | SDL_WriteLE32(io, 0x46464952); /* RIFF */ |
| | | SDL_WriteLE32(io, len * cvt.len_mult + 36); |
| | | SDL_WriteLE32(io, cvt.len_cvt + 36); |
| | | SDL_WriteLE32(io, 0x45564157); /* WAVE */ |
| | | SDL_WriteLE32(io, 0x20746D66); /* fmt */ |
| | | SDL_WriteLE32(io, 16); /* chunk size */ |
| | | SDL_WriteLE16(io, 1); /* uncompressed */ |
| | | SDL_WriteLE16(io, spec.channels); /* channels */ |
| | | SDL_WriteLE16(io, SDL_AUDIO_ISFLOAT(spec.format) ? 3 : 1); /* uncompressed */ |
| | | SDL_WriteLE16(io, cvtchans); /* channels */ |
| | | SDL_WriteLE32(io, cvtfreq); /* sample rate */ |
| | | SDL_WriteLE32(io, avgbytes); /* average bytes per second */ |
| | | SDL_WriteLE16(io, blockalign); /* block align */ |
| | |
| | | return 0; |
| | | } /* main */ |
| | | |
| | | /* end of resample_test.c ... */ |
| | | /* end of testresample.c ... */ |