Skip to content

Commit 557f4c3

Browse files
committed
MP3 support: more stuff
1 parent 40c4ea5 commit 557f4c3

1 file changed

Lines changed: 74 additions & 1 deletion

File tree

engine/client/m_mp3.c

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4883,9 +4883,82 @@ void STT_Init_f(void)
48834883

48844884
#ifdef AVAIL_MP3
48854885

4886+
static void *Q_drmp3_onMalloc(size_t sz, void* pUserData)
4887+
{
4888+
return BZ_Malloc(sz);
4889+
}
4890+
4891+
static void *Q_drmp3_onRealloc(void* p, size_t sz, void* pUserData)
4892+
{
4893+
return BZ_Realloc(p, sz);
4894+
}
4895+
4896+
static void Q_drmp3_onFree(void* p, void* pUserData)
4897+
{
4898+
BZ_Free(p);
4899+
}
4900+
4901+
static drmp3_allocation_callbacks Q_drmp3_cbfns = {
4902+
NULL,
4903+
Q_drmp3_onMalloc,
4904+
Q_drmp3_onRealloc,
4905+
Q_drmp3_onFree
4906+
};
4907+
4908+
static void QDECL S_MP3_Purge(sfx_t *sfx)
4909+
{
4910+
drmp3 *dec = sfx->decoder.buf;
4911+
4912+
sfx->decoder.buf = NULL;
4913+
sfx->decoder.ended = NULL;
4914+
sfx->decoder.purge = NULL;
4915+
sfx->decoder.decodedata = NULL;
4916+
4917+
drmp3_uninit(dec);
4918+
BZ_Free(dec);
4919+
4920+
sfx->loadstate = SLS_NOTLOADED;
4921+
}
4922+
4923+
static sfxcache_t *QDECL S_MP3_Locate(sfx_t *sfx, sfxcache_t *buf, ssamplepos_t start, int length)
4924+
{
4925+
// TODO
4926+
return NULL;
4927+
}
4928+
4929+
static float QDECL S_MP3_Query(sfx_t *sfx, sfxcache_t *buf, char *title, size_t titlesize)
4930+
{
4931+
// TODO
4932+
return 0;
4933+
}
4934+
48864935
static qboolean QDECL S_LoadMP3Sound (sfx_t *s, qbyte *data, size_t datalen, int sndspeed, qboolean forcedecode)
48874936
{
4888-
return false;
4937+
drmp3 *dec;
4938+
4939+
char ext[8];
4940+
COM_FileExtension(s->name, ext, sizeof(ext));
4941+
if (stricmp(ext, "mp3"))
4942+
return false;
4943+
4944+
dec = BZF_Malloc(sizeof(*dec) + datalen);
4945+
if (!dec)
4946+
return false;
4947+
4948+
if (!drmp3_init_memory(dec, data, datalen, &Q_drmp3_cbfns))
4949+
{
4950+
BZ_Free(dec);
4951+
return false;
4952+
}
4953+
4954+
s->decoder.buf = dec;
4955+
s->decoder.ended = S_MP3_Purge;
4956+
s->decoder.purge = S_MP3_Purge;
4957+
s->decoder.decodedata = S_MP3_Locate;
4958+
s->decoder.querydata = S_MP3_Query;
4959+
s->loopstart = -1;
4960+
4961+
return true;
48894962
}
48904963

48914964
#endif // AVAIL_MP3

0 commit comments

Comments
 (0)