Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9006865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:31:35+00:00 2026-06-16T01:31:35+00:00

For a project, I’m retrieving a live audio stream via WebSockets from a Java

  • 0

For a project, I’m retrieving a live audio stream via WebSockets from a Java server. On the server, I’m processing the samples in 16Bit/8000hz/mono in the form of 8-bit signed byte values (with two bytes making up one sample). On the browser, however, the lowest supported samplerate is 22050 hz. So my idea was to “simply” upsample the existing 8000 to 32000 hz, which is supported and seems to me like an easy calculation.

So far, I’ve tried linear upsampling and cosine interpolation, but both didn’t work. In addition to sounding really distorted, the first one also added some clicking noises. I might also have trouble with the WebAudioAPI in Chrome, but at least the sound is playing and is barely recognizable as what it should be. So I guess no codec- or endianess-problem.

Here’s the complete code that gets executed when a binary packet with sound data is received. I’m creating new buffers and buffersources all the time for the sake of simplicity (yeah, no good for performance). data is an ArrayBuffer. First, I’m converting the samples to Float, then I’m upsampling.

//endianess-aware buffer view
var bufferView=new DataView(data),
//the audio buffer to set for output
buffer=_audioContext.createBuffer(1,640,32000),
//reference to underlying buffer array
buf=buffer.getChannelData(0),
floatBuffer8000=new Float32Array(160);


//16Bit => Float
for(var i=0,j=null;i<160;i++){
    j=bufferView.getInt16(i*2,false);
    floatBuffer8000[i]=(j>0)?j/32767:j/-32767;
}   

//convert 8000 => 32000
var point1,point2,point3,point4,mu=0.2,mu2=(1-Math.cos(mu*Math.PI))/2;
for(var i=0,j=0;i<160;i++){
    //index for dst buffer
    j=i*4;

    //the points to interpolate between
    point1=floatBuffer8000[i];
    point2=(i<159)?floatBuffer8000[i+1]:point1;
    point3=(i<158)?floatBuffer8000[i+2]:point1;
    point4=(i<157)?floatBuffer8000[i+3]:point1;


    //interpolate
    point2=(point1*(1-mu2)+point2*mu2);
    point3=(point2*(1-mu2)+point3*mu2);
    point4=(point3*(1-mu2)+point4*mu2);

    //put data into buffer
    buf[j]=point1;
    buf[j+1]=point2;
    buf[j+2]=point3;
    buf[j+3]=point4;
}

//playback
var node=_audioContext.createBufferSource(0);
node.buffer=buffer;
node.connect(_audioContext.destination);
node.noteOn(_audioContext.currentTime);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:31:36+00:00Added an answer on June 16, 2026 at 1:31 am

    Finally found a solution for this. The conversion from 16Bit to Float is wrong, it just needs to be

    floatBuffer8000[i]=j/32767.0;
    

    Also, feeding the API with a lot of small samples doesn’t work well, so you need to buffer some samples and play them together.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

our project uses HttpRuntime.Cache.Get and HttpRuntime.Cache.Insert for storing and retrieving data from the cache.
This project was coped almost exacatly from the example on the admob page but
Project being built on ASP.net v 2 VB.net IIS 6 SQL Server 2005 database
Project A is an android library project in my workspace(via project properties->android->library: is library).
Project Background: I am writing a map tile overlay class for java that can
My project has no errors, I'm able to run it via F5, but I
My project has a need to cache on the iOS device data retrieved from
Project: I am having a button that toggles the column length from 3 to
My project is using a websocket server. Only for testing purposes, I also have
Project : ASP.NET 3.5 Server : SQL Server 2008 One of the page in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.