how to play pcm data in chrome

1,001 views
Skip to first unread message

npde...@gmail.com

unread,
Nov 10, 2014, 10:10:00 PM11/10/14
to discuss...@googlegroups.com
hi everybody
how to play pcm data in chrome,using javascript(WEB APP).

//incomingData is Float32Array,pcm data.
this.Play = function(incomingData, endCallback)
{
if(incomingData && incomingData.length > 0)
{
var length = incomingData.length;
var channelBuffer = this.AudioContext.createBuffer(this.ChannelCount, length, this.SampleRate); // Create Mono Source Buffer from Raw Binary 

//because channelBuffer doesn't support copyToChannel method ,data cann't be put to channelBuffer
                        //channelBuffer.copyToChannel(incomingData, 0, 0); //not supported in latest Chrome
var source = this.AudioContext.createBufferSource(); // Create Sound Source
source.buffer = channelBuffer; // Add Buffered Data to Object 
source.connect(this.AudioContext.destination); // Connect Sound Source to Output source.
source.onended = endCallback;
source.start(0);
}
}

npde...@gmail.com

unread,
Nov 10, 2014, 10:17:03 PM11/10/14
to discuss...@googlegroups.com


在 2014年11月11日星期二UTC+8上午11时10分00秒,npde...@gmail.com写道:
hi everybody
how to play pcm data in chrome,using javascript(WEB APP).

//incomingData is Float32Array,pcm data.
this.Play = function(incomingData, endCallback)
{
if(incomingData && incomingData.length > 0)
{
var length = incomingData.length;
var channelBuffer = this.AudioContext.createBuffer(this.ChannelCount, length, this.SampleRate); // Create Mono Source Buffer from Raw Binary 

//because channelBuffer doesn't support copyToChannel method ,data cann't be put to channelBuffer
                        //1.  channelBuffer.copyToChannel(incomingData, 0, 0); //not supported in latest Chrome
 
                           //2.  channelBuffer.getChannelData(0) = incomingData;  //does't work,the value of the array item is zero(by default) 

                          //3.   channelBuffer.getChannelData(0).set(incomingData); //the same as 2

Silvia Pfeiffer

unread,
Nov 11, 2014, 1:08:21 AM11/11/14
to discuss...@googlegroups.com
http://stackoverflow.com/questions/8710846/play-pcm-data-by-webaudio-api
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "discuss-webrtc" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to discuss-webrt...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

npde...@gmail.com

unread,
Nov 11, 2014, 4:37:49 AM11/11/14
to discuss...@googlegroups.com
thanks ,but it doesn't work.
ab.getChannelData(0).set(floats);  //this step just set the value of buff copy ,not the channelbuffer

在 2014年11月11日星期二UTC+8下午2时08分21秒,Silvia Pfeiffer写道:
Reply all
Reply to author
Forward
0 new messages