| PortAudio Tips Quick-Links: |
|
Audio Files
Reading and writing audio from a file is one of the first things many people want to do with PortAudio. There are generally two considerations to keep in mind:
- PortAudio does not provide file I/O: In order to read and write audio data from or to a file, you must either write the code to parse the file yourself, or use an existing library such as libsndfile. Note that at this time, we do not know of any audio file I/O libraries with licenses that are as unrestrictive as the PortAudio License (most are LGPL).
- Don't do I/O in the callback: Because the callback is a sensitive place in most operating systems, it is a good idea to pass the data to anther thread for file I/O, rather than doing file I/O in the callback. Even if the OS docs say it's safe, doing I/O in the callback can cause unbounded delays which may cause Dropouts in playback. If passing audio data between threads sounds hard to you, you're right: it's not easy. However, the task is made much easier by PortAudio's new Blocking IO interface. (Users of the older version of PortAudio, V18, may be able to take advantage of the PABLIO interface). Because the blocking interface takes care of transferring audio between threads for you, it is safe to do file IO n the same thread as our blocking IO calls.
