home *** CD-ROM | disk | FTP | other *** search
- /*
- * Program: SDK_EX4.C
- * Author: Philip VanBaren
- * Purpose: This program demonstrates how to use the Media Vision SDK routines
- * to do simple continuous data input.
- */
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
-
- #include <pcmio.h>
-
- extern int DMARunning; /* SDK flag that indicates when DMA has been started */
-
- #define IRQ -1 /* -1 means use the default value */
- #define DMA -1 /* -1 means use the default value */
- #define DMASize 16 /* 16k DMA buffer */
- #define DMADivisions 4 /* 4 divisions in this buffer */
-
- #define SamplingRate 22050
- #define StereoFlag 0 /* When this is 1, the data is interleaved left/right */
- #define CompressionFlag 0
- #define SampleSize 16 /* Number of bits per sample, 8 or 16 */
-
- #define BUFFERS 2
- #define BUF_LEN 10000
- int in_buf[BUFFERS][BUF_LEN];
- int buf_ready[BUFFERS];
- int current_buffer=0;
-
- /*
- * This function is called when the PAS code is finished with a buffer.
- */
- void far callback(void)
- {
- buf_ready[current_buffer]=1;
- if(++current_buffer>=BUFFERS)
- current_buffer=0;
- }
-
- void main(void)
- {
- int record_buffer=0;
- int process_buffer=0;
- int i;
- for(i=0;i<BUFFERS;i++)
- buf_ready[i]=0;
-
- /*
- * Initialize ProAudio stuff
- */
- if(OpenPCMBuffering(DMA,IRQ,DMASize,DMADivisions)!=0)
- puts("Error trying to open PCM buffering.");
- else if(PCMState(SamplingRate,StereoFlag,CompressionFlag,SampleSize)!=0)
- puts("Error setting sample rate.");
- else
- {
- /*
- * Start recording the first buffer.
- */
- if(RecordThisBlock((char *)in_buf[record_buffer],(long)BUF_LEN*2,callback)==0)
- {
- ClosePCMBuffering();
- puts("Error recording block.");
- exit(1);
- }
- /*
- * Flag buffer as busy. When it has been filled, this value will
- * be set back to 1.
- */
- buf_ready[record_buffer]=0;
- if(++record_buffer>=BUFFERS)
- record_buffer=0;
-
-
- while(!kbhit())
- {
- /*
- * Set up another block for recording when the current one is done.
- */
- if(QueueThisBlock((char *)in_buf[record_buffer],(long)BUF_LEN*2,callback)!=0)
- {
- ClosePCMBuffering();
- puts("Error recording block.");
- exit(1);
- }
- /*
- * Flag buffer as busy. When it has been filled, this value will
- * be set back to 1.
- */
- buf_ready[record_buffer]=0;
- if(++record_buffer>=BUFFERS)
- record_buffer=0;
-
- /*
- * Wait for a buffer to become ready.
- */
- while(!kbhit() && !buf_ready[process_buffer]);
-
- /*
- * Process in_buf[process_buffer] here.
- */
- printf("%d ",process_buffer);
-
- /*
- * Update buffer pointer
- */
- if(++process_buffer>=BUFFERS)
- process_buffer=0;
- }
- }
- /*
- * You MUST call this function before ending the program, else things won't
- * work right the next time you try to run the program. This is critical to
- * remember when debugging the program, because in debugging you often quit the
- * program before it runs to completion. The only way I know of to recover
- * if this function is NOT called is to reboot the computer!
- */
- ClosePCMBuffering();
- }
-
-