-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
80 lines (69 loc) · 2.45 KB
/
Program.cs
File metadata and controls
80 lines (69 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using OpenTK.Audio.OpenAL;
using SoundGenerators;
using AudioFilters;
using SoundComponents;
using SoundSources;
using AudioPlayer;
class Program
{
static void Main(string[] args)
{
int fs = 44100;
// Создаём микшер
using var mixer = new AudioMixer(sampleRate: fs, bufferSize: 1024)
{
OutputWavFile = "result.wav"
};
// Создаём SoundSource, эквивалентный вибрирующей стеклянной сфере
// радиуса 1 м, 5 сферических гармоник, 5 радиальных мод
var sphereSource = SoundSource.CreateVibratingGlassSphereSource(
startTime: 0f,
radius: 1f,
sphericalHarmCount: 5,
radialModesCount: 5,
sampleRate: fs,
baseAmplitude: 1f,
baseDecay: 0.2f
);
// Добавляем в микшер
mixer.AddSoundSource(sphereSource);
// Сгенерируем удар по тонкой стеклянной пластине
// Размер пластины (1m x 1m),
// mMax=5, nMax=5, sampleRate=44100
var plateSource = SoundSource.CreateThinGlassPlateSource(
startTime: 0f,
lx: 1f, ly: 1f,
mMax: 5, nMax: 5,
sampleRate: 44100,
baseAmplitude: 0.9f,
baseDecay: 0.1f
);
//Добавляем немного фильтрованного шума для окраски
plateSource.AddComponent(new SoundComponent
{
Generator = new ExponentialNoiseGenerator(0.9f, 0.01f, 0.2f),
Filter = new BiQuadFilter(BiQuadFilter.FilterType.LowPass, fs, 1000, 1),
StartTime = 0f,
Lifetime = 3f
});
// Добавляем в микшер
mixer.AddSoundSource(plateSource);
// Запускаем цикл ~5с
float total = 2f;
var startTime = DateTime.Now;
while ((DateTime.Now - startTime).TotalSeconds < total)
{
mixer.Update();
Thread.Sleep(10); // ~20 мс
}
// Сохраняем wav
mixer.SaveWav();
Console.WriteLine("Готово! Сохранён файл result.wav");
Console.ReadKey();
}
}