furnace/src/audio/taAudio.h

154 lines
3.3 KiB
C
Raw Normal View History

#ifndef _TAAUDIO_H
#define _TAAUDIO_H
#include "../ta-utils.h"
2022-02-13 20:02:43 +00:00
#include <vector>
struct SampleRateChangeEvent {
double rate;
SampleRateChangeEvent(double r):
rate(r) {}
};
struct BufferSizeChangeEvent {
unsigned int bufsize;
BufferSizeChangeEvent(unsigned int bs):
bufsize(bs) {}
};
enum TAAudioFormat {
TA_AUDIO_FORMAT_F32=0,
TA_AUDIO_FORMAT_F64,
TA_AUDIO_FORMAT_U8,
TA_AUDIO_FORMAT_S8,
TA_AUDIO_FORMAT_U16,
TA_AUDIO_FORMAT_S16,
TA_AUDIO_FORMAT_U32,
TA_AUDIO_FORMAT_S32,
TA_AUDIO_FORMAT_U16BE,
TA_AUDIO_FORMAT_S16BE,
TA_AUDIO_FORMAT_U32BE,
TA_AUDIO_FORMAT_S32BE
};
struct TAAudioDesc {
2022-02-14 02:42:57 +00:00
String name, deviceName;
double rate;
unsigned int bufsize, fragments;
unsigned char inChans, outChans;
TAAudioFormat outFormat;
TAAudioDesc():
rate(0.0),
bufsize(0),
fragments(0),
inChans(0),
outChans(0),
outFormat(TA_AUDIO_FORMAT_F32) {}
};
2022-02-13 20:02:43 +00:00
enum TAMidiMessageTypes {
TA_MIDI_NOTE_OFF=0x80,
TA_MIDI_NOTE_ON=0x90,
TA_MIDI_AFTERTOUCH=0xa0,
TA_MIDI_CONTROL=0xb0,
TA_MIDI_PROGRAM=0xc0,
TA_MIDI_CHANNEL_AFTERTOUCH=0xd0,
TA_MIDI_PITCH_BEND=0xe0,
TA_MIDI_SYSEX=0xf0,
TA_MIDI_MTC_FRAME=0xf1,
TA_MIDI_POSITION=0xf2,
TA_MIDI_SONG_SELECT=0xf3,
TA_MIDI_TUNE_REQUEST=0xf6,
TA_MIDI_SYSEX_END=0xf7,
TA_MIDI_CLOCK=0xf8,
TA_MIDI_MACHINE_PLAY=0xfa,
TA_MIDI_MACHINE_RESUME=0xfb,
TA_MIDI_MACHINE_STOP=0xfc,
TA_MIDI_KEEPALIVE=0xfe,
TA_MIDI_RESET=0xff
};
struct TAMidiMessage {
unsigned char type;
union {
struct {
unsigned char note, vol;
} note;
struct {
unsigned char which, val;
} control;
unsigned char patch;
unsigned char pressure;
struct {
unsigned char low, high;
} pitch;
struct {
unsigned int vendor;
} sysEx;
unsigned char timeCode;
struct {
unsigned char low, high;
} position;
unsigned char song;
} data;
unsigned char* sysExData;
size_t sysExLen;
void submitSysEx(std::vector<unsigned char> data);
void done();
};
class TAMidiIn {
public:
bool next(TAMidiMessage& where);
};
class TAMidiOut {
public:
bool send(TAMidiMessage& what);
};
class TAMidi {
std::vector<TAMidiIn*> in;
std::vector<TAMidiOut*> out;
2022-02-14 02:42:57 +00:00
};
2022-02-13 20:02:43 +00:00
2022-02-14 02:42:57 +00:00
class TAAudio {
protected:
TAAudioDesc desc;
TAAudioFormat outFormat;
bool running, initialized;
float** inBufs;
float** outBufs;
void (*audioProcCallback)(void*,float**,float**,int,int,unsigned int);
void* audioProcCallbackUser;
void (*sampleRateChanged)(SampleRateChangeEvent);
void (*bufferSizeChanged)(BufferSizeChangeEvent);
public:
TAMidi* midi;
void setSampleRateChangeCallback(void (*callback)(SampleRateChangeEvent));
void setBufferSizeChangeCallback(void (*callback)(BufferSizeChangeEvent));
void setCallback(void (*callback)(void*,float**,float**,int,int,unsigned int), void* user);
2022-02-13 20:02:43 +00:00
2022-02-14 02:42:57 +00:00
virtual void* getContext();
virtual bool quit();
virtual bool setRun(bool run);
virtual std::vector<String> listAudioDevices();
virtual bool init(TAAudioDesc& request, TAAudioDesc& response);
TAAudio():
outFormat(TA_AUDIO_FORMAT_F32),
running(false),
initialized(false),
inBufs(NULL),
outBufs(NULL),
audioProcCallback(NULL),
sampleRateChanged(NULL),
bufferSizeChanged(NULL) {}
virtual ~TAAudio();
2022-02-13 20:02:43 +00:00
};
#endif