예제 #1
0
		public bool AppendFile(WavFile wavFile)
		{
			var flag = true;
			switch (DataSize)
			{
				case 0:
					InitializeFromFile(wavFile);
					break;
				default:
					flag &= AppendNewData(wavFile);
					break;
			}

			flag &= WriteToFile();

			return flag;
		}
			private static bool CheckMergedSampleDuration(string filePath )
			{
				var file = new WavFile(filePath);
				return file.Duration > 10;
			}
			private string MergeSamples()
			{
				var mergedFilePath = _storagePath + TmpPath + _fileName + ".wav";
				var mergedFile = new WavFile(mergedFilePath);

				if (_samplePaths != null)
				{
					//_samplePaths.ForEach(samplePath => mergedFile.AppendFile(new WavFile(samplePath)));

					if (_samplePaths.Select(samplePath => mergedFile.AppendFile(new WavFile(samplePath))).Any(flag => !flag))
					{
						Log.Error(ThreadTag, "Merge failed.");
						return null;
					}
					if (System.IO.File.Exists(mergedFilePath)) return mergedFilePath;

					Log.Error(ThreadTag, "Merged file does not exist after file merge.");
					return null;
				}

				Log.Error(ThreadTag, "_samplePaths was null in MergeSamples");
				return null;
			}
예제 #4
0
		private void InitializeFromFile(WavFile wavFile)
		{
			ChunkId = wavFile.ChunkId;
			FileSize = wavFile.FileSize;
			RiffType = wavFile.RiffType;
			FmtId = wavFile.FmtId;
			FmtSize = wavFile.FmtSize;
			FmtCode = wavFile.FmtCode;
			Channels = wavFile.Channels;
			SampleRate = wavFile.SampleRate;
			FmtAvgBps = wavFile.FmtAvgBps;
			FmtBlockAlign = wavFile.FmtBlockAlign;
			BitDepth = wavFile.BitDepth;
			FmtExtraSize = wavFile.FmtExtraSize;
			DataId = wavFile.DataId;
			DataSize = wavFile.DataSize;
			Data = wavFile.Data;
		}
예제 #5
0
		private bool HasSameHeader(WavFile wavFile)
		{
			return (ChunkId.SequenceEqual(wavFile.ChunkId) &&
					RiffType.SequenceEqual(wavFile.RiffType) &&
					FmtId.SequenceEqual(wavFile.FmtId) &&
					FmtSize == wavFile.FmtSize &&
					FmtCode == wavFile.FmtCode &&
					Channels == wavFile.Channels &&
					SampleRate == wavFile.SampleRate &&
					FmtAvgBps == wavFile.FmtAvgBps &&
					FmtBlockAlign == wavFile.FmtBlockAlign &&
					BitDepth == wavFile.BitDepth &&
					FmtExtraSize == wavFile.FmtExtraSize &&
					DataId.SequenceEqual(wavFile.DataId));
		}
예제 #6
0
		private bool AppendNewData(WavFile wavFile)
		{
			if (!HasSameHeader(wavFile))
			{
				Log.Error("WAVFile", "Not able to append, different headers.");
				return false;
			}

			if (wavFile.DataSize == 0)
			{
				Log.Error(Tag, "trying to add empty wav file.");
				return false;
			}

			var newDataSize = DataSize + wavFile.DataSize;
			var tmp = new byte[newDataSize];

			for (var i = 0; i < newDataSize; i++)
			{
				if (i < DataSize)
					tmp[i] = Data[i];
				else
					tmp[i] = wavFile.Data[i-DataSize];
			}

			Data = tmp;
			DataSize = newDataSize;
			FileSize += wavFile.DataSize;

			return true;
		}
			private static bool CheckMergedSampleDuration(string filePath)
			{
				var file = new WavFile(filePath);
				Log.Debug(ThreadTag, "Duration of sample: " + file.Duration);
				return file.Duration > MinSampleDuration;
			}