MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / InitSoundLib

Method InitSoundLib

sndlib/sdlsound.cpp:64–120  ·  view source on GitHub ↗

Starts the sound library, maybe have it send back some information -- 3d support?

Source from the content-addressed store, hash-verified

62
63// Starts the sound library, maybe have it send back some information -- 3d support?
64int lnxsound::InitSoundLib(char mixer_type, oeApplication *sos, uint8_t max_sounds_played) {
65 SDL_AudioSpec spec;
66
67 // setup mixer
68 tMixerInit mi;
69 mi.primary_buffer = nullptr;
70 mi.primary_frequency = SOUNDLIB_SAMPLE_RATE;
71 mi.max_sounds_available = &sound_buffer_size;
72 mi.sound_cache = sound_cache;
73 mi.primary_alignment = SOUNDLIB_CHANNELS * (SOUNDLIB_SAMPLE_SIZE >> 3);
74 mi.fp_SetError = lnxsound_SetError;
75 mi.fp_ErrorText = lnxsound_ErrorText;
76 mi.p_error_code = &m_lib_error_code;
77 mi.ll_sound_ptr = ll_sound_ptr;
78
79 if (!m_mixer.Initialize(&mi)) {
80 return false;
81 } // if
82
83 int sampleCount = SOUNDLIB_DEFAULT_SAMPLES;
84 int sampleArgIndex = FindArg("-sdlSndSize");
85 if (sampleArgIndex != 0) {
86 const char *sampleCountStr = GetArg(sampleArgIndex + 1);
87 if (sampleCountStr) {
88 sampleCount = atoi(sampleCountStr);
89 if (sampleCount <= 0) {
90 sampleCount = SOUNDLIB_DEFAULT_SAMPLES;
91 }
92 }
93 }
94
95 spec.freq = SOUNDLIB_SAMPLE_RATE;
96 spec.format = SOUNDLIB_SAMPLE_SIZE == 8 ? AUDIO_U8 : AUDIO_S16SYS;
97 spec.channels = SOUNDLIB_CHANNELS;
98 spec.samples = sampleCount;
99 spec.callback = StreamAudio;
100 spec.userdata = &m_mixer;
101
102 sound_device = SDL_OpenAudioDevice(nullptr, 0, &spec, nullptr, 0);
103 if (sound_device == 0) {
104 strcpy(m_error_text, SDL_GetError());
105 return false;
106 }
107
108 mprintf(0, "Sound: Hardware configured. Kicking off stream thread...");
109 SDL_PauseAudioDevice(sound_device, 0);
110
111 m_total_sounds_played = 0;
112 m_cur_sounds_played = 0;
113 m_in_sound_frame = false;
114 m_pending_actions = false;
115 m_cache_stress_timer = 0.0f;
116 m_timer_last_frametime = -1;
117 m_sound_quality = SQT_HIGH;
118
119 return true;
120}
121

Callers 7

MusicPlayInitFunction · 0.45
InitEditGameSystemsFunction · 0.45
InitGameEditSystemsFunction · 0.45
ProcessTestKeysFunction · 0.45
InitD3Systems1Function · 0.45
finishMethod · 0.45

Calls 3

GetArgFunction · 0.85
FindArgFunction · 0.50
InitializeMethod · 0.45

Tested by

no test coverage detected