ekg2

ekg/audio_wav.h

Idź do dokumentacji tego pliku.
00001 /* *.wav I/O stolen from xawtv (recode program) which was stolen from cdda2wav */
00002 /* Copyright (C) by Heiko Eissfeldt */
00003 
00004 typedef uint8_t   BYTE;
00005 typedef uint16_t  WORD;
00006 typedef uint32_t  DWORD;
00007 typedef uint32_t  FOURCC;       /* a four character code */
00008 
00009 /* flags for 'wFormatTag' field of WAVEFORMAT */
00010 #define WAVE_FORMAT_PCM 1
00011 
00012 /* MMIO macros */
00013 #define mmioFOURCC(ch0, ch1, ch2, ch3) \
00014   ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \
00015   ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24))
00016 
00017 #define FOURCC_RIFF     mmioFOURCC ('R', 'I', 'F', 'F')
00018 #define FOURCC_LIST     mmioFOURCC ('L', 'I', 'S', 'T')
00019 #define FOURCC_WAVE     mmioFOURCC ('W', 'A', 'V', 'E')
00020 #define FOURCC_FMT      mmioFOURCC ('f', 'm', 't', ' ')
00021 #define FOURCC_DATA     mmioFOURCC ('d', 'a', 't', 'a')
00022 
00023 typedef struct CHUNKHDR {
00024     FOURCC ckid;                /* chunk ID */
00025     DWORD dwSize;               /* chunk size */
00026 } CHUNKHDR;
00027 
00028 /* simplified Header for standard WAV files */
00029 typedef struct WAVEHDR {
00030     CHUNKHDR chkRiff;
00031     FOURCC fccWave;
00032     CHUNKHDR chkFmt;
00033     WORD wFormatTag;       /* format type */
00034     WORD nChannels;        /* number of channels (i.e. mono, stereo, etc.) */
00035     DWORD nSamplesPerSec;  /* sample rate */
00036     DWORD nAvgBytesPerSec; /* for buffer estimation */
00037     WORD nBlockAlign;      /* block size of data */
00038     WORD wBitsPerSample;
00039     CHUNKHDR chkData;
00040 } WAVEHDR;
00041 
00042 #define cpu_to_le32(x) (x)
00043 #define cpu_to_le16(x) (x)
00044 #define le32_to_cpu(x) (x)
00045 #define le16_to_cpu(x) (x)
00046 
00047 static void *audio_wav_set_header(const char *freq, const char *sample, const char *channels) {
00048         WAVEHDR *fileheader;
00049         int rate, nchannels, nBitsPerSample;
00050 
00051         if (!freq || !sample || !channels) 
00052                 return NULL;
00053 
00054         rate            = atoi(freq);
00055         nchannels       = atoi(channels);
00056         nBitsPerSample  = atoi(sample);
00057 
00058         fileheader = xmalloc(sizeof(WAVEHDR));
00059 
00060         /* stolen from xawtv && cdda2wav */
00061         unsigned long nBlockAlign = nchannels * ((nBitsPerSample + 7) / 8);
00062         unsigned long nAvgBytesPerSec = nBlockAlign * rate;
00063         unsigned long temp = /* data length */ 0 + sizeof(WAVEHDR) - sizeof(CHUNKHDR);
00064 
00065         fileheader->chkRiff.ckid    = cpu_to_le32(FOURCC_RIFF);
00066         fileheader->fccWave         = cpu_to_le32(FOURCC_WAVE);
00067         fileheader->chkFmt.ckid     = cpu_to_le32(FOURCC_FMT);
00068         fileheader->chkFmt.dwSize   = cpu_to_le32(16);
00069         fileheader->wFormatTag      = cpu_to_le16(WAVE_FORMAT_PCM);
00070         fileheader->nChannels       = cpu_to_le16(nchannels);
00071         fileheader->nSamplesPerSec  = cpu_to_le32(rate);
00072         fileheader->nAvgBytesPerSec = cpu_to_le32(nAvgBytesPerSec);
00073         fileheader->nBlockAlign     = cpu_to_le16(nBlockAlign);
00074         fileheader->wBitsPerSample  = cpu_to_le16(nBitsPerSample);
00075         fileheader->chkData.ckid    = cpu_to_le32(FOURCC_DATA);
00076         fileheader->chkRiff.dwSize  = cpu_to_le32(temp);
00077         fileheader->chkData.dwSize  = cpu_to_le32(0 /* data length */);
00078 
00079         return fileheader;
00080 
00081 }
00082 
 All Struktury Danych Pliki Funkcje Zmienne Definicje typów Wyliczenia Wartości wyliczeń Definicje