public void ImportFile(string srcFile, string targetName, string targetDir)
 {
     string[] output = this.GetOutputFiles(srcFile, targetName, targetDir);
     AudioData res = new AudioData();
     res.OggVorbisData = File.ReadAllBytes(srcFile);
     res.SourcePath = srcFile;
     res.Save(output[0]);
 }
		private Sound FindMatch(AudioData baseRes)
		{
			if (baseRes == null)
			{
				return null;
			}
			else if (baseRes.IsDefaultContent)
			{
				var defaultContent = ContentProvider.GetDefaultContent<Resource>();
				return defaultContent.Res().OfType<Sound>().FirstOrDefault(r => r.Data != null && r.Data.Count == 1 && r.MainData == baseRes);
			}
			else
			{
				// First try a direct approach
				string fileExt = Resource.GetFileExtByType<Sound>();
				string targetPath = baseRes.FullName + fileExt;
				Sound match = ContentProvider.RequestContent<Sound>(targetPath).Res;
				if (match != null) return match;

				// If that fails, search for other matches
				string targetName = baseRes.Name + fileExt;
				string[] resFilePaths = Resource.GetResourceFiles().ToArray();
				var resNameMatch = resFilePaths.Where(p => Path.GetFileName(p) == targetName);
				var resQuery = resNameMatch.Concat(resFilePaths).Distinct();
				List<Sound> matchCandidates = new List<Sound>();
				foreach (string resFile in resQuery)
				{
					if (!resFile.EndsWith(fileExt)) continue;
					match = ContentProvider.RequestContent<Sound>(resFile).Res;
					if (match != null && match.Data != null && match.Data.Contains(baseRes)) matchCandidates.Add(match);
				}
				// Found some matches? Return the narrowest one
				if (matchCandidates.Count > 0)
				{
					return matchCandidates.OrderBy(m => m.Data.Count).First();
				}

				// Give up.
				return null;
			}
		}
Exemple #3
0
 private static bool IsMatch(AudioData source, Sound target)
 {
     return target.Data != null && target.Data.Contains(source);
 }
Exemple #4
0
		private Sound FindMatch(AudioData baseRes)
		{
			if (baseRes == null)
			{
				return null;
			}
			else if (baseRes.IsDefaultContent)
			{
				var defaultContent = ContentProvider.GetDefaultContent<Resource>();
				return defaultContent.Res().OfType<Sound>().FirstOrDefault(r => r.Data == baseRes);
			}
			else
			{
				// First try a direct approach
				string targetPath = baseRes.FullName + Sound.FileExt;
				Sound match = ContentProvider.RequestContent<Sound>(targetPath).Res;
				if (match != null) return match;

				// If that fails, search for other matches
				string targetName = baseRes.Name + Sound.FileExt;
				List<string> resFilePaths = Resource.GetResourceFiles();
				var resNameMatch = resFilePaths.Where(p => Path.GetFileName(p) == targetName);
				var resQuery = resNameMatch.Concat(resFilePaths).Distinct();
				foreach (string resFile in resQuery)
				{
					if (!resFile.EndsWith(Sound.FileExt)) continue;
					match = ContentProvider.RequestContent<Sound>(resFile).Res;
					if (match != null && match.Data == baseRes) return match;
				}

				// Give up.
				return null;
			}
		}
		protected override void OnGetValue()
		{
			base.OnGetValue();
			AudioData lastValue = this.value;
			AudioData[] values = this.GetValue().Cast<AudioData>().ToArray();
			this.value = values.NotNull().FirstOrDefault() as AudioData;
			this.GeneratePreview();
			if (this.value != lastValue) this.Invalidate();
		}
		private void ActionAudioDataOpenRes(AudioData audio)
		{
			if (audio == null) return;
			FileImportProvider.OpenSourceFile(audio, ".ogg", audio.SaveOggVorbisData);
		}
		private void ActionAudioDataCreateSound(AudioData audio)
		{
			Sound.CreateFromAudioData(audio);
		}
Exemple #8
0
		private void PerformStreamingUpdate(AudioData audioDataRes)
		{
			int num;
			AL.GetSource(this.alSource, ALGetSourcei.BuffersProcessed, out num);
			while (num > 0)
			{
				num--;

				int unqueued;
				unqueued = AL.SourceUnqueueBuffer(this.alSource);

				if (OggVorbis.IsStreamValid(this.strOvStr))
				{
					PcmData pcm;
					bool eof = !OggVorbis.StreamChunk(this.strOvStr, out pcm);
					if (eof)
					{
						OggVorbis.EndStream(ref this.strOvStr);
						if (this.looped)
						{
							OggVorbis.BeginStreamFromMemory(audioDataRes.OggVorbisData, out this.strOvStr);
							if (pcm.dataLength == 0)
								eof = !OggVorbis.StreamChunk(this.strOvStr, out pcm);
							else
								eof = false;
						}
					}
					if (pcm.dataLength > 0)
					{
						AL.BufferData(
							unqueued, 
							pcm.channelCount == 1 ? ALFormat.Mono16 : ALFormat.Stereo16,
							pcm.data, 
							pcm.dataLength * PcmData.SizeOfDataElement, 
							pcm.sampleRate);
						AL.SourceQueueBuffer(this.alSource, unqueued);
					}
					if (pcm.dataLength == 0 || eof)
					{
						this.strStopReq = StopRequest.EndOfStream;
						break;
					}
				}
			}
		}
Exemple #9
0
		private void PerformStreamingBegin(AudioData audioDataRes)
		{
			// Generate streaming buffers
			this.strAlBuffers = new int[3];
			for (int i = 0; i < this.strAlBuffers.Length; ++i)
			{
				AL.GenBuffers(1, out this.strAlBuffers[i]);
			}

			// Begin streaming
			OggVorbis.BeginStreamFromMemory(audioDataRes.OggVorbisData, out this.strOvStr);

			// Initially, completely fill all buffers
			for (int i = 0; i < this.strAlBuffers.Length; ++i)
			{
				PcmData pcm;
				bool eof = !OggVorbis.StreamChunk(this.strOvStr, out pcm);
				if (pcm.dataLength > 0)
				{
					AL.BufferData(
						this.strAlBuffers[i], 
						pcm.channelCount == 1 ? ALFormat.Mono16 : ALFormat.Stereo16,
						pcm.data, 
						pcm.dataLength * PcmData.SizeOfDataElement, 
						pcm.sampleRate);
					AL.SourceQueueBuffer(this.alSource, this.strAlBuffers[i]);
					if (eof) break;
				}
				else break;
			}
		}
 public void ImportFile(string srcFile, string targetName, string targetDir)
 {
     string[] output = this.GetOutputFiles(srcFile, targetName, targetDir);
     AudioData res = new AudioData(srcFile);
     res.Save(output[0]);
 }