Mercurial > hg > aimc
comparison trunk/src/Modules/Output/FileOutputHTK.cc @ 421:3b22559cd848
- Fix bug where the fram period wasn't propagating to the output file.
author | tom@acousticscale.org |
---|---|
date | Tue, 26 Oct 2010 16:46:14 +0000 |
parents | 69466da9745e |
children | 2d0b057e525c |
comparison
equal
deleted
inserted
replaced
420:733a11a65f3d | 421:3b22559cd848 |
---|---|
66 if (file_handle_ == NULL) { | 66 if (file_handle_ == NULL) { |
67 LOG_ERROR(_T("Couldn't initialize file output.")); | 67 LOG_ERROR(_T("Couldn't initialize file output.")); |
68 return false; | 68 return false; |
69 } | 69 } |
70 if (!header_written_) { | 70 if (!header_written_) { |
71 WriteHeader(channel_count_ * buffer_length_, frame_period_ms_); | 71 WriteHeader(channel_count_ * buffer_length_); |
72 } | 72 } |
73 | 73 |
74 return true; | 74 return true; |
75 } | 75 } |
76 | 76 |
77 void FileOutputHTK::ResetInternal() { | 77 void FileOutputHTK::ResetInternal() { |
78 // Finalize and close the open file, if there is one. | 78 // Finalize and close the open file, if there is one. |
79 if (file_handle_ != NULL && !header_written_) { | 79 if (file_handle_ != NULL && !header_written_) { |
80 WriteHeader(channel_count_ * buffer_length_, frame_period_ms_); | 80 WriteHeader(channel_count_ * buffer_length_); |
81 } | 81 } |
82 if (file_handle_ != NULL) | 82 if (file_handle_ != NULL) |
83 CloseFile(); | 83 CloseFile(); |
84 | 84 |
85 // Now open and set up the new file. | 85 // Now open and set up the new file. |
92 out_filename.c_str()); | 92 out_filename.c_str()); |
93 return; | 93 return; |
94 } | 94 } |
95 sample_count_ = 0; | 95 sample_count_ = 0; |
96 header_written_ = false; | 96 header_written_ = false; |
97 WriteHeader(channel_count_ * buffer_length_, frame_period_ms_); | 97 WriteHeader(channel_count_ * buffer_length_); |
98 } | 98 } |
99 | 99 |
100 void FileOutputHTK::WriteHeader(int num_elements, float period_ms) { | 100 void FileOutputHTK::WriteHeader(int num_elements) { |
101 if (header_written_) | 101 if (header_written_) |
102 return; | 102 return; |
103 | 103 |
104 /* HTK format file: (taken from the HTK book - section 5.10.1) | 104 /* HTK format file: (taken from the HTK book - section 5.10.1) |
105 * Header: 12 bytes in total, contains: | 105 * Header: 12 bytes in total, contains: |
110 */ | 110 */ |
111 | 111 |
112 // To be filled in when the file is done | 112 // To be filled in when the file is done |
113 int32_t sample_count = 0; | 113 int32_t sample_count = 0; |
114 | 114 |
115 int32_t sample_period = floor(1e4 * period_ms); | 115 int32_t sample_period = floor(1e4 * frame_period_ms_); |
116 int16_t sample_size = num_elements * sizeof(float); // NOLINT | 116 int16_t sample_size = num_elements * sizeof(float); // NOLINT |
117 | 117 |
118 // User-defined coefficients with energy term | 118 // User-defined coefficients with energy term |
119 int16_t parameter_kind = H_USER + H_E; | 119 int16_t parameter_kind = H_USER + H_E; |
120 | 120 |
168 if (file_handle_ == NULL) | 168 if (file_handle_ == NULL) |
169 return false; | 169 return false; |
170 | 170 |
171 // Write the first 4 bytes of the file | 171 // Write the first 4 bytes of the file |
172 // with how many samples there are in the file | 172 // with how many samples there are in the file |
173 // and the next 4 bytes with the frame period. | |
173 fflush(file_handle_); | 174 fflush(file_handle_); |
174 rewind(file_handle_); | 175 rewind(file_handle_); |
175 fflush(file_handle_); | 176 fflush(file_handle_); |
176 int32_t samples = sample_count_; | 177 int32_t samples = sample_count_; |
177 samples = ByteSwap32(samples); | 178 samples = ByteSwap32(samples); |
179 int32_t sample_period = floor(1e4 * frame_period_ms_); | |
180 sample_period = ByteSwap32(sample_period); | |
178 fwrite(&samples, sizeof(samples), 1, file_handle_); | 181 fwrite(&samples, sizeof(samples), 1, file_handle_); |
182 fwrite(&sample_period, sizeof(sample_period), 1, file_handle_); | |
179 | 183 |
180 // And close the file | 184 // And close the file |
181 fclose(file_handle_); | 185 fclose(file_handle_); |
182 file_handle_ = NULL; | 186 file_handle_ = NULL; |
183 header_written_ = false; | 187 header_written_ = false; |