sound_engine_defs.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #include <stdio.h>
  3. #include <stdbool.h>
  4. #define NUM_CHANNELS 4
  5. #define RANDOM_SEED 0xf31782ce
  6. #define ACC_BITS 23
  7. #define ACC_LENGTH (1 << (ACC_BITS - 1))
  8. #define OUTPUT_BITS 16
  9. #define WAVE_AMP (1 << OUTPUT_BITS)
  10. #define SINE_LUT_SIZE 256
  11. #define SINE_LUT_BITDEPTH 8
  12. typedef enum
  13. {
  14. SE_WAVEFORM_NONE = 0,
  15. SE_WAVEFORM_NOISE = 1,
  16. SE_WAVEFORM_PULSE = 2,
  17. SE_WAVEFORM_TRIANGLE = 4,
  18. SE_WAVEFORM_SAW = 8,
  19. SE_WAVEFORM_NOISE_METAL = 16,
  20. SE_WAVEFORM_SINE = 32,
  21. } SoudEngineWaveformType;
  22. typedef enum
  23. {
  24. SE_ENABLE_FILTER = 1,
  25. SE_ENABLE_GATE = 2,
  26. SE_ENABLE_RING_MOD = 4,
  27. SE_ENABLE_HARD_SYNC = 8,
  28. SE_ENABLE_KEYDOWN_SYNC = 16, //sync oscillators on keydown
  29. } SoundEngineFlags;
  30. typedef enum
  31. {
  32. FIL_OUTPUT_LOWPASS = 1,
  33. FIL_OUTPUT_HIGHPASS = 2,
  34. FIL_OUTPUT_BANDPASS = 3,
  35. } SoundEngineFilterModes;
  36. typedef struct
  37. {
  38. uint8_t a, d, s, r, volume;
  39. uint32_t envelope;
  40. int32_t envelope_speed;
  41. } SoundEngineADSR;
  42. typedef struct
  43. {
  44. int32_t f, q, p;
  45. int32_t b0, b1, b2, b3, b4; //filter coefficients
  46. } SoundEngineFilter;
  47. typedef struct
  48. {
  49. uint32_t accumulator;
  50. uint32_t frequency;
  51. uint8_t waveform;
  52. uint16_t pw;
  53. uint32_t lfsr;
  54. SoundEngineADSR adsr;
  55. uint16_t flags;
  56. uint8_t filter_mode;
  57. uint16_t filter_cutoff;
  58. uint16_t filter_resonace;
  59. SoundEngineFilter filter;
  60. } SoundEngineChannel;
  61. typedef struct
  62. {
  63. SoundEngineChannel channel[NUM_CHANNELS];
  64. uint32_t sample_rate;
  65. uint16_t* audio_buffer;
  66. uint32_t audio_buffer_size;
  67. bool external_audio_output;
  68. uint8_t sine_lut[SINE_LUT_SIZE];
  69. } SoundEngine;