| 1 | #pragma once |
| 2 | |
| 3 | #include <stdint.h> |
| 4 | #include <stdbool.h> |
| 5 | #include "pt2_replayer.h" |
| 6 | |
| 7 | // for the low-pass/high-pass filters in the SAMPLER screen |
| 8 | #define FILTERS_BASE_FREQ (PAULA_PAL_CLK / 214.0) |
| 9 | |
| 10 | // too many bits makes little sense here |
| 11 | |
| 12 | #define BPM_FRAC_BITS 52 |
| 13 | #define BPM_FRAC_SCALE (1ULL << BPM_FRAC_BITS) |
| 14 | #define BPM_FRAC_MASK (BPM_FRAC_SCALE-1) |
| 15 | |
| 16 | #define TICK_TIME_FRAC_BITS 52 |
| 17 | #define TICK_TIME_FRAC_SCALE (1ULL << TICK_TIME_FRAC_BITS) |
| 18 | #define TICK_TIME_FRAC_MASK (TICK_TIME_FRAC_SCALE-1) |
| 19 | |
| 20 | typedef struct audio_t |
| 21 | { |
| 22 | volatile bool locked, isSampling, callbackOngoing; |
| 23 | |
| 24 | bool ledFilterEnabled, oversamplingFlag; |
| 25 | |
| 26 | uint32_t amigaModel, outputRate, audioBufferSize; |
| 27 | |
| 28 | int32_t tickSampleCounter; |
| 29 | uint32_t samplesPerTickInt, samplesPerTickIntTab[(MAX_BPM-MIN_BPM)+1]; |
| 30 | uint64_t tickSampleCounterFrac, samplesPerTickFrac, samplesPerTickFracTab[(MAX_BPM-MIN_BPM)+1]; |
| 31 | |
| 32 | // for audio sampling |
| 33 | bool rescanAudioDevicesSupported; |
| 34 | |
| 35 | // for audio/video syncing |
| 36 | bool resetSyncTickTimeFlag; |
| 37 | uint32_t tickTimeIntTab[(MAX_BPM-MIN_BPM)+1]; |
| 38 | uint64_t tickTimeFracTab[(MAX_BPM-MIN_BPM)+1]; |
| 39 | } audio_t; |
| 40 | |
| 41 | void setAmigaFilterModel(uint8_t model); |
| 42 | void toggleAmigaFilterModel(void); |
| 43 | void setLEDFilter(bool state); |
| 44 | void toggleLEDFilter(void); |
| 45 | |
| 46 | void updateReplayerTimingMode(void); |
| 47 | void generateBpmTable(double dAudioFreq, bool vblankTimingFlag); |
| 48 | uint16_t get16BitPeak(int16_t *sampleData, uint32_t sampleLength); |
| 49 | uint32_t get32BitPeak(int32_t *sampleData, uint32_t sampleLength); |
| 50 | float getFloatPeak(float *fSampleData, uint32_t sampleLength); |
| 51 | double getDoublePeak(double *dSampleData, uint32_t sampleLength); |
| 52 | void normalize16BitTo8Bit(int16_t *sampleData, uint32_t sampleLength); |
| 53 | void normalize32BitTo8Bit(int32_t *sampleData, uint32_t sampleLength); |
| 54 | void normalizeFloatTo8Bit(float *fSampleData, uint32_t sampleLength); |
| 55 | void normalizeDoubleTo8Bit(double *dSampleData, uint32_t sampleLength); |
| 56 | void toggleAmigaPanMode(void); |
| 57 | void lockAudio(void); |
| 58 | void unlockAudio(void); |
| 59 | void resetAudioDither(void); |
| 60 | void audioSetStereoSeparation(uint8_t percentage); |
| 61 | void outputAudio(int16_t *target, int32_t numSamples); |
| 62 | bool setupAudio(void); |
| 63 | void audioClose(void); |
| 64 | |
| 65 | extern audio_t audio; // pt2_audio.c |