proper r18 support - no more custom "tremor" lib

This commit is contained in:
dborth 2009-09-15 06:07:44 +00:00
parent ffb8c8945f
commit acf54f521e
5 changed files with 221 additions and 17 deletions

View File

@ -47,7 +47,7 @@ LIBS := -lpng -lmxml -lfat -lz -logc -lfreetype
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(CURDIR)
LIBDIRS := $(PORTLIBS)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
@ -100,7 +100,7 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
-L$(LIBOGC_LIB)
-L$(LIBOGC_LIB) -I$(PORTLIBS)/include/freetype2
export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET)
.PHONY: $(BUILD) clean

View File

@ -42,13 +42,13 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref
# any extra libraries we wish to link with
#---------------------------------------------------------------------------------
LIBS := -ldb -ldi -lpng -lmxml -lwiikeyboard \
-lfat -lwiiuse -lz -lbte -logc -lasnd -ltremor -lfreetype -ltinysmb
-lfat -lwiiuse -lz -lbte -logc -lasnd -lvorbisidec -lfreetype -ltinysmb
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(CURDIR)
LIBDIRS := $(PORTLIBS) -I$(PORTLIBS)/include/freetype2
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional

View File

@ -52,9 +52,9 @@ void GuiSound::Play()
case SOUND_OGG:
voice = 0;
if(loop)
PlayOgg(mem_open((char *)sound, length), 0, OGG_INFINITE_TIME);
PlayOgg((char *)sound, length, 0, OGG_INFINITE_TIME);
else
PlayOgg(mem_open((char *)sound, length), 0, OGG_ONE_TIME);
PlayOgg((char *)sound, length, 0, OGG_ONE_TIME);
SetVolumeOgg(255*(volume/100.0));
break;
}

View File

@ -2,6 +2,7 @@
Copyright (c) 2008 Francisco Muñoz 'Hermes' <www.elotrolado.net>
All rights reserved.
Proper (standard) vorbis usage by Tantric, 2009
Threading modifications/corrections by Tantric, 2009
Redistribution and use in source and binary forms, with or without modification, are
@ -31,6 +32,207 @@
#include "oggplayer.h"
#include <gccore.h>
#include <unistd.h>
#include <string.h>
/* functions to read the Ogg file from memory */
static struct
{
char *mem;
int size;
int pos;
} file[4];
static int f_read(void * punt, int bytes, int blocks, int *f)
{
int b;
int c;
int d;
if (bytes * blocks <= 0)
return 0;
blocks = bytes * blocks;
c = 0;
while (blocks > 0)
{
b = blocks;
if (b > 4096)
b = 4096;
if (*f >= 0x666 && *f <= 0x669)
{
d = (*f) - 0x666;
if (file[d].size == 0)
return -1;
if ((file[d].pos + b) > file[d].size)
b = file[d].size - file[d].pos;
if (b > 0)
{
memcpy(punt, file[d].mem + file[d].pos, b);
file[d].pos += b;
}
}
else
b = read(*f, ((char *) punt) + c, b);
if (b <= 0)
{
return c / bytes;
}
c += b;
blocks -= b;
}
return c / bytes;
}
static int f_seek(int *f, long offset, int mode)
{
int k, d;
mode &= 3;
if (*f >= 0x666 && *f <= 0x669)
{
d = (*f) - 0x666;
k = 0;
if (file[d].size == 0)
return -1;
if (mode == 0)
{
if ((offset) >= file[d].size)
{
file[d].pos = file[d].size;
k = -1;
}
else if ((offset) < 0)
{
file[d].pos = 0;
k = -1;
}
else
file[d].pos = offset;
}
if (mode == 1)
{
if ((file[d].pos + offset) >= file[d].size)
{
file[d].pos = file[d].size;
k = -1;
}
else if ((file[d].pos + offset) < 0)
{
file[d].pos = 0;
k = -1;
}
else
file[d].pos += offset;
}
if (mode == 2)
{
if ((file[d].size + offset) >= file[d].size)
{
file[d].pos = file[d].size;
k = -1;
}
else if ((file[d].size + offset) < 0)
{
file[d].pos = 0;
k = -1;
}
else
file[d].pos = file[d].size + offset;
}
}
else
k = lseek(*f, (int) offset, mode);
if (k < 0)
k = -1;
else
k = 0;
return k;
}
static int f_close(int *f)
{
int d;
if (*f >= 0x666 && *f <= 0x669)
{
d = (*f) - 0x666;
file[d].size = 0;
file[d].pos = 0;
if (file[d].mem)
{
file[d].mem = (void *) 0;
}
return 0;
}
else
return close(*f);
return 0;
}
static long f_tell(int *f)
{
int k, d;
if (*f >= 0x666 && *f <= 0x669)
{
d = (*f) - 0x666;
k = file[d].pos;
}
else
k = lseek(*f, 0, 1);
return (long) k;
}
static int mem_open(char * ogg, int size)
{
static int one = 1;
int n;
if (one)
{
one = 0;
for (n = 0; n < 4; n++)
file[n].size = 0;
}
for (n = 0; n < 4; n++)
{
if (file[n].size == 0)
{
file[n].mem = ogg;
file[n].size = size;
file[n].pos = 0;
return (0x666 + n);
}
}
return -1;
}
static int mem_close(int fd)
{
if (fd >= 0x666 && fd <= 0x669) // it is a memory file descriptor?
{
fd -= 0x666;
file[fd].size = 0;
return 0;
}
else
return f_close(&fd);
}
static ov_callbacks callbacks = {
(size_t (*)(void *, size_t, size_t, void *)) f_read,
(int (*)(void *, ogg_int64_t, int)) f_seek,
(int (*)(void *)) f_close,
(long (*)(void *)) f_tell
};
/* OGG control */
@ -236,11 +438,18 @@ void StopOgg()
}
}
int PlayOgg(int fd, int time_pos, int mode)
int PlayOgg(char * buf, int buflen, int time_pos, int mode)
{
StopOgg();
private_ogg.fd = fd;
private_ogg.fd = mem_open(buf, buflen);
if (private_ogg.fd < 0)
{
private_ogg.fd = -1;
return -1;
}
private_ogg.mode = mode;
private_ogg.eof = 0;
private_ogg.volume = 127;
@ -250,12 +459,7 @@ int PlayOgg(int fd, int time_pos, int mode)
if (time_pos > 0)
private_ogg.seek_time = time_pos;
if (fd < 0)
{
private_ogg.fd = -1;
return -1;
}
if (ov_open((void *) &private_ogg.fd, &private_ogg.vf, NULL, 0) < 0)
if (ov_open_callbacks((void *) &private_ogg.fd, &private_ogg.vf, NULL, 0, callbacks) < 0)
{
mem_close(private_ogg.fd); // mem_close() can too close files from devices
private_ogg.fd = -1;

View File

@ -30,8 +30,8 @@
#define __OGGPLAYER_H__
#include <asndlib.h>
#include "tremor/ivorbiscodec.h"
#include "tremor/ivorbisfile.h"
#include <tremor/ivorbiscodec.h>
#include <tremor/ivorbisfile.h>
#ifdef __cplusplus
extern "C"
@ -68,7 +68,7 @@ extern "C"
*/
int PlayOgg(int fd, int time_pos, int mode);
int PlayOgg(char * buf, int buflen, int time_pos, int mode);
/*------------------------------------------------------------------------------------------------------------------------------------------------------*/