You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.8KB

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