ekg2
 All Struktury Danych Pliki Funkcje Zmienne Definicje typów Wyliczenia Wartości wyliczeń Definicje Grupay Strony
audio_wav.h
Idź do dokumentacji tego pliku.
1 /* *.wav I/O stolen from xawtv (recode program) which was stolen from cdda2wav */
2 /* Copyright (C) by Heiko Eissfeldt */
3 
4 typedef uint8_t BYTE;
5 typedef uint16_t WORD;
6 typedef uint32_t DWORD;
7 typedef uint32_t FOURCC; /* a four character code */
8 
9 /* flags for 'wFormatTag' field of WAVEFORMAT */
10 #define WAVE_FORMAT_PCM 1
11 
12 /* MMIO macros */
13 #define mmioFOURCC(ch0, ch1, ch2, ch3) \
14  ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \
15  ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24))
16 
17 #define FOURCC_RIFF mmioFOURCC ('R', 'I', 'F', 'F')
18 #define FOURCC_LIST mmioFOURCC ('L', 'I', 'S', 'T')
19 #define FOURCC_WAVE mmioFOURCC ('W', 'A', 'V', 'E')
20 #define FOURCC_FMT mmioFOURCC ('f', 'm', 't', ' ')
21 #define FOURCC_DATA mmioFOURCC ('d', 'a', 't', 'a')
22 
23 typedef struct CHUNKHDR {
24  FOURCC ckid; /* chunk ID */
25  DWORD dwSize; /* chunk size */
26 } CHUNKHDR;
27 
28 /* simplified Header for standard WAV files */
29 typedef struct WAVEHDR {
33  WORD wFormatTag; /* format type */
34  WORD nChannels; /* number of channels (i.e. mono, stereo, etc.) */
35  DWORD nSamplesPerSec; /* sample rate */
36  DWORD nAvgBytesPerSec; /* for buffer estimation */
37  WORD nBlockAlign; /* block size of data */
40 } WAVEHDR;
41 
42 #define cpu_to_le32(x) (x)
43 #define cpu_to_le16(x) (x)
44 #define le32_to_cpu(x) (x)
45 #define le16_to_cpu(x) (x)
46 
47 static void *audio_wav_set_header(const char *freq, const char *sample, const char *channels) {
48  WAVEHDR *fileheader;
49  int rate, nchannels, nBitsPerSample;
50 
51  if (!freq || !sample || !channels)
52  return NULL;
53 
54  rate = atoi(freq);
55  nchannels = atoi(channels);
56  nBitsPerSample = atoi(sample);
57 
58  fileheader = xmalloc(sizeof(WAVEHDR));
59 
60  /* stolen from xawtv && cdda2wav */
61  unsigned long nBlockAlign = nchannels * ((nBitsPerSample + 7) / 8);
62  unsigned long nAvgBytesPerSec = nBlockAlign * rate;
63  unsigned long temp = /* data length */ 0 + sizeof(WAVEHDR) - sizeof(CHUNKHDR);
64 
65  fileheader->chkRiff.ckid = cpu_to_le32(FOURCC_RIFF);
66  fileheader->fccWave = cpu_to_le32(FOURCC_WAVE);
67  fileheader->chkFmt.ckid = cpu_to_le32(FOURCC_FMT);
68  fileheader->chkFmt.dwSize = cpu_to_le32(16);
69  fileheader->wFormatTag = cpu_to_le16(WAVE_FORMAT_PCM);
70  fileheader->nChannels = cpu_to_le16(nchannels);
71  fileheader->nSamplesPerSec = cpu_to_le32(rate);
72  fileheader->nAvgBytesPerSec = cpu_to_le32(nAvgBytesPerSec);
73  fileheader->nBlockAlign = cpu_to_le16(nBlockAlign);
74  fileheader->wBitsPerSample = cpu_to_le16(nBitsPerSample);
75  fileheader->chkData.ckid = cpu_to_le32(FOURCC_DATA);
76  fileheader->chkRiff.dwSize = cpu_to_le32(temp);
77  fileheader->chkData.dwSize = cpu_to_le32(0 /* data length */);
78 
79  return fileheader;
80 
81 }
82