1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +00:00

Added Tremor Ogg decoder, removed libvorbis from Makefile. OGG audio working perfectly.

Tremor is extremly similar to libogg but only uses integers (and doesn't provide an encoder). The playing problem with libvorbis was probably a float-precision related issue.

No need for make build-all.
This commit is contained in:
Reuh 2015-12-29 17:25:34 +01:00
parent c053997f96
commit e39fcc6c7b
97 changed files with 16571 additions and 15 deletions

View file

@ -15,8 +15,8 @@ There are 24 audio channels available, numbered from 0 to 23.
#include <lua.h>
#include <lauxlib.h>
#include <vorbis/codec.h>
#include <vorbis/vorbisfile.h>
#include <ivorbiscodec.h>
#include <ivorbisfile.h>
// Audio object type
typedef enum {
@ -98,17 +98,13 @@ static int audio_load(lua_State *L) {
audio->type = TYPE_OGG;
// Load audio file
if (ov_fopen(path, &audio->vf) < 0) {
FILE *file = fopen(path, "rb");
if (ov_open(file, &audio->vf, NULL, 0) < 0) {
lua_pushnil(L);
lua_pushstring(L, "input does not appear to be a valid ogg vorbis file or doesn't exist");
return 2;
}
// Some Ogg Vorbis decoding parameters
bool bigendianp = false; // bigendianness
u8 word = 2; // word size; 1 or 2 (8bits/sample or 16bits/sample)
bool sgned = true; // signed data
// Decoding Ogg Vorbis bitstream
vorbis_info* vi = ov_info(&audio->vf, -1);
if (vi == NULL) luaL_error(L, "could not retrieve ogg audio stream informations");
@ -117,7 +113,7 @@ static int audio_load(lua_State *L) {
audio->channels = vi->channels;
audio->encoding = NDSP_ENCODING_PCM16;
audio->nsamples = ov_pcm_total(&audio->vf, -1);
audio->size = audio->nsamples * word;
audio->size = audio->nsamples * audio->channels * 2; // *2 because output is PCM16 (2 bytes/sample)
if (linearSpaceFree() < audio->size) luaL_error(L, "not enough linear memory available");
audio->data = linearAlloc(audio->size);
@ -127,7 +123,7 @@ static int audio_load(lua_State *L) {
int eof = 0;
int current_section;
while (!eof) {
long ret = ov_read(&audio->vf, &audio->data[offset], 4096, bigendianp, word, sgned, &current_section);
long ret = ov_read(&audio->vf, &audio->data[offset], 4096, &current_section);
if (ret == 0) {
eof = 1;

View file

@ -41,7 +41,7 @@ Load a texture from a file. Supported formats: PNG, JPEG, BMP.
*/
static int texture_load(lua_State *L) {
const char *path = luaL_checkstring(L, 1);
u8 place = luaL_optinteger(L, 2, SF2D_PLACE_RAM); //place in vram by default
u8 place = luaL_optinteger(L, 2, SF2D_PLACE_RAM); //place in ram by default
u8 type = luaL_optinteger(L, 3, 3); //type 3 is "search at the end of the filename"
texture_userdata *texture;