00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdio.h>
00024 #include <limits.h>
00025 #include <time.h>
00026
00027 #include <sndfile.h>
00028 #include <Alloc.hh>
00029 #include <dsp/DSPOp.hh>
00030 #ifdef USE_FLAC
00031 #include <FLAC/all.h>
00032 #endif
00033 #ifdef USE_MERSENNE_TWISTER
00034 #include <MersenneTwister.h>
00035 #endif
00036
00037 #include "Config.h"
00038 #include "LocalMsg.h"
00039 #include "CfgFile.hh"
00040 #include "LogFile.hh"
00041 #include "SockOp.hh"
00042
00043
00044 #ifndef SAVESRV_HH
00045 #define SAVESRV_HH
00046
00047 #define SAVS_SNDFILE_MSGLEN 255
00048 #define SAVS_LOGENTRY_SIZE 255
00049 #define SAVS_TIMELEN 12
00050 #define SAVS_DEF_FRAMELEN 8192
00051 #define SAVS_DEF_FILETIME 60
00052
00053
00057 enum
00058 {
00059 SAVS_FORMAT_WAV = 0,
00060 SAVS_FORMAT_AIFF = 1,
00061 SAVS_FORMAT_FLAC = 2
00062 };
00063
00067 enum
00068 {
00069 SAVS_TYPE_PCM = 0,
00070 SAVS_TYPE_FLOAT = 1,
00071 SAVS_TYPE_ADPCM = 2,
00072 SAVS_TYPE_MSADPCM = 3
00073 };
00074
00075
00079 class clSaveSrv
00080 {
00081 bool bRun;
00082 int iFormat;
00083 int iType;
00084 int iBits;
00085 int iDither;
00086 int iFileTime;
00087 int iFileH;
00088 unsigned int uiRndSeed;
00089 long lFrameLen;
00090 long lFrameSize;
00091 char cpSockName[_POSIX_PATH_MAX + 1];
00092 char cpSavePath[_POSIX_PATH_MAX + 1];
00093 time_t ttFileStarted;
00094 stRawDataFirst sDataHdr;
00095 SNDFILE *spSndFile;
00096 #ifdef USE_FLAC
00097 FLAC__StreamEncoder *spFLACEnc;
00098 #endif
00099 clAlloc InFrame;
00100 clAlloc OutFrame;
00101 clAlloc NoiseFrame;
00102 clAlloc FLACFrame;
00103 clCfgFile Cfg;
00104 clDSPOp DSP;
00105 clSockOp SOp;
00106 #ifdef USE_MERSENNE_TWISTER
00107 MTRand *MTR;
00108 #endif
00109 bool Initialize ();
00110 bool ConnectStream ();
00111 bool CreateFile ();
00112 bool CreateFile2 ();
00113 void CreateFileName (char *);
00114 void ProcessLoop ();
00115 void Dither ();
00116 bool WriteData ();
00117 bool WriteData2 ();
00118 public:
00119 clLogFile Log;
00120 clSaveSrv ();
00121 ~clSaveSrv ();
00122 int Main (int, char **);
00123 void Stop () { bRun = false; }
00124 #ifdef USE_FLAC
00125 FLAC__StreamEncoderWriteStatus FLACWrite (
00126 const FLAC__StreamEncoder *, const FLAC__byte *, unsigned,
00127 unsigned, unsigned);
00128 void FLACMetaData (const FLAC__StreamEncoder *,
00129 const FLAC__StreamMetadata *);
00130 #endif
00131 };
00132
00133 #endif