html - play pcm data by webAudio API - Stack Overflow

Hi I am working on WebAudio API . I read HTML5 Web Audio API, porting from javax.sound and getting dist

Hi I am working on WebAudio API . I read HTML5 Web Audio API, porting from javax.sound and getting distortion link but not getting goodquality as in java API.I am getting PCM data from server in signed bytes . Then I have to changed this into it 16 bit format . for changing I am using ( firstbyte<<8 | secondbyte ) but I am not able to get good quality of sound . is there any problem in conversion or any other way to do for getting good quality of sound ?

Hi I am working on WebAudio API . I read HTML5 Web Audio API, porting from javax.sound and getting distortion link but not getting goodquality as in java API.I am getting PCM data from server in signed bytes . Then I have to changed this into it 16 bit format . for changing I am using ( firstbyte<<8 | secondbyte ) but I am not able to get good quality of sound . is there any problem in conversion or any other way to do for getting good quality of sound ?

Share Improve this question edited May 23, 2017 at 12:31 CommunityBot 11 silver badge asked Jan 3, 2012 at 10:28 user894554user894554 2685 silver badges18 bronze badges 3
  • 1 Code snippets are always helpful. – ebidel Commented Jan 3, 2012 at 16:58
  • can anyone tell me how to convert signed byte array to Float32Array ? – user894554 Commented Jan 4, 2012 at 9:28
  • Not too proud to upvote this, but this is a good question, as the official documentation skips the play PCM part, which would be the direct function, and focus on decodeAudioData(), which is more a 'helper'. – Léon Pelletier Commented Jan 20, 2013 at 20:04
Add a ment  | 

1 Answer 1

Reset to default 5

The Web Audio API uses 32-bit signed floats from -1 to 1, so that's what I'm going to (hopefully) show you how to do, rather than 16-bit as you mentioned in the question.

Assuming your array of samples is called samples and are stored as 2's pliment from -128 to 127, I think this should work:

var floats = new Float32Array(samples.length);
samples.forEach(function( sample, i ) {
  floats[i] = sample < 0 ? sample / 0x80 : sample / 0x7F;
});

Then you can do something like this:

var ac = new webkitAudioContext()
  , ab = ac.createBuffer(1, floats.length, ac.sampleRate)
  , bs = ac.createBufferSource();
ab.getChannelData(0).set(floats);
bs.buffer = ab;
bs.connect(ac.destination);
bs.start(0);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744848308a4596977.html

相关推荐

  • html - play pcm data by webAudio API - Stack Overflow

    Hi I am working on WebAudio API . I read HTML5 Web Audio API, porting from javax.sound and getting dist

    2天前
    80

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信