Thoughts on C Programming for Audio ----------------------------------- Four types of programs, based on the different possible combinations of "file I/O" and "stream I/O": Record: access input stream from the ADC, write it to a file Play: read from an audio file, send it as a stream to the DAC Process: in real time, access ADC and DAC, modify data in between Hack: in non-real time, access file, modify data, output to file (Combinations, modify while recording, add effects while playing, etc.) File reading (in C, not using PortAudio): Declare a file pointer Assign it to an existing file (get filename from command-line argument, or query to user, or command from user; limit user's choices if possible/appropriate) Make sure file exists; report error if there's a problem finding it Open the file (with fopen()); report an error if there's a problem opening it Sniff header; (report an error if it's not the right kind of file); determine file format, sample rate, channels, data format, length of file Allocate buffer memory for the samples you're going to want to read in Read in data, possibly within a 'for' loop that checks for end-of-file or some other stop cue Do something with the data File writing (in C, not using PortAudio): Declare a file pointer Assign it to a directory/filename (get filename from command-line argument, or query to user, or command from user; limit user's choices if possible/appropriate) Open the file (with fopen()); report an error if there's a problem opening it Write header -- file format, sample rate, channels, data format, length of file, etc. Open stream and read data, and/or put data into an array Do something with it (optional) Write data (from an input stream, or from an array or buffer you've created) Close file Wait for more instructions or quit Streaming audio from ADC and/or to DAC: Declare and define a data structure ('userData') for necessary ongoing data Declare and define a callback function In main function: Initialize and start audio stream Use an event loop to look for stopping command or other crucial event Modify userData as necessary for continuous control Clean up, wait for more instructions or quit