0
Я тоже пытаюсь, чтобы мое консольное приложение C# выдало звуковой сигнал. Да, я знаю, что могу использовать Console.Beep, но я также хочу, чтобы уменьшить громкость и т.д.Ошибка при попытке чтения из массива
Но ошибка я получаю это:
Имя метода ожидается
на этой линии :
binaryWriter.Write(hdr(i));
Это мой код:
private bool Beep(int volume, int frequency, int duration)
{
try
{
double amplitude = volume * 1.27;
double a = ((amplitude * (System.Math.Pow(2, 15)))/1000) - 1;
double deltaFt = 2 * System.Math.PI * frequency/8000;
double samples = 441 * (duration/100);
int bytes = Convert.ToInt32(samples) * 4;
int[] hdr = {
0x46464952,
36 + bytes,
0x45564157,
0x20746d66,
16,
0x20001,
8000,
176400,
0x100004,
0x61746164,
bytes
};
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(44 + bytes))
{
using (System.IO.BinaryWriter binaryWriter = new System.IO.BinaryWriter(memoryStream))
{
for (int i = 0; i <= hdr.Length - 1; i++)
{
binaryWriter.Write(hdr(i));
}
for (int T = 0; T <= Convert.ToInt32(samples) - 1; T++)
{
short sample = Convert.ToInt16(a * System.Math.Sin(deltaFt * T));
binaryWriter.Write(sample);
binaryWriter.Write(sample);
}
binaryWriter.Flush();
memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
using (System.Media.SoundPlayer sp = new System.Media.SoundPlayer(memoryStream))
{
sp.PlaySync();
}
}
}
}
catch
{
return false;
}
return true;
}
Используйте скобки для массива: 'ДРЧА [I]' – LarsTech
использовать квадратные скобки, не круглые , при чтении из массива – user1666620