int AalibUnload(int channel) { if ((channel<1)||(channel>48)) { return PSPAALIB_ERROR_INVALID_CHANNEL; } channels[channel].initialized=FALSE; if ((PSPAALIB_CHANNEL_WAV_1<=channel)&&(channel<=PSPAALIB_CHANNEL_WAV_32)) { return UnloadWav(channel-PSPAALIB_CHANNEL_WAV_1); } if ((PSPAALIB_CHANNEL_OGG_1<=channel)&&(channel<=PSPAALIB_CHANNEL_OGG_10)) { return UnloadOgg(channel-PSPAALIB_CHANNEL_OGG_1); } if ((PSPAALIB_CHANNEL_SCEMP3_1<=channel)&&(channel<=PSPAALIB_CHANNEL_SCEMP3_2)) { return UnloadSceMp3(channel-PSPAALIB_CHANNEL_SCEMP3_1); } if ((PSPAALIB_CHANNEL_AT3_1<=channel)&&(channel<=PSPAALIB_CHANNEL_AT3_2)) { return UnloadAt3(channel-PSPAALIB_CHANNEL_AT3_1); } return PSPAALIB_ERROR_INVALID_CHANNEL; }
int LoadWav(cccUCS2* filename,int channel,int loadToRam) { if ((channel<0)||(channel>31)) { return PSPAALIB_ERROR_WAV_INVALID_CHANNEL; } if (streamsWav[channel].initialized) UnloadWav(channel); int chunks=0,size=0; short compressionCode=0; char temp[5]; temp[4]='\0'; streamsWav[channel].loadToRam=loadToRam; streamsWav[channel].file=sceIoOpenUCS2(filename,PSP_O_RDONLY,0777); if (streamsWav[channel].file<=0) { return PSPAALIB_ERROR_WAV_INVALID_FILE; } sceIoRead(streamsWav[channel].file,temp,4); if (strcmp(temp,"RIFF")) { sceIoClose(streamsWav[channel].file); return PSPAALIB_ERROR_WAV_INVALID_FILE; } sceIoRead(streamsWav[channel].file,&size,4); sceIoRead(streamsWav[channel].file,temp,4); if (strcmp(temp,"WAVE")) { sceIoClose(streamsWav[channel].file); return PSPAALIB_ERROR_WAV_INVALID_FILE; } while (chunks<2) { sceIoRead(streamsWav[channel].file,temp,4); if (!strcmp(temp,"fmt ")) { sceIoRead(streamsWav[channel].file,&size,4); sceIoRead(streamsWav[channel].file,&compressionCode,2); if ((compressionCode!=0)&&(compressionCode!=1)) { sceIoClose(streamsWav[channel].file); return PSPAALIB_ERROR_WAV_COMPRESSED_FILE; } sceIoRead(streamsWav[channel].file,&(streamsWav[channel].numChannels),2); sceIoRead(streamsWav[channel].file,&(streamsWav[channel].sampleRate),4); sceIoRead(streamsWav[channel].file,&(streamsWav[channel].bytesPerSecond),4); sceIoLseek(streamsWav[channel].file,2,PSP_SEEK_CUR); sceIoRead(streamsWav[channel].file,&(streamsWav[channel].sigBytes),2); streamsWav[channel].sigBytes=streamsWav[channel].sigBytes>>3; sceIoLseek(streamsWav[channel].file,size-16,PSP_SEEK_CUR); chunks++; continue; } if (!strcmp(temp,"data")) { if (chunks<1) { sceIoClose(streamsWav[channel].file); return PSPAALIB_ERROR_WAV_INVALID_FILE; } sceIoRead(streamsWav[channel].file,&(streamsWav[channel].dataLength),4); streamsWav[channel].dataLocation=sceIoLseek(streamsWav[channel].file,0,PSP_SEEK_CUR); if (streamsWav[channel].loadToRam) { streamsWav[channel].data=(char*) malloc(streamsWav[channel].dataLength); if(!streamsWav[channel].data) { sceIoClose(streamsWav[channel].file); return PSPAALIB_ERROR_WAV_INSUFFICIENT_RAM; } sceIoRead(streamsWav[channel].file,streamsWav[channel].data,streamsWav[channel].dataLength); } else { streamsWav[channel].data=(char*) malloc(2*1024*streamsWav[channel].sigBytes*streamsWav[channel].numChannels*streamsWav[channel].sampleRate/PSP_SAMPLE_RATE); if(!streamsWav[channel].data) { sceIoClose(streamsWav[channel].file); return PSPAALIB_ERROR_WAV_INSUFFICIENT_RAM; } } streamsWav[channel].dataPos=0; chunks++; continue; } sceIoRead(streamsWav[channel].file,&size,4); sceIoLseek(streamsWav[channel].file,size,PSP_SEEK_CUR); }