11-05-2019 02:13 PM - edited 11-05-2019 02:54 PM
Hello,
I am having issues producing consistently timed sound loops using the attached VI. Can anyone point towards my error or provide any suggestions? The .Wav file was built in audacity at 44100kHz, but ultimately will be played mono.
Currently the first loop is ~3 seconds, while subsequent loops are ~5 seconds. I need the file to run exactly 5 seconds each time.
I have tried the following:
Thank you,
Frank
11-05-2019 05:18 PM
I don't have time to fully run this and try things, but a couple thoughts:
-From the help on Sound Output Configure.vi:
number of samples/ch specifies the number of samples per channel in the buffer. Use a large number of samples for continuous operations. Use a smaller number of samples if you want to use less memory. |
You need a larger buffer, not a smaller one. I'd set it to something like 2x the number of samples you want per loop, as Sound Output Write should block until it writes the data to the buffer.
From Sound Output Write.vi's help:
timeout (sec) specifies the time, in seconds, that the function waits for the sound operation to complete. This VI returns an error if the time elapses. The default is 10. If you set timeout (sec) to -1, the VI waits indefinitely. If you set timeout (sec) to 0, the VI returns immediately while the sound continues to play. You can use the Sound Output Wait VI to wait for playback to complete. |
This means you don't need the Wait function (why's it there if the timeout is 0 anyway?) as your Write function is waiting until it's finished playing anyway.
I would set the buffer to 1.5x your sample size and set the Write timeout to 0. This means your first loop will finish extremely quickly, as the Write doesn't wait, like it's doing right now. It will then start writing to the buffer, but stop (since it can't get the whole file in there) until half the file is written. Once half the file has been played, there's enough space in the buffer to write more file, then it writes it and the loop happens again.
Either way this is likely an issue with your buffer size- you only gave the buffer 1/2 second of space, and your file is 5 seconds long, so you're fighting the buffer constantly. The buffer is what makes it continuous, so give the buffer more room.
This will probably also work OK at a 1:1 buffer:file size application, but I've never used these sound functions so I don't know exactly.
11-07-2019 08:58 AM
I've not done much with LabVIEW's sound VIs, but I have used them, so I thought I'd give your Wave form a try. Here are some findings (I'll try to describe what I did so that you can try to reproduce it -- you'll learn much better if you "do it yourself"):
Better practice, of course, would have been to not try to "gulp" the entire file down all at once, but to read, say, a second at a time and play back the same way -- you'd certainly want to do this for recordings that last minutes. I'll leave this as a further Exercise for the Reader.
Bob Schor
When I ran this code, I heard what sounded like white noise that lasted for 5.03 seconds. I should note that