private void button1_Click_1(object sender, EventArgs e) { if (!checkSelectedWave()) { return; } SaveAudioFileDialog.OverwritePrompt = true; SaveAudioFileDialog.RestoreDirectory = true; SaveAudioFileDialog.FileName = DEFAULT_FILE_NAME; SaveAudioFileDialog.DefaultExt = ".wav"; SaveAudioFileDialog.Filter = "WAV file (*.wav)|*.wav|All files (*.*)|*.*"; SaveAudioFileDialog.InitialDirectory = Application.StartupPath; DialogResult result = SaveAudioFileDialog.ShowDialog(); if (result == DialogResult.OK) { savePath = SaveAudioFileDialog.FileName; WaveChunk wave = this.ProcessWaves(); WAVGenerator.CreateMonoWAVFile(savePath, sampleRate, wave); this.labelBottomButtons.Text = "Saved!"; } }
public static void CreateMonoWAVFile(string filePath, SampleRate sampleRate, WaveChunk wave) { FileStream stream = new FileStream(filePath, FileMode.Create); BinaryWriter writer = new BinaryWriter(stream, Encoding.ASCII); WriteToStream(writer, sampleRate, wave); writer.Close(); }
public static void WriteToStream(BinaryWriter writer, SampleRate sampleRate, WaveChunk wave) { WAVGenerator generator = Singleton.SetAudioProperties((uint)sampleRate, 1); var data = WaveChunk.Get16BitArray(wave); generator.SetMonoData(data); generator.SaveToFile(writer); }
private WaveChunk ProcessWaves() { if (waves.Count == 0) { return(null); } WaveAttributes attr = new WaveAttributes(sampleRate, fileDuration, -1); WaveChunk wave = makeWave(waves[0], attr); for (int i = 1; i < waves.Count; i++) { var item = waves[i]; var newWave = makeWave(item, attr); switch (item.waveOperator) { case "Add": wave += newWave; break; case "Sub": wave -= newWave; break; case "Mult Wave": wave *= newWave; break; case "Div": wave /= newWave; break; default: throw new Exception("Invalid wave operation"); } } wave.LinearVolumeNormalize(); return(wave); WaveChunk makeWave(WaveItem item, WaveAttributes attr2) { attr2.TargetFrequency = item.waveFrequency; return(WaveFactory.MakeWave(WAVE_TYPES_MAP[item.waveType], attr2)); } }
private void button2_Click(object sender, EventArgs e) { if (!checkSelectedWave()) { return; } WaveChunk wave = this.ProcessWaves(); var writer = new BinaryWriter(new MemoryStream()); WAVGenerator.WriteToStream(writer, sampleRate, wave); writer.Seek(0, SeekOrigin.Begin); player = new System.Media.SoundPlayer(writer.BaseStream); player.Play(); writer.Close(); }
IEnumerator SpawnChunk(WaveChunk c) { yield return(new WaitForSeconds(c.startDelay)); for (int i = 0; i < c.count; i++) { SpawnEnemy(ChooseEnemyPrefab(c.type)); if (c.spawnRate > 0) { yield return(new WaitForSeconds(1 / c.spawnRate)); } else { yield return(new WaitForEndOfFrame()); } } }