How to produce a continuous sound?
이전 댓글 표시
I need to produce a continuous sound output composed by a finite number of periodic samples but endlessly and without gaps or glitches. Is it possible to make in MATLAB running under Windows? Assume that the reproduction time makes it impossible to construct an array long enough to pass it to the sound generation routines.
Thanks in advanced.
Joe Ercolino
채택된 답변
추가 답변 (2개)
Daniel Shub
2011년 12월 12일
2 개 추천
Continuous sound is difficult for three reasons: you must continuously generate the sound samples, then push those samples to the sound card driver, and then the sound card hardware needs to fetch them.
Assuming you can generate your sound samples faster than real-time and have enough memory to buffer say 10s worth of sound, then even if the computer does something (like defragment your hard drive or scan for viruses), you should be okay. The more you buffer, the safer you are.
Transferring the data from the soundcard driver to the hardware can be problematic and is out of your control. USB and firewire devices have limited bandwidth. High sample rates and high channel counts can tax the system and result in dropped frames. You cannot guarantee that frames will not get dropped without specialized hardware. Under Microsoft Windows, ASIO cards can let you know if a frame gets dropped. If your computer is not doing anything special, your sample rate is 44.1 kHz, and you have 2 channel audio, then you will not drop very many frames. When your computer scans for viruses, you will drop more frames. You will also drop more frames if generating the sounds is time consuming.
You can more or less continuously stream a sound (up to about 2^32 samples) with the right interface. Neither sound nor audioplayer let you do this. You can use the winsound device in the Data Acquisition Toolbox. Even better is to use a port audio sound interface. I prefer the one with psychtoolbox, but pawavplay and playrecord also work.
Walter Roberson
2011년 12월 12일
0 개 추천
It is not possible in user mode under Windows 7. Windows is not designed for real-time work, and in user mode you never know when the kernel is going to interrupt you or for how long. If Windows decides that (say) it is a good time to defragment your disc, then there isn't anything you can do about that in user mode.
카테고리
도움말 센터 및 File Exchange에서 Using audio files에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!