paulstretch_cpp

PaulStretch
Log | Files | Refs | LICENSE

PAaudiooutput.cpp (1562B)


      1 /*
      2   PAaudiooutput.C - Audio output for PortAudio
      3   Copyright (C) 2002-2009 Nasca Octavian Paul
      4   Author: Nasca Octavian Paul
      5 
      6   This program is free software; you can redistribute it and/or modify
      7   it under the terms of version 2 of the GNU General Public License 
      8   as published by the Free Software Foundation.
      9 
     10   This program is distributed in the hope that it will be useful,
     11   but WITHOUT ANY WARRANTY; without even the implied warranty of
     12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13   GNU General Public License (version 2) for more details.
     14 
     15   You should have received a copy of the GNU General Public License (version 2)
     16   along with this program; if not, write to the Free Software Foundation,
     17   Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
     18 
     19 */
     20 
     21 #include <stdlib.h>
     22 #include "PAaudiooutput.h"
     23 
     24 Player *player=NULL;
     25 PaStream *stream=NULL;
     26 
     27 static int PAprocess(const void *inputBuffer,void *outputBuffer,
     28 		unsigned long framesPerBuffer,
     29 		const PaStreamCallbackTimeInfo *outTime,PaStreamCallbackFlags statusFlags,void *userData){
     30 	float *out=(float *)outputBuffer;
     31     player->getaudiobuffer(framesPerBuffer,out);
     32 
     33     return(0);
     34 };
     35 
     36 void PAaudiooutputinit(Player *player_,int samplerate){
     37     player=player_;
     38     if (stream) return;
     39     Pa_Initialize();
     40     Pa_OpenDefaultStream(&stream,0,2,paFloat32,samplerate,PA_SOUND_BUFFER_SIZE,PAprocess,NULL);
     41     Pa_StartStream(stream);
     42 };
     43 
     44 void PAfinish(){
     45     if (stream){
     46 	Pa_StopStream(stream);
     47 	Pa_CloseStream(stream);
     48 	Pa_Terminate();
     49     };
     50     stream=NULL;
     51 
     52 };
     53 
     54 
     55 
     56