audio.h 2.06 KB
Newer Older
Jean-Andre Santoni's avatar
Jean-Andre Santoni committed
1
2
3
4
5
6
7
8
#ifndef AUDIO_H
#define AUDIO_H

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include "runtime.h"
9
#include "sound.h"
10
#include "decoder.h"
Jean-Andre Santoni's avatar
Jean-Andre Santoni committed
11
12
13

#define AUDIO_FRAMES (44100 / 60)

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// The following types are acceptable for pre-saturated mixing, as they meet the requirement for
// having a larger range than the saturated mixer result type of int16_t. double precision should
// be preferred on x86/amd64, and single precision on ARM. float16 could also work as an input
// but care must be taken to saturate at INT16_MAX-1 and INT16_MIN+1 due to float16 not having a
// 1:1 representation of whole numbers in the in16 range.
//
// TODO: set up appropriate compiler defs for mixer presaturate type.

typedef float   mixer_presaturate_t;
#define cvt_presaturate_to_int16(in)   ((int16_t)roundf(in))

//typedef double  mixer_presaturate_t;
//#define cvt_presaturate_to_int16(in)   (round(in))

//typedef int32_t mixer_presaturate_t;
//#define cvt_presaturate_to_int16(in)   ((int16_t)in)


32
33
34
35
36
37
38
typedef enum
{
   AUDIO_STOPPED = 0,
   AUDIO_PAUSED,
   AUDIO_PLAYING
} audio_source_state;

Jean-Andre Santoni's avatar
Jean-Andre Santoni committed
39
40
typedef struct
{
41
   //currently for WAV
42
   snd_SoundData sndta;
Jean-Andre Santoni's avatar
Jean-Andre Santoni committed
43
   unsigned bps; // bytes per sample
44
45
46
47
   
   //currently for Ogg Vorbis
   OggData *oggData;
   
Jean-Andre Santoni's avatar
Jean-Andre Santoni committed
48
   bool loop;
49
   float volume;
50
   float pitch;
51
   unsigned pos;
52
   audio_source_state state;
Jean-Andre Santoni's avatar
Jean-Andre Santoni committed
53
54
55
} audio_Source;

void lutro_audio_init();
56
void lutro_audio_deinit();
Jean-Andre Santoni's avatar
Jean-Andre Santoni committed
57
int lutro_audio_preload(lua_State *L);
58
void mixer_render(int16_t *buffer);
Jean-Andre Santoni's avatar
Jean-Andre Santoni committed
59
60

int audio_newSource(lua_State *L);
61
62
int audio_setVolume(lua_State *L);
int audio_getVolume(lua_State *L);
Jean-Andre Santoni's avatar
Jean-Andre Santoni committed
63
int audio_play(lua_State *L);
64
int audio_stop(lua_State *L);
65
66
67

int source_setLooping(lua_State *L);
int source_isLooping(lua_State *L);
68
int source_isStopped(lua_State *L);
69
int source_isPaused(lua_State *L);
70
int source_isPlaying(lua_State *L);
71
72
int source_getVolume(lua_State *L);
int source_setVolume(lua_State *L);
73
74
int source_tell(lua_State *L);
int source_seek(lua_State *L);
75
76
int source_getPitch(lua_State *L);
int source_setPitch(lua_State *L);
77

Jean-Andre Santoni's avatar
Jean-Andre Santoni committed
78
79
80
int source_gc(lua_State *L);

#endif // AUDIO_H