Skip to content

Commit

Permalink
Update to 7.4
Browse files Browse the repository at this point in the history
* Bug fixes with virtual channels
* Improve audio signal processing
* Add support to stream audio samples to multiple threads
* Fix bugs in documentation
* Python code for the Raspberry Pi Pico W to operate as a slave network channel.
  • Loading branch information
tom-2015 committed Dec 31, 2022
1 parent 4920dba commit d2a296a
Show file tree
Hide file tree
Showing 31 changed files with 2,688 additions and 108 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

# Version 7.4
* Bug fixes with virtual channels
* Improve audio signal processing
* Add support to stream audio samples to multiple threads
* Fix bugs in documentation
* Python code for the Raspberry Pi Pico W to operate as a slave network channel.

# Version 7.3
* Add new command "wave" as alternative to "pulses", it renders a low pass audio wave directly to the strip.

# Version 7.2
* Add new hardware version for Raspberry Pi 4 and Raspberry Pi Zero.
Expand Down
72 changes: 65 additions & 7 deletions COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,32 @@ render <channel>,<start>,<RRGGBBRRGGBB...>
# <RRGGBBRRGGBB...> Color to change the led at start Red+green+blue (no default)
```

* `system` Execute command as a system shell command, requires to start program with -s parameter.

```
system <command>
# <command> The shell command to execute.
```

* `wait_gpio` Waits for a GPIO to become value (sets GPIO as input).

```
ait_gpio <gpio_num>, <value>
# <gpio_num> The broadcom GPIO number, see https://pinout.xyz.
# <value> The value the GPIO must have before continue code (0=low, 1=high).
```

* `write_gpio` Changes the output value of a GPIO (sets GPIO as output).

```
write_gpio <gpio_num>,<value>
# <gpio_num> The broadcom GPIO number, see https://pinout.xyz.
# <value> The value to write to the GPIO (0=low, 1=high).
```

# Thread commands

* `set_thread_exit_type` This will set if the thread should be aborted when the kill_thread or ini_thread command is executed for the <thread_id> parameter
Expand All @@ -150,9 +176,9 @@ set_thread_exit_type <thread_id>,<type>
1 - wait until all commands completed, then exit
```

* `wait_thread` wait for a given thread to finish all commands (the exit type is ignored here)
* `wait_thread_exit` wait for a given thread to finish all commands (the exit type is ignored here)
```
wait_thread <thread_id>
wait_thread_exit <thread_id>
# <thread_id> The thread number (1-63)
```
Expand Down Expand Up @@ -563,7 +589,7 @@ This will paint a JPG, PNG or (animated) GIF to the LED matrix.
# <src_width> Source width, change together with src_x if you want only a part of the image file to be painted
# <src_height> Source height, change together with src_width
# <speed> If the file is an animated gif, specify here a speed multiplier, for example 2 will play at twice the speed. default is 1
# <max_loops> for animated gif only Stop repeating the animation after max_loops, default 0 = inifite loops or loops defined in the GIF
# <max_loops> for animated gif only stop repeating the animation after max_loops, default 0 = inifite loops or loops defined in the GIF
```

* `draw_line` draws an image file
Expand Down Expand Up @@ -718,10 +744,13 @@ record_audio <device>,<sample_rate>,<sample_count>,<channels>
# <device> Audio device, use arecord -L to list device and use the "plughw:*" device.
# <sample_rate> Here you can change the number of samples per second, default is 24000. Higher will require more CPU but better results with high frequency.
# <sample_count> Number of samples to store in the internal buffer before forwarding to DSP. Default is 1024 and you better leave it like that.
# <channels> Number of audio channels, default is 2 (stereo)
# <sample_count> Number of samples to store in the internal buffer before forwarding to DSP. Default is 1024 and you better leave it like that.
# <gain> Multiply samples with this value (float), may slow down the Pi.
```

Use device name thread://<thread_id> to get samples captured in another thread (see examples/stream_audio_multiple_threads.htm).

Since version 6.2 you can use udp port or named pipe as audio input device.
For example: udp://9000 as device will listen on local port 9000. External program can then send raw audio samples to this port.
Audio samples can also be broadcasted on the network to multiple Pis when using udpb://9000 it will listen to broadcast port 9000.
Expand Down Expand Up @@ -749,14 +778,15 @@ light_organ <channel>,<color_mode>,<color(s)>,<color_change_delay>,<duration>,<d
# <delay> Delay between rendering of the strip. default is 25ms increase to make flashing slower
# <start> Start at this LED number
# <len> Effect for this number of LEDs starting at start
# <gain> Multiply intensity by this gain value (float, default val = 4)
```
Color modes:
0 = 1 fixed color
1 = color sequence provided in the color(s) argument
2 = random colors provided in the color(s) argument, color(s) argument can be left empty for some default colors.
3 = keep existing color in the strip, this must be set first

* `pulses` Generates wave pattern on the LED strip (like a music driven chaser)
* `pulses` Generates wave pattern on the LED strip (like a music driven chaser), only if n samples are above a certain threshold

```
pulses <channel>,<threshold>,<color_mode>,<color(s)>,<delay>,<color_change_delay>,<direction>,<duration>,<min_brightness>,<start>,<len>
Expand All @@ -774,7 +804,25 @@ pulses <channel>,<threshold>,<color_mode>,<color(s)>,<delay>,<color_change_delay
# <len> Effect for this number of LEDs starting at start
```

* `vu_meter`
* `wave` Generates direct low pass audio wave on the strip, intensity will be set according to the audio level.

```
wave <channel>,<gain>,<color_mode>,<color(s)>,<delay>,<color_change_delay>,<direction>,<duration>,<min_brightness>,<start>,<len>
# <channel> Channel number
# <gain> Multiply the low pass output by this gain value (float, default is 4).
# <color_mode> Sets how changing of color should behave, see light_organ for possible values (default 2).
# <color(s)> Give color or multiple colors like FF0000 (red) or FF000000FF000000FF (red,green,blue)
# <delay> Delay between rendering of the strip, default 25ms. Decrease to make wave go faster but increase CPU load
# <color_change_delay> Number of seconds to wait before changing the color
# <direction> Chaser go forward or backwards
# <duration> Number of seconds before automatic exit of the command, 0 to run forever.
# <min_brightness> Minimum level of brightness or LEDs will be turned off (default is 20 max 255).
# <start> Start at this LED number
# <len> Effect for this number of LEDs starting at start
```

* `vu_meter` Generates a volume meter effect on a LED strip

```
vu_meter <channel>,<color_mode>,<color(s)>,<color_change_delay>,<duration>,<delay>,<brightness>,<start>,<len>
Expand All @@ -794,4 +842,14 @@ Color modes:
1 = color sequence provided in the color(s) argument
2 = random colors provided in the color(s) argument, color(s) argument can be left empty for some default colors.
3 = keep existing color in the strip, this must be set first
4 = Classic VU meter colors (green - yellow - orange - red)
4 = Classic VU meter colors (green - yellow - orange - red)

* `filter_audio` Apply a low/high pass filter or both on the incoming audio samples.

```
filter_audio <mode>,<low_freq>,<high_freq>
# <mode> 1: low pass, 2: high pass, 3: band pass.
# <low_freq> The low pass cut off frequency (use 0 if mode =2).
# <high_freq> The high pass filter start frequency (use 0 if mode=1).
```
42 changes: 35 additions & 7 deletions audio/light_organ.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "light_organ.h"
#include "record.h"
#include <pthread.h>
//light_organ <channel>,<color_mode>,<color(s)>,<color_change_delay>,<duration>,<delay>,<start>,<len>
//light_organ <channel>,<color_mode>,<color(s)>,<color_change_delay>,<duration>,<delay>,<start>,<len>,<random_width>,<gain>
//https://github.com/yellobyte/LED-Strip-Light-Organ/blob/main/Software/src/main.cpp
void light_organ(thread_context* context, char* args) {
const unsigned int MAX_COLORS = 255;
int channel = 0;
Expand All @@ -13,11 +14,12 @@ void light_organ(thread_context* context, char* args) {
int color_count = 0;
int color_mode = 2; //default some random colors
int color_change_delay = 60; //60 sec change color
float gain = 4.0;
int random_width = 0; //makes random bars in the light organ instead of full filled
float gain = 6.0;
int i;

if (!context->audio_capture.capturing) {
fprintf(stderr, "Error audio capture is not running on this thread. Use the audio_capture command to start capturing first!\n");
fprintf(stderr, "Error audio capture is not running on this thread. Use the record_audio command to start capturing first!\n");
return;
}

Expand Down Expand Up @@ -72,8 +74,10 @@ void light_organ(thread_context* context, char* args) {
args = read_int(args, &delay);
args = read_int(args, &start);
args = read_int(args, &len);
args = read_int(args, &random_width);
args = read_float(args, &gain);

if (debug) printf("light_organ %d,%d,%d,%d,%d,%d,%d,%d\n", channel, color_mode, color_count, color_change_delay, duration, delay, start, len);
if (debug) printf("light_organ %d,%d,%d,%d,%d,%d,%d,%d,%d\n", channel, color_mode, color_count, color_change_delay, duration, delay, start, len, random_width);

if (start >= get_led_count(channel)) start = 0;
if ((start + len) > get_led_count(channel)) len = get_led_count(channel) - start;
Expand All @@ -88,8 +92,13 @@ void light_organ(thread_context* context, char* args) {

volatile float low_pass_buffer=0; //here the record function will store the number of times threshold was reached
context->audio_capture.capture_dst_buffer = (void*)&low_pass_buffer;
context->audio_capture.dsp_mode = DSP_MODE_LOW_PASS;
context->audio_capture.dsp_mode = DSP_MODE_AVG;

int loops = 0;
int width = 1;
if (len > 10 ){
width = rand() % (len/10);
}
while ((((time(0) - start_time) < duration) || duration == 0) && context->end_current_command == 0) {
float low_pass_value;

Expand Down Expand Up @@ -119,8 +128,27 @@ void light_organ(thread_context* context, char* args) {
}
}

for (i = 0;i < len;i++) {
leds[start + i].brightness = intensity;
if (random_width){
if (loops == 10){
if (len < 10){
width = rand() % (len/10);
}else{
width = 1;
}
loops=0;
}
for (i = 0;i < len;i++) {
if ((i % (len/10)) >= width){
leds[start + i].brightness = intensity;
}else{
leds[start + i].brightness = 0;
}
}
loops++;
}else{
for (i = 0;i < len;i++) {
leds[start + i].brightness = intensity;
}
}

render_channel(channel);
Expand Down
2 changes: 1 addition & 1 deletion audio/pulses.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void audio_pulses(thread_context* context, char* args) {
float threshold=0.1;

if (!context->audio_capture.capturing) {
fprintf(stderr, "Error audio capture is not running on this thread. Use the audio_capture command to start capturing first!\n");
fprintf(stderr, "Error audio capture is not running on this thread. Use the record_audio command to start capturing first!\n");
return;
}

Expand Down
Loading

0 comments on commit d2a296a

Please sign in to comment.