Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

/root/src/subsynth/syn/Stream/AudioWorksOStream.h

Go to the documentation of this file.
00001 
00002 /****************** <SYN heading BEGIN do not edit this line> *****************
00003  *
00004  * subsynth - modular audio synthesizer
00005  * subsynth is (C) Copyright 2001-2002 by Kevin Meinert
00006  *
00007  * Original Author: Kevin Meinert
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Library General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Library General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Library General Public
00020  * License along with this library; if not, write to the
00021  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00022  * Boston, MA 02111-1307, USA.
00023  *
00024  * -----------------------------------------------------------------
00025  * File:          $RCSfile: AudioWorksOStream.h,v $
00026  * Date modified: $Date: 2002/02/04 04:14:04 $
00027  * Version:       $Revision: 1.1 $
00028  * -----------------------------------------------------------------
00029  *
00030  ****************** <SYN heading END do not edit this line> ******************/
00031 // This file loads a wave and sends samples to FIFO on sound engine.
00032 
00033 
00034 #include <iostream.h>
00035 #include <stdlib.h>
00036 #include <stdio.h>
00037 #include <unistd.h>
00038 #include <string.h>
00039 
00040 #include "aw.h"
00041 #include "awhwi.h"
00042 
00043 // Objects in the AudioWorks Hardware Test
00044 
00045 awEngine *myEngine ;
00046 
00047 awWave *myWave ;
00048 
00049 int main(int argc, char *argv[])
00050 {
00051     char aifc_file[256];
00052     sprintf(aifc_file, "%s", "../sounds/Tread_Noise.aifc") ;
00053 
00054     //initialize the AW system
00055     awInitSys();
00056     
00057     //Initialize an engine
00058     myEngine = awNewEng();
00059     if (awAttachEng(myEngine) != 0)
00060     {
00061         cout << "\nfailed to attach to engine\nengine dump:\n" << flush ;
00062         awPrint(myEngine);
00063         return 0 ;
00064     }
00065 
00066     // Set up waves and load files
00067     myWave = awNewWav();
00068     awName(myWave, aifc_file);
00069     if (awLoadWav(myWave) != 0)
00070     {
00071         cout << "\nfailed to open wave file\nwave dump:\n" << flush ;
00072         awPrint(myWave);
00073         return 0 ;
00074     }
00075 
00076     /*
00077         send wave samples to FIFO on sound engine
00078     */
00079 
00080     const int MAX_SAM_CNT = 75000 ;
00081 
00082     short sample[MAX_SAM_CNT] ;
00083     int nLeft = awGetProp(myWave, AWWV_NFRAMES) ;
00084     int offset = 0 ;
00085     int count ;
00086 
00087         
00088     //setup FIFO
00089       
00090     awFIFOi(AWFOUT_NFRAMES, 50000);
00091     awFIFOi(AWFOUT_SRATE, awGetProp(myWave, AWWV_SRATE));
00092     awFIFOi(AWFOUT_IMGFLD, 0);
00093     awEPFinish();
00094     awEPFlush();
00095 
00096     cout << "Attempting to play wave\n" ;
00097 
00098     count = (nLeft > MAX_SAM_CNT) ? MAX_SAM_CNT : nLeft;
00099 
00100     while (count > 0)
00101     {
00102         // Get samples from wave buffer
00103         awGetWavSam(myWave, AWWV_MONOIDX, offset, &count, sample) ;            
00104         // Puts <count> # of samples in <sample> variable from <myWave> starting at sample # <offset>
00105         // Note that <count> is updated to reflect how many samples were actually
00106         //   put in the <sample> array. 
00107 
00108         // If count is 0, then no more samples were written to <sample> array. Quit loop.
00109         if (count == 0) break ;
00110 
00111         // Write data to sound engine FIFO
00112         awWriteFIFO(count, AWFIFO_S16BIT_1C, sample) ;
00113 
00114         // Update parameters for more sample data
00115         offset += count ;
00116         nLeft -= count ;
00117         if (nLeft > MAX_SAM_CNT)
00118         {
00119           count = MAX_SAM_CNT ;
00120         } else {
00121           count = nLeft ;
00122         }
00123     }
00124 
00125     awEPFinish() ;
00126     awEPFlush() ;
00127     awExit() ; 
00128     return 0 ;
00129 }
00130 

Generated at Mon Apr 15 09:26:08 2002 for subsynth by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001