3using System.Collections.Generic;
7using System.Threading.Tasks;
17 string[] m_rgstrFiles;
19 Dictionary<string, float> m_rgInfo =
new Dictionary<string, float>();
48 get {
return "StdWAVFileQuery"; }
83 string[] rgstrFiles = Directory.GetFiles(m_strPath);
86 List<string> rgstr =
new List<string>();
88 for (
int i = 0; i < rgstrFiles.Length; i++)
90 FileInfo fi =
new FileInfo(rgstrFiles[i]);
92 if (fi.Extension.ToLower() ==
".wav")
93 rgstr.Add(rgstrFiles[i]);
96 m_rgstrFiles = rgstr.ToArray();
98 if (m_rgstrFiles.Length == 0)
99 throw new Exception(
"The CustomTextQuery could not find any audio WAV (*.wav) files to load.");
111 throw new NotImplementedException();
120 throw new NotImplementedException();
129 if (m_nFileIdx == m_rgstrFiles.Length)
132 using (FileStream fs = File.OpenRead(m_rgstrFiles[m_nFileIdx]))
138 m_rgInfo =
new Dictionary<string, float>();
139 m_rgInfo.Add(
"AveBytesPerSec", wav.Format.nAvgBytesPerSec);
140 m_rgInfo.Add(
"BlockAlign", wav.Format.nBlockAlign);
141 m_rgInfo.Add(
"Channels", wav.Format.nChannels);
142 m_rgInfo.Add(
"SamplesPerSec", wav.Format.nSamplesPerSec);
143 m_rgInfo.Add(
"BitsPerSample", wav.Format.wBitsPerSample);
144 m_rgInfo.Add(
"FormatTag", wav.Format.wFormatTag);
146 List<double[]> rgData =
new List<double[]>();
148 for (
int i = 0; i < wav.Samples[0].Length; i++)
150 rgData.Add(
new double[] { wav.Samples[0][i], wav.Samples[1][i] });
163 throw new NotImplementedException();
172 if (m_rgInfo !=
null && m_rgInfo.Count > 0)
175 if (m_nFileIdx == m_rgstrFiles.Length)
176 throw new Exception(
"Invalid field index.");
178 using (FileStream fs = File.OpenRead(m_rgstrFiles[m_nFileIdx]))
183 m_rgInfo =
new Dictionary<string, float>();
184 m_rgInfo.Add(
"AveBytesPerSec", wav.Format.nAvgBytesPerSec);
185 m_rgInfo.Add(
"BlockAlign", wav.Format.nBlockAlign);
186 m_rgInfo.Add(
"Channels", wav.Format.nChannels);
187 m_rgInfo.Add(
"SamplesPerSec", wav.Format.nSamplesPerSec);
188 m_rgInfo.Add(
"BitsPerSample", wav.Format.wBitsPerSample);
189 m_rgInfo.Add(
"FormatTag", wav.Format.wFormatTag);
203 using (MemoryStream ms =
new MemoryStream())
204 using (BinaryWriter bw =
new BinaryWriter(ms))
207 List<float[]> rgData = rgSamples;
209 bw.Write(rgHeader.Length);
211 bw.Write(rgData.Count);
212 bw.Write(rgData[0].Length);
214 for (
int i = 0; i < rgData[0].Length; i++)
216 for (
int j = 0; j < rgData.Count; j++)
218 bw.Write(rgData[j][i]);
234 using (MemoryStream ms =
new MemoryStream(rg))
235 using (BinaryReader br =
new BinaryReader(ms))
237 int nLen = br.ReadInt32();
238 byte[] rgFmt = br.ReadBytes(nLen);
240 int nCh = br.ReadInt32();
241 int nS = br.ReadInt32();
243 List<double[]> rgData =
new List<double[]>();
244 for (
int i = 0; i < nCh; i++)
246 rgData.Add(
new double[nS]);
249 for (
int i = 0; i < nS; i++)
251 for (
int j = 0; j < nCh; j++)
253 float fVal = br.ReadSingle();
268 List<int> rgSize =
new List<int>();
270 using (FileStream fs = File.OpenRead(m_rgstrFiles[m_nFileIdx]))
275 rgSize.Add((
int)wav.Format.nChannels);
276 rgSize.Add(wav.SampleCount);
299 Dictionary<string, float> rgInfo =
QueryInfo();
304 fmt.
nChannels = (ushort)rgInfo[
"Channels"];
309 List<float[]> rgrgSamples =
new List<float[]>();
Specifies a key-value pair of properties.
string GetProperty(string strName, bool bThrowExceptions=true)
Returns a property as a string value.
The ParamPacker is use to pack and unpack parameters sent to each custom query.
static string UnPack(string str)
Unpack the custom query parameters.
The StandardQueryWAVFile provides queries that read sound frequencies from (*.WAV) files residing in ...
double[] QueryByTime(DateTime dt, TimeSpan ts, int nCount)
The QueryByTime method is not implemented.
void Reset()
Reset the file index to the first file.
byte[] ConvertOutput(float[] rg, out string strType)
Converts the output values into the native type used by the CustomQuery.
List< float[]> QueryRealF()
The QueryRealF method returns all samples of the next file in the directory.
static byte[] PackBytes(WaveFormat fmt, List< float[]> rgSamples)
The PackBytes method packs the wav file information into a byte stream.
IXCustomQuery Clone(string strParam)
Clone the custom query returning a new copy.
CUSTOM_QUERY_TYPE QueryType
Returns the QUERY_TYPE of REAL_FLOAT.
void Close()
Close the custom query.
Dictionary< string, float > QueryInfo()
The Query information returns information about the data queried such as header information.
string Name
Returns the custom query name 'StdWAVFileQuery'.
StandardQueryWAVFile(string strParam=null)
The constructor.
List< int > GetQuerySize()
The GetQuerySize method returns the size of the query as {1,1,filesize}.
List< double[]> QueryRealD()
The QueryRealD method returns all samples of the next file in the directory.
byte[] QueryBytes()
The QueryBytes method is not implemented.
int FieldCount
Returns the field count of 1.
static List< double[]> UnPackBytes(byte[] rg, out WaveFormat fmt)
The UnPackBytes method is used to unpack a byte stream into the Wav information.
void Open()
Open the custom query. The query must be opened before calling QueryBytes.
The WAVReader is an extension of the BinaryReader and is used to read WAV files.
The WAVWriter is a special BinaryWriter used to write WAV files.
The custom query interface defines the functions implemented by each Custom Query object used to spec...
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.db.stream namespace contains all data streaming related classes.
CUSTOM_QUERY_TYPE
Defines the custom query type to use.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...