/*********************************************************** synopsis: push all the game sounds onto the soundCache linked list. Not that soundCache is passed into pushSound by reference, so that the head pointer can be updated inputs: pointer to the soundCache outputs: n/a ***********************************************************/ static void bufferSounds(struct sound **soundCache) { pushSound(soundCache, "click-answer", "audio/click-answer.wav"); pushSound(soundCache, "click-shuffle", "audio/click-shuffle.wav"); pushSound(soundCache, "foundbig", "audio/foundbig.wav"); pushSound(soundCache, "found", "audio/found.wav"); pushSound(soundCache, "clear", "audio/clearword.wav"); pushSound(soundCache, "duplicate", "audio/duplicate.wav"); pushSound(soundCache, "badword", "audio/badword.wav"); pushSound(soundCache, "shuffle", "audio/shuffle.wav"); pushSound(soundCache, "clock-tick", "audio/clock-tick.wav"); pushSound(soundCache, "foundall", "audio/foundall.wav"); }
static int l_SoundLoadRaw(lua_State * lState) { const char *szFName = luaL_checkstring(lState, 1); unsigned int nSize; // open palette file in binary mode FILE *dsfSound = fopen(szFName, "rb"); if(dsfSound == NULL) { return luaL_error(lState, "Failed to open raw sound file '%s'", szFName); } fseek(dsfSound, 0, SEEK_END); nSize = ftell(dsfSound); rewind (dsfSound); // create new sound object, Sound obj is responsible for delete memory char *data = (char*)malloc(nSize); // make sure we have a valid pointer if(data == NULL) { fclose(dsfSound); return luaL_error(lState, "Unable to allocate %d bytes for sound memory", nSize); } // init the memory acquired and read in the data size_t nRead = fread(data, 1, nSize, dsfSound); // close the file when we are done fclose(dsfSound); // make sure we read in something if(nRead != nSize) { free(data); return luaL_error(lState, "Can only read in %d bytes of tile sound data", nRead); } // create new sound object, Sound obj is responsible for delete memory Sound ** ppSound = NULL; ppSound = (Sound**)pushSound(lState); *ppSound = (Sound*)malloc(sizeof(Sound)); if(*ppSound == NULL) { return luaL_error(lState, "Unable to allocate %d bytes for sound memory", nSize); } (*ppSound)->data = (void*)data; (*ppSound)->size = nSize; return 1; }