44#define WAV_BUF_SIZE    320 
   46#define WAV_HEADER_SIZE 44 
   58#if __BYTE_ORDER == __LITTLE_ENDIAN 
   64#if __BYTE_ORDER == __BIG_ENDIAN 
   66    (((((b)      ) & 0xFF) << 24) | \ 
   67    ((( (b) >>  8) & 0xFF) << 16) | \ 
   68    ((( (b) >> 16) & 0xFF) <<  8) | \ 
   69    ((( (b) >> 24) & 0xFF)      )) 
   71    (((((b)      ) & 0xFF) <<  8) | \ 
   72    ((( (b) >>  8) & 0xFF)      )) 
   73#define ltohl(b) htoll(b) 
   74#define ltohs(b) htols(b) 
   76#error "Endianess not defined" 
   83    unsigned short format, 
chans, bysam, bisam;
 
   84    unsigned int freq, bysec;
 
   89    if (fread(&format, 1, 2, f) != 2) {
 
   93    if (
ltohs(format) != 1) {
 
   94        ast_log(
LOG_WARNING, 
"Not a supported wav file format (%d). Only PCM encoded, 16 bit, mono, 8kHz/16kHz files are supported with a lowercase '.wav' extension.\n", 
ltohs(format));
 
   97    if (fread(&
chans, 1, 2, f) != 2) {
 
  105    if (fread(&freq, 1, 4, f) != 4) {
 
  110    if ((freq != 8000 && freq != 16000) || freq != hz) {
 
  115    if (fread(&bysec, 1, 4, f) != 4) {
 
  120    if (fread(&bysam, 1, 2, f) != 2) {
 
  124    if (
ltohs(bysam) != 2) {
 
  128    if (fread(&bisam, 1, 2, f) != 2) {
 
  133    if (fseek(f,hsize-16,SEEK_CUR) == -1 ) {
 
 
  142    int type, size, formtype;
 
  144    if (fread(&
type, 1, 4, f) != 4) {
 
  148    if (fread(&size, 1, 4, f) != 4) {
 
  152#if __BYTE_ORDER == __BIG_ENDIAN 
  155    if (fread(&formtype, 1, 4, f) != 4) {
 
  159    if (memcmp(&
type, 
"RIFF", 4)) {
 
  163    if (memcmp(&formtype, 
"WAVE", 4)) {
 
  173        if (fread(&
buf, 1, 4, f) != 4) {
 
  178        if (fread(&data, 1, 4, f) != 4) {
 
  182#if __BYTE_ORDER == __BIG_ENDIAN 
  185        if (memcmp(&
buf, 
"fmt ", 4) == 0) {
 
  190        if(memcmp(
buf, 
"data", 4) == 0 )
 
  193        if (fseek(f,data,SEEK_CUR) == -1 ) {
 
  199    curpos = lseek(fd, 0, SEEK_CUR);
 
  200    truelength = lseek(fd, 0, SEEK_END);
 
  201    lseek(fd, curpos, SEEK_SET);
 
  202    truelength -= curpos;
 
 
  210    int datalen,filelen,bytes;
 
  213    fseek(f, 0, SEEK_END);
 
  217    datalen = 
htoll(bytes);
 
  219    filelen = 
htoll(36 + bytes);
 
  225    if (fseek(f, 4, SEEK_SET)) {
 
  229    if (fwrite(&filelen, 1, 4, f) != 4) {
 
  233    if (fseek(f, 40, SEEK_SET)) {
 
  237    if (fwrite(&datalen, 1, 4, f) != 4) {
 
  241    if (fseeko(f, cur, SEEK_SET)) {
 
 
  252    unsigned int hs = 
htoll(16);
 
  253    unsigned short fmt = 
htols(1);
 
  255    unsigned short bysam = 
htols(2);
 
  256    unsigned short bisam = 
htols(16);
 
  257    unsigned int size = 
htoll(0);
 
  259    if (writehz == 16000) {
 
  268    if (fwrite(
"RIFF", 1, 4, f) != 4) {
 
  272    if (fwrite(&size, 1, 4, f) != 4) {
 
  276    if (fwrite(
"WAVEfmt ", 1, 8, f) != 8) {
 
  280    if (fwrite(&hs, 1, 4, f) != 4) {
 
  284    if (fwrite(&fmt, 1, 2, f) != 2) {
 
  288    if (fwrite(&
chans, 1, 2, f) != 2) {
 
  292    if (fwrite(&hz, 1, 4, f) != 4) {
 
  296    if (fwrite(&bhz, 1, 4, f) != 4) {
 
  300    if (fwrite(&bysam, 1, 2, f) != 2) {
 
  304    if (fwrite(&bisam, 1, 2, f) != 2) {
 
  308    if (fwrite(
"data", 1, 4, f) != 4) {
 
  312    if (fwrite(&size, 1, 4, f) != 4) {
 
 
  332    tmp->
hz = sample_rate;
 
 
  354    if (s->
mode == O_RDONLY) {
 
  363    if (fs->
bytes & 0x1) {
 
  364        if (fwrite(&zero, 1, 1, s->
f) != 1) {
 
 
  374#if __BYTE_ORDER == __BIG_ENDIAN 
  405#if __BYTE_ORDER == __BIG_ENDIAN 
  408    for( x = 0; x < samples; x++)
 
  409        tmp[x] = (tmp[x] << 8) | ((tmp[x] & 0xff00) >> 8);
 
 
  418#if __BYTE_ORDER == __BIG_ENDIAN 
  420    short tmp[16000], *tmpi;
 
  428#if __BYTE_ORDER == __BIG_ENDIAN 
  430    if (f->
datalen > 
sizeof(tmp)) {
 
  435    for (x=0; x < f->
datalen/2; x++)
 
  436        tmp[x] = (tmpi[x] << 8) | ((tmpi[x] & 0xff00) >> 8);
 
 
  457    samples = sample_offset * 2; 
 
  459    if ((cur = ftello(fs->
f)) < 0) {
 
  464    if (fseeko(fs->
f, 0, SEEK_END) < 0) {
 
  469    if ((
max = ftello(fs->
f)) < 0) {
 
  474    if (whence == SEEK_SET) {
 
  475        offset = samples + 
min;
 
  477        offset = samples + cur;
 
  478    } 
else if (whence == SEEK_END) {
 
  479        offset = 
max - samples;
 
  482        offset = (offset > 
max)?
max:offset;
 
  485    offset = (offset < 
min)?
min:offset;
 
  486    return fseeko(fs->
f, offset, SEEK_SET);
 
 
  494    if ((fd = fileno(fs->
f)) < 0) {
 
  498    if ((cur = ftello(fs->
f)) < 0) {
 
  503    if (ftruncate(fd, cur)) {
 
 
  512    offset = ftello(fs->
f);
 
  514    return (offset - 44)/2;
 
 
  520    .mime_types = 
"audio/x-wav;codec=pcm;bit=16;rate=16000",
 
 
  536    .mime_types = 
"audio/wav|audio/x-wav|audio/x-wav;codec=pcm;bit=16;rate=8000",
 
  546    .desc_size = 
sizeof(
struct wav_desc),
 
 
Asterisk main include file. File version handling, generic pbx functions.
Asterisk architecture endianess compatibility definitions.
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
#define ast_debug(level,...)
Log a DEBUG message.
Asterisk module definitions.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODULE_SUPPORT_CORE
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
struct ast_frame fr
frame produced by read, typically
struct ast_format_def * fmt
struct ast_format * format
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
union ast_frame::@239 data