LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Play input data in serial connection in speakers ?

What happened when you used the queue and build array?
0 Kudos
Message 11 of 17
(834 Views)

Hi ajapyy,

 

It sounds like what you want to do is play back sound as you acquire sound samples from some source. You want to stream the sound. The Play Waveform express VI is not a good choice for this. It expects an array that has all the sound samples in it. It is great if you have a sound created from somewhere, but not so good for the point by point operation you want. Part of the reason is that everytime you call it, it configures the sound device, plays the sound samples you give it, and then closes the sound device.

 

One obvious option is to collect samples from your source in an array and then pass the entire array to the Play Waveform vi. I am geussing this is not what you want. It sounds like what you want is a continuous playback of sound from your source.

 

To do a point by point sound output you want Sound Output Write.vi This will require some more setup. You have to call Sound Output Configure to setup your sound device (speaker?). This creates a task ID that you pass to the Sound Output Write.vi. Get the task ID in an initialize step, and in the consumer loop call Sound Output Write.vi with the latest sample from the producer loop.

 

One thing to note about this. The producer consumer loop with ordinary while loops does not guarantee timing. So the playback of your sound may not be smooth. For your application it may be good enough.

 

 

 

 

Message 12 of 17
(826 Views)

If you intend on playing the audio as it comes in you will have problems.  What is the sampling rate of the audio beng sent over serial?  What is the baud of your serial port?  It looks like it defaults to 9600, and it takes 4 bytes to serial data, to get a single point of audio.  This means that if there is no time needed to process the serial data, and there is no time in giving that data to the output, then you will get 2400 points of data per second.

 

According to this wiki article audio sampling rates of 8Khz is only suitable for human speak without sibilance, I imagine 2K is just noise.

 

http://en.wikipedia.org/wiki/Sampling_(signal_processing)

 

But even with all of this you must take into account some processing time.  You'll also want to buffer it into some kind of queue or array, so your data points are evently spaced appart.

0 Kudos
Message 13 of 17
(816 Views)

my data is not sound, is another signal. sampling rate is 2K and baudrate is 500000bps which it achieved with using a PL2303 adaptor. 


Hooovahh wrote:

 

But even with all of this you must take into account some processing time.  You'll also want to buffer it into some kind of queue or array, so your data points are evently spaced appart.


this is my problem, how I can  buffer them to create array ?

I use producer/consumer in my VI. 

0 Kudos
Message 14 of 17
(795 Views)

clendon.gibson@canrig.com wrote:

Hi ajapyy,

 

It sounds like what you want to do is play back sound as you acquire sound samples from some source. You want to stream the sound. The Play Waveform express VI is not a good choice for this. It expects an array that has all the sound samples in it. It is great if you have a sound created from somewhere, but not so good for the point by point operation you want. Part of the reason is that everytime you call it, it configures the sound device, plays the sound samples you give it, and then closes the sound device.

 

One obvious option is to collect samples from your source in an array and then pass the entire array to the Play Waveform vi. I am geussing this is not what you want. It sounds like what you want is a continuous playback of sound from your source.

 

To do a point by point sound output you want Sound Output Write.vi This will require some more setup. You have to call Sound Output Configure to setup your sound device (speaker?). This creates a task ID that you pass to the Sound Output Write.vi. Get the task ID in an initialize step, and in the consumer loop call Sound Output Write.vi with the latest sample from the producer loop.

 

One thing to note about this. The producer consumer loop with ordinary while loops does not guarantee timing. So the playback of your sound may not be smooth. For your application it may be good enough.

 


if there is no way to play scaller samples, I must collect samples and then play them,. so this method can be good if other ways can not worked.

 

could you place a snippest from a VI that used Sound Output Write.vi ?

0 Kudos
Message 15 of 17
(794 Views)

@ajapyy wrote:

if there is no way to play scaller samples, 


Only if your sample rate is much higher, and your ability to output a value can occur much faster.  Maybe with real-time you could do this.  A simple solution is to build your samples into an array, then when your array is so large, put the whole array down to be played.  Depending on the size of the array you'll probably want to pre-allocate the values and use replace array.

0 Kudos
Message 16 of 17
(774 Views)

@ajapyy wrote:

my data is not sound, is another signal. sampling rate is 2K and baudrate is 500000bps which it achieved with using a PL2303 adaptor. 


Hooovahh wrote:

 

But even with all of this you must take into account some processing time.  You'll also want to buffer it into some kind of queue or array, so your data points are evently spaced appart.


this is my problem, how I can  buffer them to create array ?

I use producer/consumer in my VI. 


Could you tell us why you want to do this?  Maybe if we understood the why, we might be able to come up with a better solution.  🙂

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 17 of 17
(761 Views)