How to produce a continuous sound?
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (2)
Daniel Shub
am 12 Dez. 2011
2 Stimmen
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
am 12 Dez. 2011
0 Stimmen
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.
Kategorien
Mehr zu Using audio files finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!