Learn, Share, Build

September 24, 2017, at 07:24 AM

So I'm making a music visualizer on my RaspberryPi, and I'm attempting to output signals to GPIO pins in real time, synced to music.

My program uses a Clip object to play music, and a class I named WaveformGenerator to decode the music to a byte array in real time, for other threads to use and display.

Now the problem is, when WaveformGenerator is reading bytes in sync with the Clip object and saving it to static byte[] waveform as described here:

//fileIn is the same .wav file that the Clip object is playing
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(fileIn);
            int bytesPerFrame = audioInputStream.getFormat().getFrameSize();
            if (bytesPerFrame == AudioSystem.NOT_SPECIFIED) {
                bytesPerFrame = 1;
            int persecond = (int) Main.player.clip.getFormat().getSampleRate();
            //This is the number of bytes that should be played every 10ms
            int numBytes = (int)(persecond * (10/1000.0) * bytesPerFrame);
            waveform = new byte[numBytes];
            try {
                int numBytesRead = 0;
                int numFramesRead = 0;
                // Try to read numBytes bytes from the file.
                while((numBytesRead = audioInputStream.read(waveform))!=-1) {
                    // Calculate the number of frames actually read.
                    numFramesRead = numBytesRead / bytesPerFrame;
                    totalFramesRead += numFramesRead;

                    while(totalFramesRead>(Main.player.clip.getFramePosition())) {
//wait for Clip's current position to exceed this position, 
syncing the two inputstreams
            } catch (Exception ex) {
                // Handle the error...

The call Main.player.clip.getFramePosition(), (Where Main is the main class and holds a static reference to a custom musicplayer object that holds a reference to the Clip object that is playing sound), takes around a second to return, thus desyncing the two streams and missing out on a LOT of data on the sound. On my laptop, this call returns instantly with no problems, but on my RaspberryPi 3B it takes a long time to return.

I have no idea how to fix this or get around this. I am certain that it is this specific call that hangs my program through many hours of debugging.

Learn, Share, Build

Learn, Share, Build

so I want to add a '$' to my printf statement, can someone help me? I tried many ways in the above line of code but nothing seems to workI get the correct answer but not the $! I get errors when I try to add the $

Learn, Share, Build

Learn, Share, Build

What is issue here? I am trying to make adjacency list with util library like list, linkedlistBut after running the code it is generating

Learn, Share, Build

Learn, Share, Build

I'm using Spring Boot 15

Learn, Share, Build

Learn, Share, Build

In my project I use hibernate with jpa and now i try to add loggingThere is no exceptions, but logging does not work