MCPcopy Create free account
hub / github.com/Aloshi/EmulationStation / init

Method init

src/Sound.cpp:22–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20}
21
22void Sound::init()
23{
24 if(mSampleData != NULL)
25 deinit();
26
27 if(mPath.empty())
28 return;
29
30 //load wav file via SDL
31 SDL_AudioSpec wave;
32 Uint8 * data = NULL;
33 Uint32 dlen = 0;
34 if (SDL_LoadWAV(mPath.c_str(), &wave, &data, &dlen) == NULL) {
35 LOG(LogError) << "Error loading sound \"" << mPath << "\"!\n" << " " << SDL_GetError();
36 return;
37 }
38 //build conversion buffer
39 SDL_AudioCVT cvt;
40 SDL_BuildAudioCVT(&cvt, wave.format, wave.channels, wave.freq, AUDIO_S16, 2, 44100);
41 //copy data to conversion buffer
42 cvt.len = dlen;
43 cvt.buf = new Uint8[cvt.len * cvt.len_mult];
44 memcpy(cvt.buf, data, dlen);
45 //convert buffer to stereo, 16bit, 44.1kHz
46 if (SDL_ConvertAudio(&cvt) < 0) {
47 LOG(LogError) << "Error converting sound \"" << mPath << "\" to 44.1kHz, 16bit, stereo format!\n" << " " << SDL_GetError();
48 delete[] cvt.buf;
49 }
50 else {
51 //worked. set up member data
52 SDL_LockAudio();
53 mSampleData = cvt.buf;
54 mSampleLength = cvt.len_cvt;
55 mSamplePos = 0;
56 mSampleFormat.channels = 2;
57 mSampleFormat.freq = 44100;
58 mSampleFormat.format = AUDIO_S16;
59 SDL_UnlockAudio();
60 }
61 //free wav data now
62 SDL_FreeWAV(data);
63}
64
65void Sound::deinit()
66{

Callers

nothing calls this directly

Calls 2

deinitFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected