MCPcopy Create free account
hub / github.com/cjcliffe/CubicSDR / writeToFile

Method writeToFile

src/audio/AudioFileWAV.cpp:65–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65bool 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
102bool AudioFileWAV::closeFile()
103{

Callers 1

sinkMethod · 0.80

Calls 2

c_strMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected