LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems about audio saving

Solved!
Go to solution

Hi all,

 

I have a problem regarding to saving audio files in Labview.

 

In my program, I acquire the audio signals from the PC sound card continuously and save them in a queue. After some preconditions are activated, these audio signals in the queue will be saved in a .wav file. This program is working well except one problem, which is the time mismatch in this .wav file. For example, I record a sound segment for about 30s, but after saving, this .wav file is just 21s long. It contains everything of the original recorded segment, but the time axis is compressed, which sounds like fast played. I searched all day and could not find any information about it.

 

These sound recording and saving functions are parts of one large program, and I am sorry I can't provide a single vi about it. I add the figures as below and I hope it helps. I am also willing to provide any further information.

 

PS: I do considered the mismatch caused by approximation of 't0' (posted in http://forums.ni.com/t5/LabVIEW/Time-mismatch-with-Sound-Input-Read-VI/td-p/1385404 )and compensate for that during the saving part. (reflected in figure2)

 

Thank you so much for the help!

 

part1.png

 

part2.png

0 Kudos
Message 1 of 5
(3,091 Views)

Hi Sun87,

I really like to help you but first I need some more information about your system.

Which LV version do you use? on which OS? What kind of sound card do you have?

If you get distortions, it seems that the sampling rate on your sound card doesn't match the sampling rate of the sound file. Depending on your sound card you may have a selectable sample rate.

It would be helpful to check whether the problem resides in LV or if it also occurs when other programs access the sound card. Does your .wav file sound well when played through Windows Media Player and iTunes respectively?

Please answer to my questions in order to figure out what our next steps will be.

Kind regards,
Vanessa
Applications Engineer, Munich

0 Kudos
Message 2 of 5
(3,064 Views)
Solution
Accepted by topic author Sun87

Hi Vans,

 

Thank you for your reply.

 

For your questions,

 

1. I am using Labview 2011 sp1 on Windows 7/Xp. I tested the program on both desktops and laptops. I am not sure about the sound card types, but since this problem occurs on several different computers, I think it's not the problem of sound cards.

 

2. For the sampling rate of sound card, actually I did check that. I read the waveform signals from the 'sound input read.vi' and the term 'dt' equals to 1 over the sampling rate. So I think the sampling rate of the sound card is correct.

 

Actually I just solved this problem by myself, but the solution is pretty weird. I find that there are two reasons that caused this problem.

 

1. When I get the sound signals from 'sound input read.vi', I firstly save them in a queue. After the acquisition is done, I save all signals in the queue to a .wav file. But in order to overcome the sound overlap and gap caused by the approximation of 't0', I will do a waveform signal re-organize before saving, as below. According to my knowledge, I think this 'dt' in the resulting waveform (pointed by the arrow) should be the same as before, but actually it's not and it becomes 1.

fig1.png

 

2. So to solve the first problem, I manually modify the 'dt' term again as below. After the modification I am sure the 'dt' is back to the correct value. But next is the weird thing, which is I saved the same waveform signal in two different ways, by using 'sound file write.vi' and 'sound file write simple.vi' respectively. The first method is the one I used before and it caused the problem I posted here. The second one works. In my program, I set the sampling rate as 16kHz, 16bits/sample and 1 channel. The .wav file from the first method has a strange bitrate as 705 bits/s and the .wav file from the second method has the right bitrate which is 256 bits/s.

fig2.png

 

I tested the program hundreds of times and every time it acted like I described above. I don't know if anyone else has ever faced the same problem like me, but I hope my solution can be helpful for others. And I also hope it will be useful for improving your LabView products.

 

Thank you for your time.

 

Best regards,

Sun87

 

0 Kudos
Message 3 of 5
(3,059 Views)

PS: this fast-played problem also happens when I want to save some .avi video files by using the 'IMAQ AVI Write Frame.vi'.

 

It's like I record the video from a webcam for about 30s, but the saved .avi file just has a length like 6s or 7s. The grab speed of the camera is 30fps and I used the 'MJPEG Compressor' as the video filter. In this part, the video file is saved in real-time, which means it's saved as soon as it's acquired. So I assume the video file should also be 30 fps, but it's not.

 

I don't know if there is any connection between these two problems, but I also appreciate anyone can bring any ideas.

0 Kudos
Message 4 of 5
(3,047 Views)

For the first method, you need to use the "Sound file write Open" and then set the correct sound format to confirm the sampling rate is the same as the one you actually used.

0 Kudos
Message 5 of 5
(1,128 Views)