Billism Posted December 4, 2014 Share Posted December 4, 2014 In case anyone is interested, I ported the C++ spectrogram program that CalcProgrammer1 made, to .Net C#. His original post: http://forum.corsair.com/v3/showthread.php?t=133471 The .Net project: https://github.com/billism1/KeyboardAudio Video of it in action: [ame] [/ame] Link to comment Share on other sites More sharing options...
CalcProgrammer1 Posted December 4, 2014 Share Posted December 4, 2014 Awesome! Have a video of it in action? Link to comment Share on other sites More sharing options...
Billism Posted December 4, 2014 Author Share Posted December 4, 2014 Awesome! Have a video of it in action? I just edited the post to include it. Thanks again for your awesome work! Link to comment Share on other sites More sharing options...
Battlerobot Posted December 8, 2014 Share Posted December 8, 2014 Complete noob here. How would I go about using this? Link to comment Share on other sites More sharing options...
SimpleStreet Posted December 9, 2014 Share Posted December 9, 2014 Complete noob here. How would I go about using this? You will need a program to compile the code from his Github, i suggest using Visual studio, easy installation and free. It is noted that OpenTK is needed to make the program work, so you will need to install that as well. all that is remaining is acctually getting the code from Github, run it in visual studio, and that should be it i belive ?, you may need to exit the corsair software thing, that might get in the way of making it run properly. Link to comment Share on other sites More sharing options...
Billism Posted December 9, 2014 Author Share Posted December 9, 2014 You will need a program to compile the code from his Github, i suggest using Visual studio, easy installation and free. It is noted that OpenTK is needed to make the program work, so you will need to install that as well. all that is remaining is acctually getting the code from Github, run it in visual studio, and that should be it i belive ?, you may need to exit the corsair software thing, that might get in the way of making it run properly. Basically, yea. However, using Visual Studio 2012/2013 and NuGet (on by default), the OpenTK library should download automatically when you build. The pre-built Windows binaries can be downloaded from here: https://drive.google.com/open?id=0B8K-r-Qxbbn0QlMtNzR5S2xoZUE&authuser=0 Though, this has not been tested on any other machine than my own. Link to comment Share on other sites More sharing options...
SimpleStreet Posted December 10, 2014 Share Posted December 10, 2014 Basically, yea. However, using Visual Studio 2012/2013 and NuGet (on by default), the OpenTK library should download automatically when you build. The pre-built Windows binaries can be downloaded from here: https://drive.google.com/open?id=0B8K-r-Qxbbn0QlMtNzR5S2xoZUE&authuser=0 Though, this has not been tested on any other machine than my own. Just gave it a go and it seems to work nicely, however i had to get the code and change the amplifier down to like 1 to make you being able to see it following the music, other than that it looks very nice good job May i ask where you found the FFT algorithm ? NVM it seems like i cant read, i found it Link to comment Share on other sites More sharing options...
swarfega Posted December 10, 2014 Share Posted December 10, 2014 Just like the other project, it makes my keyboard lights freeze so doesn't work. Link to comment Share on other sites More sharing options...
Corski Posted December 10, 2014 Share Posted December 10, 2014 I also experience the LEDs feezing up. It seems to lag out after about a second of input. I tracked it down to the HidD_SetFeature method blocking after a couple of write calls. Could it be because I'm connected via 1 USB3.0 cable instead of 2 USB2.0 connections? Link to comment Share on other sites More sharing options...
Corski Posted December 10, 2014 Share Posted December 10, 2014 Ok, it appears to indeed be a synchronization issue. If I put in a delay after each HidD_SetFeature call by inserting System.Threading.Thread.Sleep(5), it works! Many thanks Billism and CalcProgrammer1! Link to comment Share on other sites More sharing options...
SimpleStreet Posted December 11, 2014 Share Posted December 11, 2014 Just like the other project, it makes my keyboard lights freeze so doesn't work. the only time i had the keyboard light freeze was when i tried to run the program when CUE was active, have you tried to close the software before running the program ? Link to comment Share on other sites More sharing options...
Battlerobot Posted December 16, 2014 Share Posted December 16, 2014 I'm getting an error when I try to run the program on Visual Studio An unhandled exception of type 'OpenTK.Audio.AudioDeviceException' occurred in OpenTK.dll Additional information: All attempts to open capture devices returned IntPtr.Zero. See debug log for verbose list. Link to comment Share on other sites More sharing options...
Billism Posted December 21, 2014 Author Share Posted December 21, 2014 I'm getting an error when I try to run the program on Visual Studio An unhandled exception of type 'OpenTK.Audio.AudioDeviceException' occurred in OpenTK.dll Additional information: All attempts to open capture devices returned IntPtr.Zero. See debug log for verbose list. Can you provide the stack trace? Also, can you check to make sure you do indeed have a default audio input device? For the purpose of this program, we want a loopback device, such as Windows' "Stereo Mix" as the default audio input device. Link to comment Share on other sites More sharing options...
Jeffery Sanders Posted December 21, 2014 Share Posted December 21, 2014 Works great here as well. Just had to turn off CUE, but that has already been stated. Thanks for porting!!! Link to comment Share on other sites More sharing options...
ScarredMecha Posted December 24, 2014 Share Posted December 24, 2014 Why is it so "noisy" when there's no sound input/output? EDIT: figured it out Link to comment Share on other sites More sharing options...
Darkthing Posted December 27, 2014 Share Posted December 27, 2014 Ok, it appears to indeed be a synchronization issue. If I put in a delay after each HidD_SetFeature call by inserting System.Threading.Thread.Sleep(5), it works! Many thanks Billism and CalcProgrammer1! It would appear mine also freezes after a second of input. I, however, am fairly illiterate as to solving these problems myself. Would anyone happen to know where Corski applied this proposed solution? Many thanks in advance! Link to comment Share on other sites More sharing options...
Corski Posted December 27, 2014 Share Posted December 27, 2014 In the file, KeyboardWriter.cs, add the following line of code: System.Threading.Thread.Sleep(1); Just after the call to write to the usb, near the of the file. i.e. just after this line: bool c = HidD_SetFeature(this.keyboardUsbDevice, ref usb_pkt[0], 65); If it doesn't work for 1 millisecond in the Sleep call, try a longer delay. In addition to this, you might also need to make sure that CUE is not running. Link to comment Share on other sites More sharing options...
vegito1991 Posted December 27, 2014 Share Posted December 27, 2014 i wonder if possible to get more colors option to run the visualization such as orange, violet, brown as the coding only limited to few basic colors such as pure red, green, white, black, skyblue, blue.... Link to comment Share on other sites More sharing options...
ScarredMecha Posted December 29, 2014 Share Posted December 29, 2014 i wonder if possible to get more colors option to run the visualization such as orange, violet, brown as the coding only limited to few basic colors such as pure red, green, white, black, skyblue, blue.... You can change the colors of the background and the bars by modifying the code in KeyboardWriter.cs, then compiling. public void Write(int iter, byte[] fftData) { // Rainbow to key lights for (int x = 0; x < 91; x++) { for (int y = 0; y < 7; y++) { this.red = (byte)(1.5f * (Math.Sin((x / 92.0f) * 2 * 3.14f) + 1)); this.grn = (byte)(1.5f * (Math.Sin(((x / 92.0f) * 2 * 3.14f) - (6.28f / 3)) + 1)); this.blu = (byte)(1.5f * (Math.Sin(((x / 92.0f) * 2 * 3.14f) + (6.28f / 3)) + 1)); this.SetLed((x + iter) % 92, y, red, grn, blu); } } // FFT Data to key lights for (int i = 0; i < 91; i++) { for (int k = 0; k < 7; k++) { if (fftData[(int)(i * 2.1 + 1)] > (255 / (15 + (i * 0.8))) * (7 - k)) { this.SetLed(i, k, 0x07, 0x07, 0x07); } } } The first nest of for loops produces the background lighting, while the second nest of for loops produces the lighting for the bars. You can replace "this.SetLed((x + iter) % 92, y, red, grn, blu);" with something like "this.SetLed((x + iter) % 92, y, 0x00, 0x00, 0x00);" if you want a static color, or you can program your own lighting effect if you have the ability. The last 3 arguments of SetLed are the brightness level of red, green, and blue channels respectively. You can put 0x00, 0x01, ..., all the way to 0x07. (8 levels of brightness each, including black/off) The second for loop nest has the line "this.SetLed(i, k, 0x07, 0x07, 0x07);" which can be changed to something else if you want. It is white by default. I managed to make a rainbowish lighting arrangement with a bit of tweaking, looks pretty cool imo [ame]https://www.youtube.com/watch?v=i9TFnZIe53I[/ame] Link to comment Share on other sites More sharing options...
vegito1991 Posted December 30, 2014 Share Posted December 30, 2014 You can change the colors of the background and the bars by modifying the code in KeyboardWriter.cs, then compiling. public void Write(int iter, byte[] fftData) { // Rainbow to key lights for (int x = 0; x < 91; x++) { for (int y = 0; y < 7; y++) { this.red = (byte)(1.5f * (Math.Sin((x / 92.0f) * 2 * 3.14f) + 1)); this.grn = (byte)(1.5f * (Math.Sin(((x / 92.0f) * 2 * 3.14f) - (6.28f / 3)) + 1)); this.blu = (byte)(1.5f * (Math.Sin(((x / 92.0f) * 2 * 3.14f) + (6.28f / 3)) + 1)); this.SetLed((x + iter) % 92, y, red, grn, blu); } } // FFT Data to key lights for (int i = 0; i < 91; i++) { for (int k = 0; k < 7; k++) { if (fftData[(int)(i * 2.1 + 1)] > (255 / (15 + (i * 0.8))) * (7 - k)) { this.SetLed(i, k, 0x07, 0x07, 0x07); } } } The first nest of for loops produces the background lighting, while the second nest of for loops produces the lighting for the bars. You can replace "this.SetLed((x + iter) % 92, y, red, grn, blu);" with something like "this.SetLed((x + iter) % 92, y, 0x00, 0x00, 0x00);" if you want a static color, or you can program your own lighting effect if you have the ability. The last 3 arguments of SetLed are the brightness level of red, green, and blue channels respectively. You can put 0x00, 0x01, ..., all the way to 0x07. (8 levels of brightness each, including black/off) The second for loop nest has the line "this.SetLed(i, k, 0x07, 0x07, 0x07);" which can be changed to something else if you want. It is white by default. I managed to make a rainbowish lighting arrangement with a bit of tweaking, looks pretty cool imo https://www.youtube.com/watch?v=i9TFnZIe53I thanks for the advice, and i also manage to build the same effect like you own in the video...=) Link to comment Share on other sites More sharing options...
ScarredMecha Posted December 31, 2014 Share Posted December 31, 2014 thanks for the advice, and i also manage to build the same effect like you own in the video...=) Just wondering, do you have any problem with the program crashing after a while? Mine tends to crash after a few minutes, randomly. Link to comment Share on other sites More sharing options...
vegito1991 Posted December 31, 2014 Share Posted December 31, 2014 Just wondering, do you have any problem with the program crashing after a while? Mine tends to crash after a few minutes, randomly. i lower down my frequency to 0.7 ~ 1.0f and put System.Threading.Thread.Sleep(5); in the private void SendUsbMessage(byte[] data_pkt). Not sure if works with you. My situation is the led only crash with those specific softwares such as CUE and steam, And the FF 13, 13-2 pc version also. Link to comment Share on other sites More sharing options...
ScarredMecha Posted January 3, 2015 Share Posted January 3, 2015 i lower down my frequency to 0.7 ~ 1.0f and put System.Threading.Thread.Sleep(5); in the private void SendUsbMessage(byte[] data_pkt). Not sure if works with you. My situation is the led only crash with those specific softwares such as CUE and steam, And the FF 13, 13-2 pc version also. Thanks a lot, that seems to have solved the freezing problem. Runs nice and smooth now! Also, here's some code for a more "true" looking rainbow effect (red, orange, yellow, green, blue, violet, back to red). I don't really know C#, but I figured out enough of it to make it work the way I want it to. Any optimization tips? :p: http://pastebin.com/JEzPsHaG Link to comment Share on other sites More sharing options...
vegito1991 Posted January 3, 2015 Share Posted January 3, 2015 Thanks a lot, that seems to have solved the freezing problem. Runs nice and smooth now! Also, here's some code for a more "true" looking rainbow effect (red, orange, yellow, green, blue, violet, back to red). I don't really know C#, but I figured out enough of it to make it work the way I want it to. Any optimization tips? :p: http://pastebin.com/JEzPsHaG actually you can just apply the rainbow motion effect to the spectrograph with this for (int i = 0; i < 91; i++) { for (int k = 0; k < 7; k++) { if (fftData[(int)(i * 2.1 + 1)] > (255 / (15 + (i * 0.8))) * (7 - k)) { this.red = (byte)(4.5f * (Math.Sin((i / 92.0f) * 2 * 3.14f) + 1)); this.grn = (byte)(4.5f * (Math.Sin(((i / 92.0f) * 2 * 3.14f) - (6.28f / 3)) + 1)); this.blu = (byte)(4.5f * (Math.Sin(((i / 92.0f) * 2 * 3.14f) + (6.28f / 3)) + 1)); this.SetLed((i + iter) % 92, k, red, grn, blu); } } } UpdateKeyboard(); or this one ---- invert rainbow---- for (int i = 0; i < 91; i++) { for (int k = 0; k < 7; k++) { if (fftData[(int)(i * 2.1 + 1)] > (255 / (15 + (i * 0.8))) * (7 - k)) { this.red = (byte)(4f * (Math.Sin((i % 15.0f) * 2 * 5.14f) + 1)); this.grn = (byte)(4f * (Math.Sin(((i % 15.0f) * 2 * 5.14f) - (6.28f / 3)) + 1)); this.blu = (byte)(4f * (Math.Sin(((i % 15.0f) * 2 * 5.14f) + (6.28f / 3)) + 1)); this.SetLed((i + iter) % 92, k, red, grn, blu); } } } UpdateKeyboard(); Link to comment Share on other sites More sharing options...
CalcProgrammer1 Posted January 6, 2015 Share Posted January 6, 2015 actually you can just apply the rainbow motion effect to the spectrograph with this That was a crude rainbow-ish thing I came up with using the sin functions. It isn't a true rainbow in that it never actually displays pure single color. To get a proper rainbow look into HSV (hue, saturation, value - aka HSB - hue, saturation, brightness) to RGB conversion. I just used HSV to RGB to make a much better rainbow effect on an Arduino with a WS2812b LED strip but the same technique works here. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.