#ifndef MINIAUDIOENGINE_H #define MINIAUDIOENGINE_H #define MA_ENABLE_ONLY_SPECIFIC_BACKENDS #define MA_ENABLE_JACK #define MA_DISABLE_PULSE #define MA_NO_GENERATION #define MA_DEBUG_OUTPUT #define MA_LOG_LEVEL_DEBUG DEBUG #define MINIAUDIO_IMPLEMENTATION #include "miniaudio.h" #include "ma_writer_node.h" #include using namespace std; #include "defines.h" typedef struct { ma_splitter_node input; ma_hpf_node hpf; ma_hpf_node_config hpfConfig; ma_loshelf_node loshelf; ma_loshelf_node_config loshelfConfig; ma_peak_node mLow; ma_peak_node_config mLowConfig; ma_peak_node mHigh; ma_peak_node_config mHighConfig; ma_hishelf_node hishelf; ma_hishelf_node_config hishelfConfig; ma_vumeter_node vumeter; ma_splitter_node output; } filterBank; typedef struct { ma_engine engines[MAX_AUDIODEVICES]; ma_device devices[MAX_AUDIODEVICES]; filterBank filters[MAX_LAYERS]; ma_writer_node sendAuxNode[MAX_AUDIODEVICES]; ma_pcm_rb auxBuffers[MAX_AUDIODEVICES]; ma_node_graph ng; layerData currentStatus[MAX_LAYERS]; ma_sound sounds[MAX_LAYERS]; ma_resource_manager resourceManager; ma_context context; ma_device_info* pPlaybackDeviceInfos; ma_device_info pSelectedPlaybackDeviceInfos[MAX_AUDIODEVICES]; ma_uint32 playbackDeviceCount; ma_uint32 devicesSelected; ma_bool8 mediaLoaded[MAX_LAYERS]; uint layersQty; uint *audioDevicesId; uint audioDevicesQty; ma_data_source_node dataSupplyNode[MAX_AUDIODEVICES]; ma_data_source_rb dataSourceRB[MAX_AUDIODEVICES]; } MAE; class MiniAudioEngine { public: static void audioDataCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount); MiniAudioEngine(); void stopEngine(); bool startEngine(uint layersQty, uint* audioDevicesID, uint audioDevicesQty); ma_result loadMedia(int layer, char *media); void volChanged(int layer, int vol); void volChanged(int layer, int vol, int fadeIn, int fadeOut); void panChanged(int layer, float pan); void pitchChanged(int layer, float pitch); ma_result playbackChanged(int layer, Status status); ma_result setCursor(int layer, int cursor); ma_result printFormatInfo(int layer); float getDuration(int layer); float getCursor(int layer); Status getStatus(int layer); inline float getVol(int layer) { return ma_sound_get_volume(&m_mae.sounds[layer]); }; inline bool getAtEnd(int layer) { return m_mae.sounds[layer].atEnd; } ma_result filterParamChanged(int layer, int channel, int value); bool setBypass(int audioDevice, int layer, bool bypass); inline float getLevel(int layer) { float level = ma_vumeter_node_get_level(&m_mae.filters[layer].vumeter); return ma_volume_linear_to_db(level) - 4.0f; }; char* getDeviceName(uint id); private: MAE m_mae; ma_result startDevices(); ma_result getAllAudioDevices(); ma_result startContext(); void refreshValues(int layer); ma_result seekToCursor(int layer, int cursor); ma_result setNodeGraph(); ma_result createFilterBank(uint layer); ma_result setLoopPoint(int layer, int cursor); ma_result setRangePoint(int layer, int cursor); }; #endif // MINIAUDIOENGINE_H