Quick method for handling arrays to generate waveforms

I'm currently working on optimizing the code for my web application. While it functions, the performance is a bit slow and I am looking to make improvements:

The main concepts behind the code are:

  • The function retrieves the current buffer and converts it into an array with a sampling rate of 50ms
  • Each element in the array must be rendered using the updateWave function at every sampling interval
  • Subsequently, for each iteration, the new elements need to be rendered while excluding the previously rendered data from the previous buffer

Here's the updated (simplified) code:

private String data = "";   
// This function renders the waveform on the page smoothly and accurately by passing a random double value every 50ms    
public void updateWave(String waveValue){
    wave.renderWaveOnFly(Double.parseDouble(waveValue));
}

public final native void waveIt()/*-{   
    var instance = this;
    $wnd._waver = setInterval(function(){
            // Retrieving current buffer data from the flash interface
            // Note: All data in the buffer is fetched
            var newData = $wnd.Recorder.audioData().toString();
            var strData = newData.toString();
            var arr = strData.split(',');
            var arrEl = arr.pop();
            <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b8d1d6cbccd9d6dbdd96f8dbd7d596d5c1dbd7dcdd96cfd9cedddfcfcc96cbd0d7cfdbd9cbdd96dbd4d1ddd6cc96ebd0d7cfdbd9cbdd">[email protected]</a>::updateWave(Ljava/lang/String;)(arrEl.toString());
        }
    ,50);
}-*/;

// This function renders the waveform based on a mathematical function 
// resulting in smooth rendering and responsive UI
public final native void waveItByRandomValue()/*-{  
    var instance = this;
    $wnd._waver = setInterval(function(){
            var arrEl = Math.cos(i++/25) - 0.2 + Math.random() * 0.3;
            <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fd94938e899c939e98d3bd9e9290d390849e929998d38a9c8b989a8a89d38e95928a9e9c8e98d39e9194989389d3ae95928a9e9c8e98">[email protected]</a>::updateWave(Ljava/lang/String;)(arrEl.toString());
        }
    ,50);
}-*/;

public native void renderWaveOnFly(Double _data)/*-{
    var data = $wnd.data;
    data.push(_data);
    $wnd._waveform.update({
        data: data
    });
}-*/;

The waveIt() function reads data from a flash interface (linked to a microphone). In a demo scenario, I initiate recording for 10 seconds, then call waveIt(). After 10 seconds, I clear the interval using clearInterval($wnd._waver)

Current Issues:

  • waveIt() function runs slowly, causing unresponsive UI and delayed rendering
  • Contrastingly, waveItByRandomValue() renders quickly without affecting UI responsiveness

I am seeking new strategies to tackle this issue effectively.

To view my project live, visit:

For further elaboration, check out my discussion on Google Groups:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JSP generates unconventional HTML output

I'm encountering a strange issue with one of my JSP pages. It seems like the HTML is not being fully rendered. The output looks like this: <html> ... <table> ... </table> <div id= So, the last line is exactly what ...

Error: Axios header not refreshing automatically in React. User must manually refresh the page

After logging in, I want to update the JWT token in the header before redirecting to the home page. Login.tsx ... const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => { event.preventDefault(); const data = new FormData(event.curr ...

`Can you explain how to specify the elements of an array within a form using AngularJS?`

Below is an array containing objects: //Data source code $scope.data = [ { name: 'Lname', items: [{ label: 'Lastname', type: 'text', model: 'lname', pattern: '/^[a-zA-Z]$/', ...

The foundation of the Selenium framework seems to be malfunctioning

As a beginner in Selenium, I attempted to create a basic framework that isn't functioning correctly. I utilized TESTNG and DataProvider annotation. If anyone could provide assistance or recommend an alternative framework/code, it would be greatly app ...

Creating unique random shapes within a larger shape on a canvas, as shown in the image

I have a parent rectangle and would like to add up to 10 or fewer rectangles on the right-hand side corner of the parent rectangle, as shown in the image below: I attempted to write code to achieve this, but the alignment is off-center from the parent rec ...

The NodeJS req.query is providing inaccurate information

When I send a JSON from the Client-Side to a NodeJS Server, it looks like this: $.ajax({ type: "POST", dataType: "jsonp", url: "www.xyz.com/save", data: { designation: "Software Developer", skills: [ "", "ASP.NET", "P ...

Conditional rendering with React.js in the DOM

Just starting out with React and encountering an issue with rendering using reactDom: index.js import ReactDOM from 'react-dom'; import A from 'components/A'; import B from 'components/B'; render(<A />, document.getEl ...

The error encountered with react createRef was caused by a faulty implementation

Here is the revised question post completing the answer In this particular code snippet, I have encountered an issue where my file browser opens correctly upon submission, however, the updated state is not reflected when I click the final submit button. ...

Angular allows you to easily upload multiple files at once

I am currently facing an issue while attempting to upload multiple files. There seems to be an error somewhere in my code that I have yet to identify. The problem is that nothing is being displayed in the console, but the 'uploadData' appears to ...

What could be causing the malfunction of DirectionalLight in three.js?

While working on a project in three.js to create a ring, I encountered an issue with lighting. The camera setup is fine, but I'm facing difficulties with lighting. Below is my code snippet: <script src="three.js"></script> <sc ...

Choose the initial search result without actually opening it using jQuery

I am working on an HTML file that contains multiple input fields, which get automatically filled when a corresponding item is selected from the auto-complete feature. Here is a snippet of my HTML code: <table class="table table-bordered"> <u ...

The Document.querySelector() method is not displaying every element

As a beginner, I am currently exploring the world of relative CSS selectors and JSPath for my automation scripts. During my journey, I noticed that there are differences in the return statements between these two methods. Below is an example demonstrating ...

Adjust the position of the footer up or down based on changes in page content height

If I have jQuery at my disposal, how can I achieve the following task? There is a div on the page with dynamic content and no fixed height. The height of this div changes as users type and content appears or disappears accordingly. Although everything is ...

The Transparent Quirk in Three.js

Hey there! I'm working on displaying a 3D avatar on my website that allows users to apply textures to the character. I'm hoping to enable users to create transparent textures so they can see the model underneath. Right now, when implementing tran ...

Can you explain how JSON and AJAX are different when used in conjunction with jQuery?

Is it true that JSON serializes all data, preventing problems with client-side issues like cross-browser support? I've found using AJAX with jQuery to be straightforward, but I'm still unclear about the differences. I have also come across anot ...

Error: The function pajinate is not defined for jQuery([...])

I'm currently experiencing difficulties with the jQuery Pajinate plugin after migrating to a new host. The script was functioning properly on my previous hosting platform, but now I seem to be encountering some problems. Below is the code snippet: ...

Explore search results that include values nested within map arrays

I have an array with multiple objects, each containing a nested array of subValues. My goal is to filter components based on search criteria. While I can successfully search the parent level objects' values, I am struggling with filtering based on the ...

What is the method for extracting a list of properties from an array of objects, excluding any items that contain a particular value?

I have an array of objects, and I want to retrieve a list with a specific property from those objects. However, the values in the list should only include objects that have another property set to a certain value. To clarify, consider the following example ...

The AWS Lambda function utilizing Puppeteer is encountering an issue when trying to switch to a new

My Puppeteer project running in AWS Lambda stopped working since yesterday. I made a small code change, but it keeps getting stuck at the browser's newPage method, even after reverting my changes. I am utilizing the lambda starter kit project from: h ...

Guide to utilizing Selenium to extract frames

Using Selenium, I fetched the content of this page ... <frameset rows="0,0,*" frameborder="no" border="0"> <frame name="applet_container" scrolling="no" marginwidth="0" marginheight="0" noresize src=""> <frame name="javascript_conta ...