Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

real time record using microphone and play back with loudspearker

Hi there, I am trying to use Producer/Consumer pattern to record sound and play back with loudspearker.

I have data acquisition in the producer loop, and play sound in the consumer loop.

As I want it be real time (dont want too much delay from record time to playback time), so I set it as just take 0.1 second sound in the loop, and then play it back.

 

Now the problem is: when I run the program, there s a significant gap sound, like "ta...ta...ta..." every 0.1 second. Is there a way to solve the problem?

 

Attached is my VI, I replaced the data acquisition by a sine wave, thus you can run my VI without a microphone.

 

 

0 Kudos
Message 1 of 10
(4,187 Views)

Hey Linda,

Is there any specific reason on why you are using producer consumer architecture. I tried changing your code a bit  it seems to be working fine. Have a look at it. Hope this works for you.

 

Cheers

lab

0 Kudos
Message 2 of 10
(4,169 Views)

hi, lab_boy,

 

Thank you for your reply, I use the producer consumer architecture because I want to add some signal processing later and that might cost some time.

 

I tried your modified VI, there is still some noise there. Is there a way make it play as smooth as playing a long waveform, (eg, 5 second) w/o loop? 

 

Thanks again 

 

0 Kudos
Message 3 of 10
(4,165 Views)

Hi linda_zhuna,

 

May I ask why will constantly generating/acquiring data not work?  You mentioned you take only .1 second intervals because you want the data to be close to real time as possible.  However, Producer/Consumer design pattern writes the data to the queue in the producer loop, while the consumer loop polls the dequeue waiting for data. As soon as there is data available then the consumer loop executes its process.  The queues are similar to a buffer and the first data into the queue is the first data out.  You are hearing a break every .1 seconds because the data is being generated again from the very beginning rather than picking up where it left off.  What happens when you set the duration to 5 seconds rather than .1 seconds?  

Regards,


h_baker
National Instruments
Applications Engineer
0 Kudos
Message 4 of 10
(4,155 Views)

Hi, h_baker 

 

Thanks for your reply:)

 

I use the sine wave here just for simple. In my real application, I will use microphones for sound acquisition of real time sound.

So if I use 5 seconds instead of 0.1 second, then when I hear it, it will be 5 seconds delay... Thats why I set it as 0.1 second, thus I will not feel the delays if its only .1s.

 

 

  

0 Kudos
Message 5 of 10
(4,152 Views)
Why are you using the waveform subset vi?  This is what is breaking up your signal.  Delete this from your code and you should hear a constant tone because the data is queing and dequeing as explained in my last post.  This should sound much better to you.
Regards,


h_baker
National Instruments
Applications Engineer
0 Kudos
Message 6 of 10
(4,138 Views)

Hi, I think I didn't explain my VI well. The sine waveform generator and the waveform subset vi are both used as simulation. In my real program, that part will be replaced by data acquisition with microphones.

The only reason I use the sine and waveform subset here is because I am afraid not everyboday on the forums has a microphone to play with my program!

 

Again, as I mentioned before, what I want is a real time playback, which means I want to collect data every 0.1 seconds, and at the same time play back, this is my idea to keep it "REAL TIME", although there is 0.1 second delay at the beginning.

If it is set as 1 second, of course there will be no gap noise, but that is not what I want, because there will be 1 second delay, thats too long for me.

 

Is there anybody can help me?

 

 

0 Kudos
Message 7 of 10
(4,131 Views)
I guess I do not understand why you are using the waveform subset vi.  Given how it is set up, I am assuming that you will acquire the data from the microphones via different channels using a DAQ Assistant.  It appears that you are using the waveform subset vi to separate one signal from the group for playback.  Please feel free to correct me and explain more if this is not the case.  If my assumptions are correct, then try using the Index Waveform Array.vi instead.  This will allow you to stream one channel for playback without having to worry about the gap. 
Regards,


h_baker
National Instruments
Applications Engineer
0 Kudos
Message 8 of 10
(4,101 Views)

As I said, the sine generator and the waveform subset are all my simulation part.

 

Well, please ignor them and see this VI, question2.vi.

Here I deleted all the sine part but use my data acquisition as the input. It get a 0.1 second long waveform every 0.1 second from the microphone, and at the same time playing it back using the loudspeaker. If you run it, u will found there s significant noise.

 

I hope this time you could understand my problem, thanks:)

0 Kudos
Message 9 of 10
(4,095 Views)
Here is the new vi
0 Kudos
Message 10 of 10
(4,094 Views)