Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // gLibAudio by Geecko - A rock-solid, light-weight audio library.
- //
- // This work is licensed under the Creative Commons BY-SA 3.0 Unported License.
- // See LICENSE for more details.
- //
- // Please report bugs at : geecko.dev@free.fr
- #include "glibaudio.h"
- #include <pspkernel.h>
- #include <pspaudio.h>
- #include <psputility.h>
- #include <pspmp3.h>
- #include <pspdebug.h> // TODO remove
- #include <malloc.h>
- /* Global variables */
- static bool init=false;
- /* Internal functions */
- bool _gaRead(gaSound *snd)
- {
- unsigned char* data;
- int size, offset;
- sceMp3GetInfoToAddStreamData(snd->handle, &data, &size, &offset);
- sceIoLseek32(snd->file, offset, PSP_SEEK_SET);
- sceMp3NotifyAddStreamData(snd->handle, sceIoRead(snd->file, data, size));
- return false;
- }
- /* Main functions */
- void gaInit()
- {
- if (init) return;
- sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC);
- sceUtilityLoadModule(PSP_MODULE_AV_MP3);
- sceMp3InitResource();
- init = true;
- }
- void gaTerm()
- {
- if (!init) return;
- sceMp3TermResource();
- sceUtilityUnloadModule(PSP_MODULE_AV_AVCODEC);
- sceUtilityUnloadModule(PSP_MODULE_AV_MP3);
- init = false;
- }
- gaSound* gaLoad(const char *path)
- {
- if (path == NULL) return NULL;
- if (!init) gaInit();
- gaSound* snd = malloc(sizeof(gaSound));
- snd->file = sceIoOpen(path, PSP_O_RDONLY, 0777);
- snd->init.mp3StreamStart = 0;
- snd->init.mp3StreamEnd = sceIoLseek32(snd->file, 0, PSP_SEEK_END);
- snd->init.unk1 = 0;
- snd->init.unk2 = 0;
- snd->init.mp3Buf = malloc(8192);
- snd->init.mp3BufSize = 8192;
- snd->init.pcmBuf = malloc(9216);
- snd->init.pcmBufSize = 9216;
- snd->handle = sceMp3ReserveMp3Handle(&snd->init);
- _gaRead(snd);
- sceMp3Init(snd->handle);
- return snd;
- }
- void gaFree(gaSound** snd)
- {
- if (snd == NULL) return;
- if (!init) gaInit();
- sceMp3ReleaseMp3Handle((*snd)->handle);
- free((*snd)->init.mp3Buf);
- free((*snd)->init.pcmBuf);
- sceIoClose((*snd)->file);
- free(*snd);
- *snd = NULL;
- }
- void gaPlay(gaSound *snd)
- {
- if (snd == NULL) return;
- if (!init) gaInit();
- short *buf;
- sceAudioChReserve(0, 1152, PSP_AUDIO_FORMAT_STEREO);
- while (1)
- {
- if (sceMp3CheckStreamDataNeeded(snd->handle) > 0)
- {
- _gaRead(snd);
- }
- sceMp3Decode(snd->handle, &buf);
- sceAudioOutputBlocking(0, 0x8000, buf);
- }
- }
- // EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement