| 63 | } |
| 64 | |
| 65 | bool AudioFileWAV::writeToFile(AudioThreadInputPtr input) |
| 66 | { |
| 67 | if (!outputFileStream.is_open()) { |
| 68 | |
| 69 | std::string ofName = getOutputFileName(); |
| 70 | |
| 71 | outputFileStream.open(ofName.c_str(), std::ios::binary); |
| 72 | currentFileSize = 0; |
| 73 | |
| 74 | writeHeaderToFileStream(input); |
| 75 | } |
| 76 | |
| 77 | size_t maxRoomInCurrentFileInSamples = getMaxWritableNumberOfSamples(input); |
| 78 | |
| 79 | if (maxRoomInCurrentFileInSamples >= input->data.size()) { |
| 80 | writePayloadToFileStream(input, 0, input->data.size()); |
| 81 | } |
| 82 | else { |
| 83 | //we complete the current file and open another: |
| 84 | writePayloadToFileStream(input, 0, maxRoomInCurrentFileInSamples); |
| 85 | |
| 86 | closeFile(); |
| 87 | |
| 88 | // Open a new file with the next sequence number, and dump the rest of samples in it. |
| 89 | currentSequenceNumber++; |
| 90 | currentFileSize = 0; |
| 91 | |
| 92 | std::string ofName = getOutputFileName(); |
| 93 | outputFileStream.open(ofName.c_str(), std::ios::binary); |
| 94 | |
| 95 | writeHeaderToFileStream(input); |
| 96 | writePayloadToFileStream(input, maxRoomInCurrentFileInSamples, input->data.size()); |
| 97 | } |
| 98 | |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | bool AudioFileWAV::closeFile() |
| 103 | { |