paulstretch_cpp

PaulStretch
Log | Files | Refs | LICENSE

AOutputS.cpp (1830B)


      1 /*
      2   Copyright (C) 2009 Nasca Octavian Paul
      3   Author: Nasca Octavian Paul
      4 
      5   This program is free software; you can redistribute it and/or modify
      6   it under the terms of version 2 of the GNU General Public License 
      7   as published by the Free Software Foundation.
      8 
      9   This program is distributed in the hope that it will be useful,
     10   but WITHOUT ANY WARRANTY; without even the implied warranty of
     11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12   GNU General Public License (version 2) for more details.
     13 
     14   You should have received a copy of the GNU General Public License (version 2)
     15   along with this program; if not, write to the Free Software Foundation,
     16   Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
     17 */
     18 
     19 #include <stdio.h>
     20 #include <stdlib.h>
     21 #include "AOutputS.h"
     22 using namespace std;
     23 
     24 AOutputS::AOutputS(){
     25     handle=AF_NULL_FILEHANDLE;
     26 };
     27 
     28 AOutputS::~AOutputS(){
     29     close();
     30 };
     31 
     32 bool AOutputS::newfile(string filename,int samplerate,bool use32bit){
     33     close();//inchide un posibil fisier existent
     34 
     35     AFfilesetup afsetup=afNewFileSetup();
     36     if (use32bit) afInitSampleFormat(afsetup,AF_DEFAULT_TRACK,AF_SAMPFMT_TWOSCOMP,32);
     37     afInitChannels(afsetup,AF_DEFAULT_TRACK,2);
     38     afInitRate(afsetup,AF_DEFAULT_TRACK,samplerate);    
     39     
     40     handle=afOpenFile(filename.c_str(),"w",afsetup);
     41     if (handle==AF_NULL_FILEHANDLE){//eroare
     42 	afFreeFileSetup(afsetup);
     43 	return(false);
     44     };
     45     
     46     afSetVirtualSampleFormat(handle,AF_DEFAULT_TRACK,AF_SAMPFMT_TWOSCOMP,32);
     47     afFreeFileSetup(afsetup);
     48     return(true);
     49 };
     50 
     51 void AOutputS::close(){
     52     if (handle!=AF_NULL_FILEHANDLE){
     53 	afCloseFile(handle);
     54 	handle=AF_NULL_FILEHANDLE;
     55     };
     56 };
     57 
     58 void AOutputS::write(int nsmps,int *smps){
     59     if (handle==AF_NULL_FILEHANDLE) return;
     60     afWriteFrames(handle,AF_DEFAULT_TRACK,smps,nsmps);
     61 };
     62