diff --git a/sound.h b/sound.h index 732587c..36607ee 100644 --- a/sound.h +++ b/sound.h @@ -1,5 +1,5 @@ -#ifndef SOUND_H -#define SOUND_H +#pragma once + #include #include #include @@ -18,32 +18,31 @@ typedef uint8_t SoundData; typedef long unsigned int SoundPos; typedef unsigned int SoundVolume; -typedef enum SoundState { +enum SoundState { STOPPED, PLAYING, PAUSED -} SoundState_t; +}; -typedef enum SoundProviderControl { +enum SoundProviderControl { END, FAILURE -} SoundProviderControl_t; +}; -typedef enum SoundEvent { +enum SoundEvent { STOP, START, PAUSE, RESUME, VOLSET -} SoundEvent_t; +}; -typedef struct SoundControl { - SoundEvent_t event; +struct SoundControl { + SoundEvent event; SoundChNum channel; SoundProvider *provider; SoundVolume vol; -} SoundControl_t; +}; #include #include -#endif diff --git a/soundMixer.cpp b/soundMixer.cpp index 47d885c..39f89bd 100644 --- a/soundMixer.cpp +++ b/soundMixer.cpp @@ -17,7 +17,7 @@ static int lcm(int a, int b) { bool SoundMixer::handleQueue() { xSemaphoreTake(mutex, portMAX_DELAY); - SoundControl_t ctrl; + SoundControl ctrl; bool upd = false; // Should we recalculate anything? while(xQueueReceive(queue, &ctrl, 0) == pdTRUE) { // Handle all events without blocking SoundChNum channel = ctrl.channel; @@ -123,7 +123,7 @@ void SoundMixer::soundCallback() { } } out += sound->actual * chVolume[i]; - SoundProviderControl_t ctrl; + SoundProviderControl ctrl; while(xQueueReceive(sound->controlQueue, &ctrl, 0) == pdTRUE) { switch(ctrl) { case END: @@ -152,7 +152,7 @@ void SoundMixer::decSound() { xSemaphoreTake(chActiveCount, portMAX_DELAY); } -void SoundMixer::addEvent(SoundControl_t event) { +void SoundMixer::addEvent(SoundControl event) { xQueueSendToBack(queue, &event, portMAX_DELAY); } @@ -175,7 +175,7 @@ SoundMixer::SoundMixer(SoundChNum normal_channels, SoundChNum auto_channels, dac mutex = xSemaphoreCreateMutex(); timerMutex = xSemaphoreCreateCounting(1, 1); chActiveCount = xSemaphoreCreateCounting(chCount, 0); - queue = xQueueCreate(CONFIG_SND_CONTROL_QUEUE_SIZE, sizeof(SoundControl_t)); + queue = xQueueCreate(CONFIG_SND_CONTROL_QUEUE_SIZE, sizeof(SoundControl)); for (SoundChNum i = 0; i < chCount; i++) { // Set defaults chActive[i] = false; @@ -204,7 +204,7 @@ void SoundMixer::checkTimer() { void SoundMixer::play(SoundChNum channel, SoundProvider *sound) { stop(channel); - SoundControl_t ctrl; + SoundControl ctrl; ctrl.event = START; ctrl.channel = channel; ctrl.provider = sound; @@ -215,7 +215,7 @@ void SoundMixer::play(SoundChNum channel, SoundProvider *sound) { void SoundMixer::stop(SoundChNum channel) { if (uxSemaphoreGetCount(timerMutex) == 0) { - SoundControl_t ctrl; + SoundControl ctrl; ctrl.event = STOP; ctrl.channel = channel; addEvent(ctrl); @@ -230,7 +230,7 @@ void SoundMixer::stopAll() { void SoundMixer::pause(SoundChNum channel) { if (uxSemaphoreGetCount(timerMutex) == 0) { - SoundControl_t ctrl; + SoundControl ctrl; ctrl.event = PAUSE; ctrl.channel = channel; addEvent(ctrl); @@ -244,7 +244,7 @@ void SoundMixer::pauseAll() { } void SoundMixer::resume(SoundChNum channel) { - SoundControl_t ctrl; + SoundControl ctrl; ctrl.event = RESUME; ctrl.channel = channel; addEvent(ctrl); @@ -260,7 +260,7 @@ void SoundMixer::resumeAll() { } void SoundMixer::setVolume(SoundChNum channel, SoundVolume vol) { - SoundControl_t ctrl; + SoundControl ctrl; ctrl.event = VOLSET; ctrl.channel = channel; ctrl.vol = vol; @@ -275,9 +275,9 @@ SoundVolume SoundMixer::getVolume(SoundChNum channel) { return vol; } -SoundState_t SoundMixer::state(SoundChNum channel) { +SoundState SoundMixer::state(SoundChNum channel) { xSemaphoreTake(mutex, portMAX_DELAY); - SoundState_t s; + SoundState s; if (chActive[channel]) s = PLAYING; else if (chPaused[channel]) s = PAUSED; else s = STOPPED; diff --git a/soundMixer.h b/soundMixer.h index 9668230..9a85e51 100644 --- a/soundMixer.h +++ b/soundMixer.h @@ -1,5 +1,4 @@ -#ifndef SOUND_MIXER_H -#define SOUND_MIXER_H +#pragma once #ifndef min #define min(a,b) ((a)<(b)?(a):(b)) @@ -38,7 +37,7 @@ class SoundMixer { bool handleQueue(); // Handle suspended events (SAFE) void setupTimer(); // Set divisors and start timer - void addEvent(SoundControl_t event); + void addEvent(SoundControl event); void checkTimer(); // Start one-shot "promo-"timer if isn't active public: @@ -52,7 +51,7 @@ class SoundMixer { void resume(SoundChNum channel); void setVolume(SoundChNum channel, SoundVolume vol); SoundVolume getVolume(SoundChNum channel); - SoundState_t state(SoundChNum channel); // SAFE + SoundState state(SoundChNum channel); // SAFE SoundChNum playAuto(SoundProvider *sound, SoundVolume vol); // Auto select channel and play sound on it (if no aviable, count of channels will be returned) @@ -60,5 +59,3 @@ class SoundMixer { void pauseAll(); void resumeAll(); }; - -#endif diff --git a/soundProvider.cpp b/soundProvider.cpp index 90ae31b..e4ab165 100644 --- a/soundProvider.cpp +++ b/soundProvider.cpp @@ -3,7 +3,7 @@ SoundProvider::SoundProvider() { queue = xQueueCreate(CONFIG_SND_PROVIDER_MAIN_QUEUE_SIZE, sizeof(SoundData)); assert(queue != NULL); - controlQueue = xQueueCreate(CONFIG_SND_PROVIDER_CONTROL_QUEUE_SIZE, sizeof(SoundProviderControl_t)); + controlQueue = xQueueCreate(CONFIG_SND_PROVIDER_CONTROL_QUEUE_SIZE, sizeof(SoundProviderControl)); assert(controlQueue != NULL); } diff --git a/soundProvider.h b/soundProvider.h index efb611a..b88c066 100644 --- a/soundProvider.h +++ b/soundProvider.h @@ -1,5 +1,5 @@ -#ifndef SOUND_PROVIDER_H -#define SOUND_PROVIDER_H +#pragma once + class SoundMixer; class SoundProvider { // Abstract interface for sound providers. Include queues initialisation/deinitialisation. @@ -35,5 +35,3 @@ class SoundProvider { // Abstract interface for sound providers. Include queues friend SoundMixer; }; - -#endif diff --git a/soundProviderTask.cpp b/soundProviderTask.cpp index e60ca34..9f71936 100644 --- a/soundProviderTask.cpp +++ b/soundProviderTask.cpp @@ -1,4 +1,5 @@ #include +#include SoundProviderTask::SoundProviderTask() {} SoundProviderTask::~SoundProviderTask() {} diff --git a/soundProviderTask.h b/soundProviderTask.h index 26ea0d1..1a97325 100644 --- a/soundProviderTask.h +++ b/soundProviderTask.h @@ -1,5 +1,5 @@ -#ifndef SOUND_PROVIDER_TASK_H -#define SOUND_PROVIDER_TASK_H +#pragma once + #include class SoundProviderTask: public SoundProvider { @@ -26,5 +26,3 @@ class SoundProviderTask: public SoundProvider { SoundProviderTask(); virtual ~SoundProviderTask(); }; - -#endif