-
Notifications
You must be signed in to change notification settings - Fork 4
The Visualizer
Up to date as of version 1.6
- Overview
- Selecting basic audio settings
- Basic trackbar settings
- The Beat Zone
- Configuring the spectrums
- The different Visualization Types
The visualizer is by far the most advanced part of this project. However that also means that you can make some fairly advanced stuff with it.
The first thing to do to get the visualizer working, is selecting some basic settings:
The first combobox Select Audio Source is simply a collection of audio output devices in windows. Here you simply select a source. The next one, Visualization type is alle the different types of visualization there is available. Currently there are 6 different options:
- Beat
- Spectrum Beat
- Spectrum Wave
- Beat Wave
- "Beat Wave" Beat
- Full Spectrum
The inner functions of these will be explained further down. Next up is the Visual Samples box, where you select how many samples of the audio to take. The default is 128, but it can be everything from 0 to BASS.NET dies. It is basically the resolution of the audio sampling that you are defining here. Then comes Audio Samples which is a value in BASS.NET that can be changed, however the value 16384 is the default, and the one that should be used.
Then comes three trackbars, that define the settings' sensitivity, smoothness and sample time:
From the top, the Sensitivity track bar defines a value to multiply the audio input samples with. As a default this setting is 3. The function for how the sensitivity works is as follows:
YValue = (int)(Sqrt(BASSValue) * SensitivityTrackBar.Value * 255 - 4);
Then comes the Smoothness trackbar, this trackbar defines how much the values should be smoothed with. As a default this value is set to 1, since that gives a very direct output with most of the visualization types. How it works is as follows, if the trackbar is at, as an example, 5, then the last 5 readings, is added together and divided by 5. The time between these samples is defined by the next trackbar, the Sample Time trackbar, which tells how many milliseconds there should be, between each sampling of audio. This value can be set down to about 10 ms without trouble, however if the data comes in too fast, the Arduino cant follow up, and potentially crash.
This is the part of the visualizer, where you decide which values to include, and which to exclude:
The graph shows what the current audio input values are. To the left of the graph, is the trigger level settings. Trigger level is there to tell at which height in Y values the samples have to get, to be included in an output. This trigger value can be between 0 and 255. The Trigger Level Trackbar can be changed manually, or you can check the Auto Trigger checkbox, this will then automatically take control of the trigger level. Its maximum and minimum values can be set right next to the Trigger Level trackbar. Right under the Beat Zone graph, you can select what X values to include and exclude, by dragging the From and To Trackbars. These tell from what value on the graph, to what value of the graph to take from. In the bottom, there's to more boxes, these decide what values need to be exceeded to change the auto trigger level. The value can be seen in the bottom right corner. The function to determine the current trigger value is as following:
foreach(Values in Samples)
if (Value.Y > TriggerTrackBar.Value)
if (Value.X > FromTrackBar.Value)
if (Value.X < ToTrackBar.Value)
Hit++
TriggerValue = (Hit / (ToTrackBar.Value — FromTrackBar.Value)) * (255 * 3)
If that TriggerValue is then higher or lower than the specified ranges, the trigger level will increase or decrease with it. Down in the bottom you can also select from which series ID to what series ID to visualize on. As a default it is set from 0 to -1, where -1 simply indicates all the series. If the LEDs are excluded, lets say you have 50 LEDs and you wanna visualize from 0 to 25, then the rest of the LEDs will just display the color from before, and not change.
There are two modifiable spectrums, one for Spectrum Beat/Wave and one for Wave Beat:
Here we will only go through how to use the inputs, how they influence the output, comes down in the bottom. However, each chart shows two series, Red, Green and Blue. These three lines have an input each, in these inputs, you can put in different functions, on how you want to show these different colors. It can understand functions that only include ()^*/+-. Any other inputs (such as Cos or Euters) will give an error. You can not only have one function her series, you can also use piecewice. The usage of this is as follows:
PW[The Function:FromX:ToX]
Using the PW in the input, negates everything else that's not inside a PW. That means that if you wrote:
PW[x * 2:0:255] + 10 * x
The last part would be ignored, and only the PW function will be shown. You can have multiple PW's. There is no need for a spacer or anything between them, it could be as follows:
PW[The Function:FromX:ToX]PW[The Function:FromX:ToX]PW[The Function:FromX:ToX]
or
PW[The Function:FromX:ToX] PW[The Function:FromX:ToX] PW[The Function:FromX:ToX]
This is an example with the input "PW[x * 1 : 0 : 100] PW[x * 2 - 100 : 100 : 765]"
Then there is also a checkbox, that says Auto Scale Values, what this does, is if a function gets higher than 255 (which is the maximum in RGB) it will just set that point to be 255. The same goes if the value is less than 0, it would just be set to 0. If you do not use auto scale, then the values higher than 255 and those lower than 0 will be ignored.
With this you can make some fairly interesting functions, that display in its own unique way.
As said earlier, there are six different visualization types:
- Beat
- Spectrum Beat
- Spectrum Wave
- Beat Wave
- "Beat Wave" Beat
- Full Spectrum
Beat is the first type. What this does, is taking the previous color value, example from Fade Colors, and light it up, with a percentage of the beat. With that, all the LEDs will have the same color. The function for this, is as follows:
foreach(Values in Samples)
if (Value.Y > TriggerTrackBar.Value)
if (Value.X > FromTrackBar.Value)
if (Value.X < ToTrackBar.Value)
Hit++
OutValuePercantage = Hit / (BeatZoneToTrackBar.Value - BeatZoneFromTrackBar.Value)
Where the Arduino then takes that value, and times it with the LEDs current color.
Works on the same principle as Beat, however it now uses a spectrum, defined from before. This type takes the value from each point in the Beat Zone chart, and the percentage of the maximum, is then multiplied with the RGB value in the Spectrum Beat chart. All the values from each point is then added together, and divided by the amount. This can be described as:
foreach(Values in Samples)
if (Value.Y > TriggerTrackBar.Value)
if (Value.X > FromTrackBar.Value)
if (Value.X < ToTrackBar.Value)
if (ChartValueRed[Value.X].Y = 0)
TotalRed += ChartValueGRed[Value.X].Y
RedCount++;
if (ChartValueGreen[Value.X].Y = 0)
TotalGreen += ChartValueGreen[Value.X].Y
GreenCount++;
if (ChartValueBlue[Value.X].Y = 0)
TotalBlue += ChartValueBlue[Value.X].Y
BlueCount++;
EndRed = TotalRed / RedCount;
EndGreen = TotalGreen / GreenCount;
EndBlue = TotalBlue / BlueCount;
Where the EndRed, EndGreen and EndBlue values, are the once that's going to be displayed on all the LEDs.
This uses the same spectrum as the Spectrum Beat, however it displays in a wave. Meaning that the series you gave the LEDs in the start, is now used here. What it does is color the first pixel in the series, with the color given from the computer. At the same time, all the LED's color shift a spot, so all the colors move one pixel. This then gives an impression of a wave, hence the name. This mode, as well as the previous Spectrum mode, allows for very specialized functions, that fit a special song.
This one is probably one of the easiest en prettiest of the types. It works in the same way as Spectrum Wave, however it is not dependent to give a color, at certain point. Instead, it takes how many total hits there are, and returns the value from the Beat Wave chart. That means that it works almost the same as the Spectrum once, however the function is a bit simpler:
foreach(Values in Samples)
if (Value.Y > TriggerTrackBar.Value)
if (Value.X > FromTrackBar.Value)
if (Value.X < ToTrackBar.Value)
Hit++
EndValue = (255 * 3) * (Hit / ToTrackBar.Value - FromTrackBar.Value)
EndRed = ChartValueRed[EndValue].Y
EndGreen = ChartValueGreen[EndValue].Y
EndBlue = ChartValueBlue[EndValue].Y
if (EndRed > 255)
EndRed = 255
if (EndRed < 0)
EndRed = 0
if (EndGreen > 255)
EndGreen = 255
if (EndGreen < 0)
EndGreen = 0
if (EndBlue > 255)
EndBlue = 255
if (EndBlue < 0)
EndBlue = 0
An example of this could be as follows:
The green bar shows where on the chart we are. So at that point (marked with an orange line) you can see that the color red is at 255 in the top, while green is about 80 and blue is not there. That means that the color 255:80:0 is being sent to the first LED in the series.
"Beat wave" Beat uses the same values as Beat Wave, however it displays it in a Beat style. So that all the LEDs show the color chosen in the Beat Wave Settings panel.
This last visualization type is kinda special. It requires a special kind of setup do look good. What this does is split the series up, in sections that's as long as defined here:
The strip is then split into sections, that describe a section of the Beat Zone. It would be a good idea not to have the visualization samples to 128, since that would be a LOT of sections. These sections then display what the Beat Zone shows. It would work best, if you have a lot of strips that's form a pattern resembling a spectrum. Be careful with how many visualization samples you have, since it can easily crash the Arduino, if set too high.
This would require a special kind of setup, that could look something like this:
Were the spectrum then would be displayed on.
Kristian Skov Johansen 2018