Created
June 10, 2016 04:14
-
-
Save dharmatech/6cb8fb83e46d56a1cc37f32e42559714 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.IO; | |
| using System.Media; | |
| namespace WavFileTest | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| using (var stream = new MemoryStream()) | |
| { | |
| var writer = new BinaryWriter(stream); | |
| writer.Write("RIFF".ToCharArray()); // chunk id | |
| writer.Write((UInt32)0); // chunk size | |
| writer.Write("WAVE".ToCharArray()); // format | |
| writer.Write("fmt ".ToCharArray()); // chunk id | |
| writer.Write((UInt32)16); // chunk size | |
| writer.Write((UInt16)1); // audio format | |
| var channels = 1; | |
| var sample_rate = 8000; | |
| var bits_per_sample = 8; | |
| writer.Write((UInt16)channels); | |
| writer.Write((UInt32)sample_rate); | |
| writer.Write((UInt32)(sample_rate * channels * bits_per_sample / 8)); // byte rate | |
| writer.Write((UInt16)(channels * bits_per_sample / 8)); // block align | |
| writer.Write((UInt16)bits_per_sample); | |
| writer.Write("data".ToCharArray()); | |
| var seconds = 20; | |
| var data = new byte[sample_rate * seconds]; | |
| for (var t = 0; t < data.Length; t++) | |
| data[t] = (byte)( | |
| t & t >> 8 | |
| //t * (42 & t >> 10) | |
| //t | t % 255 | t % 257 | |
| //t * (t >> 9 | t >> 13) & 16 | |
| ); | |
| writer.Write((UInt32)(data.Length * channels * bits_per_sample / 8)); | |
| foreach (var elt in data) writer.Write(elt); | |
| writer.Seek(4, SeekOrigin.Begin); // seek to header chunk size field | |
| writer.Write((UInt32)(writer.BaseStream.Length - 8)); // chunk size | |
| stream.Seek(0, SeekOrigin.Begin); | |
| new SoundPlayer(stream).PlaySync(); | |
| } | |
| } | |
| } | |
| } |
is this working cuz it just errors
i think ur using a js bytebeat code which is incompatable with c, idk but it works for me @prankapple
I was searching for a way to play byte beats on Windows without installing anything, and since c# compiler is the only one to be packaged in C:\Windows\Microsoft.NET this code has been verry helpfull. Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
noice