Idź do dokumentacji tego pliku.00001
00002
00003
00004 typedef uint8_t BYTE;
00005 typedef uint16_t WORD;
00006 typedef uint32_t DWORD;
00007 typedef uint32_t FOURCC;
00008
00009
00010 #define WAVE_FORMAT_PCM 1
00011
00012
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;
00025 DWORD dwSize;
00026 } CHUNKHDR;
00027
00028
00029 typedef struct WAVEHDR {
00030 CHUNKHDR chkRiff;
00031 FOURCC fccWave;
00032 CHUNKHDR chkFmt;
00033 WORD wFormatTag;
00034 WORD nChannels;
00035 DWORD nSamplesPerSec;
00036 DWORD nAvgBytesPerSec;
00037 WORD nBlockAlign;
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
00061 unsigned long nBlockAlign = nchannels * ((nBitsPerSample + 7) / 8);
00062 unsigned long nAvgBytesPerSec = nBlockAlign * rate;
00063 unsigned long temp = 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 );
00078
00079 return fileheader;
00080
00081 }
00082