MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / BuildWavFile

Function BuildWavFile

tensorflow/contrib/ffmpeg/default/ffmpeg_lib.cc:205–221  ·  view source on GitHub ↗

Creates the contents of a .wav file using pcm_s16le format (signed 16 bit little endian integers).

Source from the content-addressed store, hash-verified

203// Creates the contents of a .wav file using pcm_s16le format (signed 16 bit
204// little endian integers).
205string BuildWavFile(int32 samples_per_second, int32 channel_count,
206 const std::vector<float>& samples) {
207 string data = WavHeader(samples_per_second, channel_count, samples);
208 data.reserve(data.size() + samples.size() * sizeof(int16));
209 for (float value : samples) {
210 const int16 quantized =
211 static_cast<int16>(value * std::numeric_limits<int16>::max());
212 char raw[2];
213 ::memcpy(raw, &quantized, sizeof(int16));
214 if (!port::kLittleEndian) {
215 std::swap(raw[0], raw[1]);
216 }
217 data.push_back(raw[0]);
218 data.push_back(raw[1]);
219 }
220 return data;
221}
222
223Status ReadInfoFile(const string& filename, uint32* width, uint32* height,
224 uint32* frames) {

Callers 1

CreateAudioFileFunction · 0.85

Calls 5

WavHeaderFunction · 0.85
maxFunction · 0.50
reserveMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected