Salve ragazzi, so che la mia richiesta è alquanto strana, ma qualcuno di voi a provato o sa come convertire dei numeri random in note musicali? ho provato con questo codice:
Il risultato è abbastanza mediocre, qualche idea
Codice:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Media;
using System.Threading;
namespace Earth_Voice
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button_play_Click(object sender, EventArgs e)
{
Beep.BeepBeep(1000, 1000, 2000);
label_frame.Text = "-100";
Beep.BeepBeep(1000, 1125, 2000);
label_frame.Text = "100";
Beep.BeepBeep(1000, 1478, 2000);
label_frame.Text = "110";
Beep.BeepBeep(1000, 1568, 2000);
label_frame.Text = "120";
Beep.BeepBeep(1000, 1987, 2000);
label_frame.Text = "130";
Beep.BeepBeep(1000, 1234, 2000);
label_frame.Text = "140";
Beep.BeepBeep(1000, 1235, 2000);
label_frame.Text = "150";
Beep.BeepBeep(1000, 1869, 2000);
label_frame.Text = "160";
Beep.BeepBeep(1000, 1457, 2000);
label_frame.Text = "170";
}
}
public class Beep
{
public static void BeepBeep(int Amplitude, int Frequency, int Duration)
{
double A = ((Amplitude * (System.Math.Pow(2, 15))) / 1000) - 1;
double DeltaFT = 2 * Math.PI * Frequency / 44100.0;
int Samples = 441 * Duration / 10;
int Bytes = Samples * 4;
int[] Hdr = { 0X46464952, 36 + Bytes, 0X45564157, 0X20746D66, 16, 0X20001, 44100, 176400, 0X100004, 0X61746164, Bytes };
using (MemoryStream MS = new MemoryStream(44 + Bytes))
{
using (BinaryWriter BW = new BinaryWriter(MS))
{
for (int I = 0; I < Hdr.Length; I++)
{
BW.Write(Hdr[I]);
}
for (int T = 0; T < Samples; T++)
{
short Sample = System.Convert.ToInt16(A * Math.Sin(DeltaFT * T));
BW.Write(Sample);
BW.Write(Sample);
}
BW.Flush();
MS.Seek(0, SeekOrigin.Begin);
using (SoundPlayer SP = new SoundPlayer(MS))
{
SP.PlaySync();
}
}
}
}
}
}
Il risultato è abbastanza mediocre, qualche idea