File confec.cpp changed (mode: 100644) (index 666321a..1a68e82) |
... |
... |
void csLoadSound( |
246 |
246 |
float reverbDelayFactor ){ |
float reverbDelayFactor ){ |
247 |
247 |
// Load the sound file if it does not exist in sound_loaded. |
// Load the sound file if it does not exist in sound_loaded. |
248 |
248 |
if( sound_loaded.find( file_name ) == sound_loaded.end() ){ |
if( sound_loaded.find( file_name ) == sound_loaded.end() ){ |
|
249 |
|
void *memory = nullptr; |
|
250 |
|
size_t length = 0; |
|
251 |
|
FILE *file = FileOpen( file_name.c_str(), "rb" ); |
|
252 |
|
if( file ){ |
|
253 |
|
// Adapted from cs_read_file_to_memory. |
|
254 |
|
fseek( file, 0, SEEK_END ); |
|
255 |
|
length = ftell( file ); |
|
256 |
|
fseek( file, 0, SEEK_SET ); |
|
257 |
|
memory = malloc( length ); |
|
258 |
|
(void)(fread( memory, length, 1, file ) + 1); // Discard return value |
|
259 |
|
fclose( file ); |
|
260 |
|
} |
|
261 |
|
// Process the in-memory file into a playable audio clip. |
|
262 |
|
cs_loaded_sound_t sound = { 0, 0, 0, 0, { nullptr, nullptr } }; |
249 |
263 |
if( file_name.length() >= 4 |
if( file_name.length() >= 4 |
250 |
264 |
&& file_name.substr( file_name.length() - 4 ) == ".ogg" ){ |
&& file_name.substr( file_name.length() - 4 ) == ".ogg" ){ |
251 |
|
sound_loaded[file_name] = cs_load_ogg( file_name.c_str() ); |
|
|
265 |
|
cs_read_mem_ogg( memory, length, &sound ); |
252 |
266 |
}else{ |
}else{ |
253 |
|
sound_loaded[file_name] = cs_load_wav( file_name.c_str() ); |
|
|
267 |
|
cs_read_mem_wav( memory, length, &sound ); |
254 |
268 |
} |
} |
|
269 |
|
free( memory ); |
|
270 |
|
sound_loaded[file_name] = sound; |
255 |
271 |
} |
} |
256 |
272 |
// Cancel loading if the sound file failed to load. The unplayable |
// Cancel loading if the sound file failed to load. The unplayable |
257 |
273 |
// sound stays in sound_loaded and prevents future loading attempts. |
// sound stays in sound_loaded and prevents future loading attempts. |