forked from Aircoookie/WLED
-
-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AudioLux Usermod #80
Draft
netmindz
wants to merge
13
commits into
mdev
Choose a base branch
from
AudioLux
base: mdev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
AudioLux Usermod #80
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c839d49
Start initial code on trying to wrap AudioLux into WLED
netmindz cd58dd1
Start initial code on trying to wrap AudioLux into WLED
netmindz bc07d7a
Start initial code on trying to wrap AudioLux into WLED
netmindz f27a319
Updated AudioLux dep
netmindz 557e17b
Updated AudioLux dep
netmindz 27b9099
Try and exclude AudioLux from XL due to size issue
netmindz 2b2f929
Add Hue
netmindz 36c7ae2
Add Hue
netmindz a7c5165
Add Fire
netmindz f90b04d
Trying to use a Visualization
netmindz 30b8bf5
Start adding example of connecting to WLED audio data
netmindz e5435b6
Start adding example of connecting to WLED audio data
netmindz bd9205d
AudioFire example
netmindz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
#pragma once | ||
|
||
#include "wled.h" | ||
|
||
#include "pixl.h" | ||
#include "Logging.h" | ||
|
||
#define LOGLEVEL LOG_LEVEL_INFOS | ||
|
||
using namespace pixl; | ||
|
||
//======================================================================================================================== | ||
|
||
class WLEDAudioInput : public Input { | ||
public: | ||
WLEDAudioInput(){} | ||
void update() { | ||
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { | ||
// add support for no audio | ||
um_data = simulateSound(SEGMENT.soundSim); | ||
} | ||
} | ||
float getInput(int index = 0) { | ||
if (index == 0) { | ||
float volume = *(float*)um_data->u_data[0]; | ||
float value = (float) map((volume * 4), 0, 1020, 0, 1000) / 1000.0f; | ||
if(value > 0) Serial.println(value); | ||
return value; | ||
} else if (index == 1) { | ||
uint8_t *fftResult = (uint8_t*) um_data->u_data[2]; | ||
return 0.0; // TODO map 0-255 to expected range - https://github.com/netmindz/Audiolux/blob/81056ab8f59cb4a801b541ba57a62786b4b93a73/msgeq7.cpp#L39 | ||
} else { | ||
return 0.0; | ||
} | ||
} | ||
private: | ||
um_data_t *um_data; | ||
}; | ||
|
||
class AudioLux { | ||
|
||
int NUM_LEDS; | ||
LEDStrip ledstrip = LEDStrip(NUM_LEDS); | ||
LEDs leds = LEDs(&ledstrip, 0, 0, false); | ||
Input* input; | ||
Visualization* viz; | ||
Animation* anim; | ||
Looper* looper = Looper::instance(); | ||
|
||
public: | ||
|
||
AudioLux() {} | ||
|
||
void initEffect() { | ||
|
||
NUM_LEDS = SEGMENT.virtualWidth() * SEGMENT.virtualHeight(); | ||
|
||
ledstrip = LEDStrip(NUM_LEDS); | ||
leds = LEDs(&ledstrip, 0, NUM_LEDS, false); | ||
|
||
// Add all the components to the looper so they update every frame | ||
|
||
looper->clearAll(); | ||
delete viz; | ||
delete anim; | ||
delete input; | ||
looper->setUpdatesPerSecond(40); | ||
} | ||
|
||
void setVizTwinkleVisualization() { | ||
initEffect(); | ||
|
||
input = new NullInput(); | ||
looper->addInput(input); | ||
|
||
viz = new TwinkleVisualization(input, NUM_LEDS); | ||
looper->addVisualization(viz); | ||
} | ||
|
||
void setVizHueVisualization() { | ||
initEffect(); | ||
|
||
input = new RandomInput(); | ||
looper->addInput(input); | ||
|
||
viz = new HueVisualization(input, NUM_LEDS); | ||
anim = new PassThroughAnimation(viz, leds); | ||
looper->addVisualization(viz); | ||
looper->addAnimation(anim); | ||
} | ||
|
||
void setFireVisualization() { | ||
initEffect(); | ||
|
||
input = new RandomInput(); | ||
looper->addInput(input); | ||
|
||
viz = new FireVisualization(input, NUM_LEDS); | ||
looper->addVisualization(viz); | ||
} | ||
|
||
void setAudioFireVisualization() { | ||
initEffect(); | ||
|
||
input = new WLEDAudioInput(); | ||
looper->addInput(input); | ||
|
||
viz = new FireVisualization(input, NUM_LEDS); | ||
looper->addVisualization(viz); | ||
} | ||
|
||
void loop() { | ||
Looper::instance()->loop(); | ||
for(int i = 0; i < NUM_LEDS; i++) { | ||
SEGMENT.setPixelColor(i, ledstrip.leds[i]); // TODO: UGLY copy for now | ||
} | ||
} | ||
}; | ||
|
||
//======================================================================================================================== | ||
|
||
AudioLux audioLux; | ||
|
||
static const char _data_FX_mode_TwinkleVisualization[] PROGMEM = "AudioLux - Twinkle"; | ||
static const char _data_FX_mode_HueVisualization[] PROGMEM = "AudioLux - Hue"; | ||
static const char _data_FX_mode_FireVisualization[] PROGMEM = "AudioLux - Fire"; | ||
static const char _data_FX_mode_AudioFireVisualization[] PROGMEM = "AudioLux - AudioFire"; | ||
|
||
|
||
uint16_t mode_TwinkleVisualization() { | ||
if (SEGENV.call == 0) { | ||
audioLux.setVizTwinkleVisualization(); | ||
} | ||
audioLux.loop(); | ||
return FRAMETIME; | ||
} | ||
|
||
uint16_t mode_HueVisualization() { | ||
if (SEGENV.call == 0) { | ||
audioLux.setVizHueVisualization(); | ||
} | ||
audioLux.loop(); | ||
return FRAMETIME; | ||
} | ||
|
||
uint16_t mode_FireVisualization() { | ||
if (SEGENV.call == 0) { | ||
audioLux.setFireVisualization(); | ||
} | ||
audioLux.loop(); | ||
return FRAMETIME; | ||
} | ||
|
||
uint16_t mode_AudioFireVisualization() { | ||
if (SEGENV.call == 0) { | ||
audioLux.setAudioFireVisualization(); | ||
} | ||
audioLux.loop(); | ||
return FRAMETIME; | ||
} | ||
|
||
|
||
class AudioLuxUsermod : public Usermod { | ||
|
||
public: | ||
|
||
AudioLuxUsermod(const char *name, bool enabled):Usermod(name, enabled) {} //WLEDMM | ||
|
||
void setup() { | ||
|
||
if(!enabled) return; | ||
|
||
strip.addEffect(255, &mode_TwinkleVisualization, _data_FX_mode_TwinkleVisualization); | ||
strip.addEffect(255, &mode_HueVisualization, _data_FX_mode_HueVisualization); | ||
strip.addEffect(255, &mode_FireVisualization, _data_FX_mode_FireVisualization); | ||
strip.addEffect(255, &mode_AudioFireVisualization, _data_FX_mode_AudioFireVisualization); | ||
|
||
initDone = true; | ||
} | ||
|
||
void loop() { | ||
if (!enabled || strip.isUpdating()) return; | ||
|
||
// do your magic here | ||
if (millis() - lastTime > 1000) { | ||
//USER_PRINTLN("I'm alive!"); | ||
lastTime = millis(); | ||
} | ||
|
||
|
||
} | ||
|
||
uint16_t getId() | ||
{ | ||
return USERMOD_ID_AUDIOLUX; | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea why that isn't taking effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possibly you also need to add the library to
lib_ignore
. otherwise the compiler still tries to build the audiolux library even when its not needed. Can check later this aternoon...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so adding the compiled code, despite not actually being referenced. Just statically linking all parts of all libraries. Wonder if there is an option you can pass to the linker