| 58 | static ifstream infile; |
| 59 | |
| 60 | static void write_wave_header() |
| 61 | { |
| 62 | uint32_t byte_rate=2*sample_rate; |
| 63 | unsigned char header[]={ |
| 64 | /* RIFF header */ |
| 65 | 'R','I','F','F', /* ChunkID */ |
| 66 | /* We cannot determine this number in advance */ |
| 67 | /* This is what espeak puts in this field when writing to stdout */ |
| 68 | 0x24,0xf0,0xff,0x7f, /* ChunkSize */ |
| 69 | 'W','A','V','E', /* Format */ |
| 70 | /* fmt */ |
| 71 | 'f','m','t',' ', /* Subchunk1ID */ |
| 72 | 16,0,0,0, /* Subchunk1Size */ |
| 73 | 1,0, /* AudioFormat (1=PCM) */ |
| 74 | 1,0, /* NumChannels */ |
| 75 | 0,0,0,0, /* SampleRate */ |
| 76 | 0,0,0,0, /* ByteRate */ |
| 77 | 2,0, /* BlockAlign */ |
| 78 | 16,0, /* BitsPerSample */ |
| 79 | /* data */ |
| 80 | 'd','a','t','a', /* Subchunk2ID */ |
| 81 | /* Again using espeak as an example */ |
| 82 | 0x00,0xf0,0xff,0x7f}; /* Subchunk2Size */ |
| 83 | /* Write actual sample rate */ |
| 84 | *reinterpret_cast<uint32_t*>(header+24)=sample_rate; |
| 85 | /* Write actual byte rate */ |
| 86 | *reinterpret_cast<uint32_t*>(header+28)=byte_rate; |
| 87 | if(!outfile.is_open()) |
| 88 | { |
| 89 | #ifdef WIN32 |
| 90 | _setmode(_fileno(stdout),_O_BINARY); |
| 91 | #endif |
| 92 | } |
| 93 | ((outfile.is_open())?outfile:cout).write(reinterpret_cast<char*>(&header[0]),sizeof(header)); |
| 94 | } |
| 95 | |
| 96 | static int wave_header_written=0; |
| 97 | |