au.h (1217B)
- #include <unistd.h> // write()
- #include <inttypes.h> // uint32_t
- #include <stdio.h> // perror()
- struct au_header {
- uint32_t offset;
- uint32_t length;
- uint32_t encoding;
- uint32_t samplerate;
- uint32_t channels;
- };
- enum au_header_encoding {
- AU_ENCODING_8B_G711_ULAW = 01,
- AU_ENCODING_8B_LPCM = 02,
- AU_ENCODING_16B_LPCM = 03,
- AU_ENCODING_24B_LPCM = 04,
- AU_ENCODING_32B_LPCM = 05,
- AU_ENCODING_32B_FPCM = 06,
- AU_ENCODING_64B_FPCM = 07,
- AU_ENCODING_4B_G721_ADPCM = 23,
- AU_ENCODING_3B_G723_ADPCM = 25,
- AU_ENCODING_8B_G711_ALAW = 27,
- };
- static void
- be32enc(void *buf, uint32_t in)
- {
- char *out = (char *)buf;
- out[0] = (in >> 24) & 0xff;
- out[1] = (in >> 16) & 0xff;
- out[2] = (in >> 8) & 0xff;
- out[3] = (in >> 0) & 0xff;
- }
- static int
- write_au_header(int fd, struct au_header *header)
- {
- char buf[4];
- uint32_t *value = (uint32_t*)header;
- if(4 != write(fd, "\x2E\x73\x6E\x64", 4))
- {
- perror("write(fd, signature, 4)");
- return -1;
- }
- // 5: number of params in struct au_header
- for(int i = 0;i<5; i++)
- {
- // 32 bits = 4 octets
- be32enc(buf, *(value+i));
- if(4 != write(fd, buf, 4))
- {
- perror("write(fd, au_header, 4)");
- return -1;
- }
- }
- return 0;
- }