engine/source/gamelib/soundmix.c
// Load a sound or return index
Load a sound or return index
Load a sound or return index
int sound_load_sample(char *filename, char *packfilename, int iLog)
{
    s_soundcache *cache;
    samplestruct sample;
    static char convcache[256];
    if(!mixing_inited)
    {
        return -1;
    }
    strcpy(convcache, filename);
    lc(convcache, strlen(convcache));
    if(List_FindByName(&samplelist, convcache))
    {
        cache = &soundcache[(size_t)List_Retrieve(&samplelist)];
        if(!cache->sample.sampleptr)
        {
            if(!sound_reload_sample(cache->index) && iLog)
            {
                printf("sound_load_sample can't restore sampleptr from file '%s'!\n", filename);
            }
        }
        return cache->index;
    }
    memset(&sample, 0, sizeof(sample));
    if(!loadwave(filename, packfilename, &sample, MAX_SOUND_LEN))
    {
        if(iLog)
        {
            printf("sound_load_sample can't load sample from file '%s'!\n", filename);
        }
        return -1;
    }
    __realloc(soundcache, sound_cached);
    soundcache[sound_cached].sample = sample;
    List_GotoLast(&samplelist);
    List_InsertAfter(&samplelist, (void *)(size_t)sound_cached, convcache);
    soundcache[sound_cached].index = sound_cached;
    soundcache[sound_cached].filename = List_GetName(&samplelist);
    sound_cached++;
    return sound_cached - 1;
}
int sound_load_sample ( char * filename , char * packfilename , int iLog ) { s_soundcache * cache ; samplestruct sample ; static char convcache [ 256 ] ; if ( ! mixing_inited ) { return -1 ; } strcpy ( convcache , filename ) ; lc ( convcache , strlen ( convcache ) ) ; if ( List_FindByName ( & samplelist , convcache ) ) { cache = & soundcache [ ( size_t ) List_Retrieve ( & samplelist ) ] ; if ( ! cache -> sample . sampleptr ) { if ( ! sound_reload_sample ( cache -> index ) && iLog ) { printf ( " \n " , filename ) ; } } return cache -> index ; } memset ( & sample , 0 , sizeof ( sample ) ) ; if ( ! loadwave ( filename , packfilename , & sample , MAX_SOUND_LEN ) ) { if ( iLog ) { printf ( " \n " , filename ) ; } return -1 ; } __realloc ( soundcache , sound_cached ) ; soundcache [ sound_cached ] . sample = sample ; List_GotoLast ( & samplelist ) ; List_InsertAfter ( & samplelist , ( void * ) ( size_t ) sound_cached , convcache ) ; soundcache [ sound_cached ] . index = sound_cached ; soundcache [ sound_cached ] . filename = List_GetName ( & samplelist ) ; sound_cached ++ ; return sound_cached - 1 ; }
Load a sound or return index
Load a sound or return index
/////////////////////////////