LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

When .wav sound is recorded, the file, when played is streched two times original lenght

Solved!
Go to solution

Hello!

I have a problem with recording the sound to .wav file.

The .vi aquires sound normaly, and displays it on the front panel in real time. But when i record the file, and listen to it, everything is slowed down two times. So if I record 10s, then i listen to the file for 22s.

Any idea, where i go wrong?

I have attached a .jpg of the .vi, if you need the working .vi please let me know.

Nice day

 

0 Kudos
Message 1 of 8
(3,506 Views)

Always post your VI and say which Labview version you use. As we can not debug a picture. You will get feedback much faster this way. As many people will not help without code.

Now to your problem. First of all you should know that sound card do not support all sample rates. Which sample rates your sound card support you will find in the the manual. I am 99.9% sure your sound card will not support 50KHz as sample rate. But try 44100 Hz as all sound card support this sample rate and maybe also 22050 Hz. Then goto help in the toolbar select find examples and search for sound Open the Sound Input to File.vi file. This will give you a template for recording sound. You have to set the sample rate then open a sound file for write. The default value is 22050 Hz. And your program is using this. Hence sampling with 50 KHz your sound will be stretched by a factor somewhat over 2.

So to solve your problem. Set the sample rate on the daq card to 44100 Hz, give the correct info then open the sound file for write. And try again



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
Message 2 of 8
(3,499 Views)

I'm using LabView 2010, a NI 9234 analog card to aquire sound, a NI USB 9162 carrier and of course a microphone.

I tried like you suggested with 44100 sample rate (it's the same: 10s of record, ends up in a 23,2s of .wav file), and with 22050 sample rate (this one is much better, 10s of record, ends up in 11,7s of .wav file). Then I tried with some other rates, like: 18000,20000 its the same (11,7s), when i tried 17000Hz it was 7,6s.

I tried many combinations in between, but there isn't a smooth passage, like 7,6s then 7,8s, 8s and so on, if i would change the sample rate, but it only jumps from 7,6s straight to 11,7s, so I assume, there must be some other thing going on in the .vi, not only the sample rate, that i got wrong.

In the attachment there is my .vi.

Thanks again for the help.

0 Kudos
Message 3 of 8
(3,494 Views)

Please read my first post in this thread. And look at the example I suggested. As your program is now it will only be accurate with with a 22050 Hz sample rate. But you will never get an exactly 10 seconds recodring. and testing other samplerates than 22050 is just dumb as it will not work.

Your coding is not that bad for a beginner. But it has some flaws and the way you do things are dodgy. And your coding cause the trouble you see. Not some errors in the functions you  are using

What is your program exactly meant to do?



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 4 of 8
(3,482 Views)
Solution
Accepted by spitfir3

 
Hello.
 
Besides Coq Rouge instructions, there are two points you should check:


1. Sampling speed of 9234 card. Real one is not the one you request.  
    See manual page 15.  
     " When using the internal master timebase of 13.1072 MHz, the result is data rates of
       51.2 kS/s, 25.6 kS/s, 17.067 kS/s, and so on down to 1.652 kS/s, depending
       on the value of n."


So if you request 22050 as sample rate in DAQmx sample clock, the real speed will be 25600. Since wav file assumes 22050 (see point 2) you will have a  11.7 s for a real 10 seconds signal.


 
2. In "open wav file.vi" you should state the sound format that wil be recorded as header in wav file for further recovering.
Default is 22050, 2 channel 16 bits. That means that your requested recording at 50000 was really done a 51200
and recorded as it was 22050.
 
The wav format must be correct to recover the signal as is. (real sampling speed, 1 channel,16 bits in your case).

In this forum there are quite a lot of info about wav files.
 
 
Best regards.
Aipio

---------------------------------------------------------
"Qod natura non dat, Salmantica non praestat"
---------------------------------------------------------
Message 5 of 8
(3,478 Views)

Coq Rouge and alipio thanks for your help! I was able to solve this problem with the help of both of you.

First I added the sound format to sound file open.vi, and then change the values from default to 25600 and 1 channel. Now it works fine and 10s are 10s like it should be Smiley Happy .

 

Yes I'm a newby in all this stuff Coq Rouge, Im using LabView now for 3 weeks for some student project, that's why it's all so messy. This is only one fraction of the whole program, and I only copied it into a new .vi for easier demonstration of the problem. Beside that sound aquiering, i aquire 8 diferent temperatures and record them, and read some data from ECU unit of the car thru OBDII (this is the hardest part, if you can't get the databases from ECU manufacturer), and then display all this in a user freindly interface with lots of graphs, for easier analising of the data.

 

Thanks again for your help, you saved me a lots of time.

 

Nice day!

 

 

0 Kudos
Message 6 of 8
(3,461 Views)

A good point from alipio. I did not check what kind of equipment your DAQ unit was. In order to get a sample rate equal to 44100 you must at least use a  external time base equal to 44100*256=11.2896 MHz. Using this time base you will also be able to use 22050 as samplerate. If this is school project. Ask your teacher if he can supply you with some sort of generator creating this frequency. The manual will give you pointers how to set up your system.



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 7 of 8
(3,458 Views)

One last note. A 44100 (or 22050) Hz samplerate is only needed then you need to reproduce your data (wav file) through a sound card. If you only create a wav file for data storage. The wav file can have any samplerate  between 1 - 0xFFFFFFFF. It is stored as 4 bit integer in the wav file  



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 8 of 8
(3,454 Views)