-
Notifications
You must be signed in to change notification settings - Fork 0
/
audio.h
64 lines (56 loc) · 1.8 KB
/
audio.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
/*
spiffy - ZX spectrum emulator
Copyright Edward Cree, 2010-13
audio.h - audio functions
*/
#include <stdio.h>
#include <stdbool.h>
#ifdef AUDIO
#include <SDL.h>
#define MAX_SINC_RATE 32
#define SAMPLE_RATE 16000 // Audio sample rate, Hz
#define AUDIOBUFLEN (256)
#define AUDIOBITBUFLEN ((SAMPLE_RATE*MAX_SINC_RATE)/16)
#define AUDIOBITLEN ((SAMPLE_RATE**sinc_rate)/16)
#define AUDIOSYNCLEN (SAMPLE_RATE/40)
#define MAX_SINCBUFLEN (AUDIOSYNCLEN*MAX_SINC_RATE)
#define SINCBUFLEN (AUDIOSYNCLEN**sinc_rate)
#define AUDIO_WAIT 5e3
#define AUDIO_MAXWAITS 40
uint8_t *get_sinc_rate(void);
void update_sinc(uint16_t filterfactor);
void mixaudio(void *abuf, Uint8 *stream, int len);
typedef struct
{
uint8_t bits[AUDIOBITBUFLEN];
uint8_t cbuf[MAX_SINCBUFLEN];
unsigned int rp, wp; // read & write pointers for 'bits' circular buffer
unsigned int crp, cwp; // read & write pointers for 'cbuf' circular buffer
bool play; // true if tape is playing (we mute and allow skipping)
FILE *record;
bool busy[2]; // true if [core, audio] thread is using. see file 'sound' for shutdown sequence
}
audiobuf;
double sincgroups[MAX_SINC_RATE][AUDIOSYNCLEN];
void wavheader(FILE *a);
#endif /* AUDIO */
bool ay_enabled;
typedef struct
{
uint8_t reg[16]; // The programmable registers R0-R15
uint8_t regsel; // the selected register for reading/writing
bool bit[3]; // output high? A/B/C
unsigned int count[3]; // counters A/B/C
unsigned int envcount; // counter for envelope
uint8_t env; // envelope magnitude
bool envstop; // envelope stopped?
bool envrev; // envelope direction reversed?
uint8_t out[3]; // final output level A/B/C
unsigned int noise; // internal noise register
unsigned int noisecount; // counter for noise
}
ay_t;
ay_t ay;
void ay_init(ay_t *ay);
void ay_tstep(ay_t *ay, unsigned int steps);