aboutsummaryrefslogtreecommitdiff
path: root/libopna/opnassg.h
blob: adcd231f52b7ce0cd00e5f85d72d1c4de8b17a39 (plain)
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
#ifndef LIBOPNA_OPNASSG_H_INCLUDED
#define LIBOPNA_OPNASSG_H_INCLUDED

#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

struct opna_ssg_ch {
  uint16_t tone_counter;
  bool out;
};

struct opna_ssg {
  uint8_t regs[0x10];
  struct opna_ssg_ch ch[3];
  uint8_t noise_counter;
  uint32_t lfsr;
  uint16_t env_counter;
  uint8_t env_level;
  bool env_att;
  bool env_alt;
  bool env_hld;
  bool env_holding;
  unsigned mask;
};

struct opna_ssg_resampler {
  int16_t buf[(1<<7)];
  unsigned index;
};

void opna_ssg_reset(struct opna_ssg *ssg);
void opna_ssg_resampler_reset(struct opna_ssg_resampler *resampler);
// generate raw data
// Monoral
// Output level: [-32766, 32766]
// Samplerate: clock / 8
// (on opna: masterclock / 32
// 7987200 / 32 = 249600)
void opna_ssg_generate_raw(struct opna_ssg *ssg, int16_t *buf, int samples);

// mix samplerate converted data for mixing with OPNA output
// call to buffer written with OPNA output
// samplerate: 7987200/144 Hz
//            (55466.66..) Hz
void opna_ssg_mix_55466(
  struct opna_ssg *ssg, struct opna_ssg_resampler *resampler,
  int16_t *buf, int samples);
void opna_ssg_writereg(struct opna_ssg *ssg, unsigned reg, unsigned val);

// channel level (0 - 31)
int opna_ssg_channel_level(const struct opna_ssg *ssg, int ch);

#ifdef __cplusplus
}
#endif

#endif // LIBOPNA_OPNASSG_H_INCLUDED