• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_CORE_KERNELS_SPECTROGRAM_TEST_UTILS_H_
17 #define TENSORFLOW_CORE_KERNELS_SPECTROGRAM_TEST_UTILS_H_
18 
19 #include <complex>
20 #include <string>
21 #include <vector>
22 
23 #include "tensorflow/core/framework/types.h"
24 
25 namespace tensorflow {
26 
27 // Reads a wav format file into a vector of floating-point values with range
28 // -1.0 to 1.0.
29 bool ReadWaveFileToVector(const string& file_name, std::vector<double>* data);
30 
31 // Reads a binary file containing 32-bit floating point values in the
32 // form [real_1, imag_1, real_2, imag_2, ...] into a rectangular array
33 // of complex values where row_length is the length of each inner vector.
34 bool ReadRawFloatFileToComplexVector(
35     const string& file_name, int row_length,
36     std::vector<std::vector<std::complex<double> > >* data);
37 
38 // Reads a CSV file of numbers in the format 1.1+2.2i,1.1,2.2i,3.3j into data.
39 void ReadCSVFileToComplexVectorOrDie(
40     const string& file_name,
41     std::vector<std::vector<std::complex<double> > >* data);
42 
43 // Reads a 2D array of floats from an ASCII text file, where each line is a row
44 // of the array, and elements are separated by commas.
45 void ReadCSVFileToArrayOrDie(const string& filename,
46                              std::vector<std::vector<float> >* array);
47 
48 // Write a binary file containing 64-bit floating-point values for
49 // reading by, for example, MATLAB.
50 bool WriteDoubleVectorToFile(const string& file_name,
51                              const std::vector<double>& data);
52 
53 // Write a binary file containing 32-bit floating-point values for
54 // reading by, for example, MATLAB.
55 bool WriteFloatVectorToFile(const string& file_name,
56                             const std::vector<float>& data);
57 
58 // Write a binary file containing 64-bit floating-point values for
59 // reading by, for example, MATLAB.
60 bool WriteDoubleArrayToFile(const string& file_name, int size,
61                             const double* data);
62 
63 // Write a binary file containing 32-bit floating-point values for
64 // reading by, for example, MATLAB.
65 bool WriteFloatArrayToFile(const string& file_name, int size,
66                            const float* data);
67 
68 // Write a binary file in the format read by
69 // ReadRawDoubleFileToComplexVector above.
70 bool WriteComplexVectorToRawFloatFile(
71     const string& file_name,
72     const std::vector<std::vector<std::complex<double> > >& data);
73 
74 // Generate a sine wave with the provided parameters, and populate
75 // data with the samples.
76 void SineWave(int sample_rate, float frequency, float duration_seconds,
77               std::vector<double>* data);
78 
79 }  // namespace tensorflow
80 
81 #endif  // TENSORFLOW_CORE_KERNELS_SPECTROGRAM_TEST_UTILS_H_
82