Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint8_t *wavData;
- SDL_AudioSpec fileSpec;
- uint32_t streamLen = 0;
- if (!SDL_LoadWAV(sWavFile.c_str(), &fileSpec, (uint8_t **)&wavData, &streamLen)) {
- std::cout << "Couldn't load audio file!\n" << SDL_GetError() << '\n';
- bSampleValid = false;
- return;
- }
- std::ofstream test;
- test.open("test.txt", std::ios::out | std::ios::trunc);
- for (int i = 0; i < streamLen; i += 2) {
- test << (wavData[i] << 8 | wavData[i + 1]) << '\n';
- }
- test.close();
- SDL_AudioCVT cvt;
- if (!SDL_BuildAudioCVT(&cvt, fileSpec.format, fileSpec.channels, fileSpec.freq,
- cge.sampleSpec.format, fileSpec.channels, fileSpec.freq)) {
- std::cout << "Failed to build cvt!\n" << SDL_GetError() << '\n';
- }
- cvt.buf = (uint8_t *)malloc(streamLen * cvt.len_mult);
- cvt.len = streamLen;
- memcpy(cvt.buf, wavData, streamLen);
- SDL_FreeWAV((uint8_t *)wavData);
- if (!SDL_ConvertAudio(&cvt)) {
- std::cout << "Failed to convert audio!\n" << SDL_GetError() << '\n';
- }
- fSample = (float *)cvt.buf;
- nSamples = cvt.len_cvt / sizeof(float) / cge.spec.channels;
- bSampleValid = true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement