private static void MusicMod(List <Tuple <double, double>[]> ret, WavFile musik, WavFile musik1, MelodyModell Mod) { for (int i = 0; i < musik.DataList.Count; i++) { musik.DataList[i] = (Int16)((musik.DataList[i] * 3) / 7); } var datM = musik1.DataList.Select(v => { return((double)v); }).ToArray(); for (int i = 1; 2 * (i * Mod.BPMd) < musik.DataList.Count - Mod.BPMd; i++) { var sp = FastFourierTransform.FFTSpectr(datM, 2 * (i * Mod.BPMd), 2, 14, Mod.BPMd); int maxCh = 1; maxCh = (int)NoteDetector.DetectNote(Mod.BPMd, datM, i, Mod.BPMd); ret.Add(sp); var Bit = Generators.MusicImmitation(1 << 14, /*(int)((1 << 14) / (220 / 2.69 * ((i % 3 + 2) * 0.1)))*/ Math.Max(maxCh, 1), 5000, 10); for (int j = 0; j < Bit.Length && musik.DataList.Count > (i * Mod.BPMd + j + Mod.StartSd) * 2; j++) { musik.DataList[2 * (i * Mod.BPMd + j)] = (Int16)((Bit[j] * 4 / 7d + musik.DataList[2 * (i * Mod.BPMd + j) /*+ Mod.StartSd*/])); musik.DataList[2 * (i * Mod.BPMd + j) + 1] = (Int16)((Bit[j] * 4 / 7d + musik.DataList[2 * (i * Mod.BPMd + j) + 1 /*+ Mod.StartSd*/])); } } }
public static void MusicMod2(WavFile musik, WavFile musik1, WavFile musikW, WavFile musikS, MelodyModell Mod) { for (int i = 0; i < musik.DataList.Count; i++) { musik.DataList[i] = (Int16)((musik.DataList[i] * 2) / 7); } double[] BitW = new double[musikW.DataList.Count]; for (int i = 0; i < musikW.DataList.Count; i++) { BitW[i] = (Int16)((musikW.DataList[i] * 5) / 7); } var datM = musik1.DataList.Select(v => { return((double)v); }).ToArray(); for (int i = 1; 2 * (i * Mod.BPMd) < musik.DataList.Count - Mod.BPMd; i++) { var maxCh = NoteDetector.DetectNote(Mod.BPMd, datM, i, Mod.BPMd); var Bit = BitW; double k = 1; if (i % 3 == 0) { k = 2; } for (int j = 0; j < Bit.Length / 2 && musik.DataList.Count > (i * Mod.BPMd + j + Mod.StartSd) * 2; j++) { musik.DataList[2 * (i * Mod.BPMd + j) + Mod.StartSd] = (Int16)((Bit[2 * j] * k + musik.DataList[2 * (i * Mod.BPMd + j) + Mod.StartSd])); musik.DataList[2 * (i * Mod.BPMd + j) + 1 + Mod.StartSd] = (Int16)((Bit[2 * j + 1] * k + musik.DataList[2 * (i * Mod.BPMd + j) + 1 + Mod.StartSd])); } } }
public static SongParametrs Test6() { int MelodySize = 44100 * 6; int Start = 44100 * 20; var musik = WavFile.Read(@"D:\Test4.wav"); var melodyl = new int[MelodySize]; var melodyr = new int[MelodySize]; for (int i = 0; i < (MelodySize - 1) * 2; i += 2)//musik.DataList.Count;i++) { melodyl[i / 2] = musik.DataList[i + Start]; melodyr[i / 2 + 1] = musik.DataList[i + Start]; } var dat = new SongData() { Left = melodyl, Right = melodyr, leng = MelodySize }; var param = BeatPerMinutDetecter.Detector(dat); return(param); }
private void ReadDataWave() { System.Windows.Forms.OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "All Supported Files (*.wav)|*.wav"; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { return; } FileName = openFileDialog.FileName; WavFile file = new WavFile(FileName); //входной файл WavData orig = file.ReadData(); Processed = new WavData(orig.Header, orig.Data.Length); SelectedData.Clear(); Line.Points.Clear(); using (orig) { int c = orig.GetSamplesCount(); int x = 0; for (int i = 0; i < c; i++) { float y = orig.ReadNextSample(); //читаем следующий семпл Line.Points.Add(new DataPoint(x++, y)); } Model.InvalidatePlot(true); } }
public void Test_SFF_Linear2() { // test creating SFF file from 16-bit 48kHz mono WAV file // read the wav file (int sampleRate, double[] audio) = WavFile.ReadMono("../../../../../data/03-02-03-01-02-01-19.wav"); Assert.AreEqual(48000, sampleRate); // save the SFF int fftSize = 1 << 12; var spec = new Spectrogram(sampleRate, fftSize, stepSize: 300, maxFreq: 2000); spec.Add(audio); spec.SaveData("testDoor.sff"); // load the SFF and verify all the values are the same var spec2 = new SFF("testDoor.sff"); Assert.AreEqual(spec.SampleRate, spec2.SampleRate); Assert.AreEqual(spec.StepSize, spec2.StepSize); Assert.AreEqual(spec.Width, spec2.Width); Assert.AreEqual(spec.FftSize, spec2.FftSize); Assert.AreEqual(spec.NextColumnIndex, spec2.FftFirstIndex); Assert.AreEqual(spec.Height, spec2.Height); Assert.AreEqual(spec.OffsetHz, spec2.OffsetHz); Assert.AreEqual("SFF 701x170", spec2.ToString()); }
public static WavFile Compose(IModulator modulator, SampleRateType sampleRate, BitArray data) { using MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); bw.Write(new byte[(int)(0.5 * 2 * (int)sampleRate)]); foreach (bool bit in data) { if (bit) { modulator.WriteOne(ms); } else { modulator.WriteZero(ms); } } bw.Write(new byte[(int)(0.5 * 2 * (int)sampleRate)]); var wavFile = new WavFile((int)sampleRate, ms.ToArray()); return(wavFile); }
public static Task <WaveData> ReadAsync(WavFile file, Stream stream, int samplesPerPixel) { return(Task.Factory.StartNew <WaveData>(() => { return Read(file, stream); })); }
private void Button_Click(object sender, RoutedEventArgs e) { var ofd = new OpenFileDialog(); if (ofd.ShowDialog() != true) { return; } try { var file = WavFile.Read(ofd.FileName); var type = file.GetType(); var result = ""; foreach (var prop in type.GetProperties()) { result += prop.Name + ":" + prop.GetValue(file) + "\n"; } ResultText.Text = result; //WaveImage.Source = file.DrawChannel(0, 1); } catch (Exception ex) { MessageBox.Show(ex.Message); ResultText.Text = ""; } }
public Tests() { var bytes = new byte[4096]; for (int i = 0; i < bytes.Length; i++) { bytes[i] = (byte)((float)i / bytes.Length * bytes.Length); } var modulator = NzrModulator.Get_1_3150_BitDurationModulator(); var envelope = Encoder.Encode(bytes); var sound = Wave.Compose(modulator, modulator.SampleRate, envelope.ToBitArray()); using (FileStream fs = new FileStream($"NONFILTER.wav", FileMode.Create)) { BinaryWriter bw = new BinaryWriter(fs); bw.Write(sound.ToBytes()); } sound = new WavFile(new FileInfo("NONFILTER.wav")); NzrDemodulator demodulator = NzrDemodulator.Get_1_3150_BitDurationDemodulator(); BitArray bitArray = Wave.Decompose(demodulator, sound); if (bitArray != null) { Envelope decodedEnvelope = Encoder.Decode(bitArray); Console.WriteLine("1000"); Console.WriteLine(Check(bytes, decodedEnvelope.Data.Take(decodedEnvelope.Data.Length - 2).ToArray())); } Console.WriteLine(); }
async void Start() { instance = this; string from = "en-US"; string to = "it-IT"; string voice = "it-IT-Elsa"; string api = "1.0"; string host = "wss://dev.microsofttranslator.com"; string path = "/speech/translate"; string uri = host + path + "?from=" + from + "&to=" + to + "&api-version=" + api + "&voice=" + voice; Debug.Log("starting web socket"); client = new ClientWebSocket(); client.Options.SetRequestHeader("Ocp-Apim-Subscription-Key", apiKey); await client.ConnectAsync(new Uri(uri), CancellationToken.None); Debug.Log("connected to socket"); var header = WavFile.GetWaveHeader(0); var wavHeaderBuffer = new ArraySegment <byte>(header); send(wavHeaderBuffer); ready = true; }
/// <summary> /// Load a wav file and draw the waveform /// </summary> /// <param name="filename">Filename</param> public void LoadFromFile(string filename) { if (Status == Status.Playing) { Stop(); } if (WavFile != null && WavFile.FileName == filename) { return; } Reset(); MainSlider.Reset(); WavFile = WavFile.Read(filename); MainSlider.MinScale = WavFile.MinScale; SetChannels(); RefreshSliderImage(); DrawWaveImage(); RefreshMiddleLines(); MyPlayer.Source = new Uri(filename); MyPlayer.Play(); Status = Status.Stop; MyPlayer.Stop(); if (!AutoStart) { } else { Play(); } if (FileLoaded != null) { FileLoaded(this, EventArgs.Empty); } }
public static WaveData Read(WavFile file, Stream stream) { stream.Position = file.DataOffset; if (file.Channels == 1) { switch (file.SampleBit) { case 8: return(Read1Channel(stream, file.SampleNumber, file.MaxWidth, Read8Bit)); case 16: return(Read1Channel(stream, file.SampleNumber, file.MaxWidth, Read16Bit)); default: return(null); } } else { switch (file.SampleBit) { case 8: return(Read2Channels(stream, file.SampleNumber / 2, file.MaxWidth, Read8Bit)); case 16: return(Read2Channels(stream, file.SampleNumber / 2, file.MaxWidth, Read16Bit)); default: return(null); } } }
private void SaveDateWave() { WavFile new_file = new WavFile(FileName.Remove(FileName.Length - 4) + "-Modify.wav"); //выходной файл Line.Points.ForEach(p => Processed.WriteSample((float)p.Y)); new_file.WriteData(Processed); }
public static WaveData Read(WavFile file) { var stream = new FileStream(file.FileName, FileMode.Open); var result = Read(file, stream); stream.Close(); return(result); }
public static void Behavioral_VisitorDemo2() { var wavFile = WavFile.Read("myfile.wav"); wavFile.ApplyFilter(new NoiseReductionFilter()); wavFile.ApplyFilter(new ReverbFilter()); wavFile.ApplyFilter(new NormalizeFilter()); }
public void TestWriteTag() { var tag = new ListTag(); tag.Name = "これはテストです。採集実行日:" + DateTime.Now; WavFile.WriteTagToWavFile(@"..\..\testData\input\01-1.wav", tag, true); }
/// При скрывании окна сбрасывает все параметры данного окна до исходных. private void LoadFileForm_VisibleChanged(object sender, EventArgs e) { this.wav = new WavFile(); this.fileTextBox.Text = ""; this.showResButton.BackColor = Color.Gray; this.showResButton.Enabled = false; this.runButton.Enabled = true; this.FFTProgressBar.Value = 0; }
private async void LoadWavData(SafeFileHandle handle) { _wv?.Dispose(); _wv = new WavFile(); await _wv.OpenAsync(handle); WavFileInfo.Text = _wv.ToString(); }
public void Test_SaveEmpty_Throws() { (int sampleRate, double[] audio) = WavFile.ReadMono("../../../../../data/cant-do-that-44100.wav"); int fftSize = 4096; var spec = new Spectrogram(sampleRate, fftSize, stepSize: 500); //spec.Add(audio); Assert.Throws <InvalidOperationException>(() => { spec.SaveImage("empty.png"); }); }
public static ImageSource Draw1Channel(WavFile wavFile, WaveStyle style, double startPer, double scale, double width, double height) { using (var stream = File.Open(wavFile.FileName, FileMode.Open)) { using (var reader = new BinaryReader(stream)) { } } return(null); }
public void Test_Quickstart_Hal() { (int sampleRate, double[] audio) = WavFile.ReadMono("../../../../../data/cant-do-that-44100.wav"); int fftSize = 4096; var spec = new Spectrogram(sampleRate, fftSize, stepSize: 500, maxFreq: 3000); spec.Add(audio); spec.SaveImage("../../../../../dev/graphics/hal.png", intensity: .2); Console.WriteLine(spec); }
public SuccessViewModel CalculateSuccess(SongViewModel song) { try { SongBE entity; entity = Mapper.Map <SongViewModel, SongBE>(song); SongDAL songDAL = new SongDAL(); SuccessViewModel successViewModel = new SuccessViewModel(); var listSongs = songDAL.GetSongsToCalculate(entity.Category); (int sampleRate, double[] audio) = WavFile.ReadMono(FileUtils.GetRepoMusicPath(song.SongKey)); var spec = new Spectrogram.Spectrogram(sampleRate / 2, fftSize: (16384 / 8), stepSize: (2500 * 5), maxFreq: 2200); spec.Add(audio); var tempPath = Path.GetTempPath(); spec.SaveImage(tempPath + "/" + song.SongKey + ".jpg", intensity: 5, dB: true); var file = FileUtils.GetImageBytes(tempPath + "/" + song.SongKey + ".jpg"); successViewModel.ImageBase64 = "data:image/jpg;base64," + Convert.ToBase64String(file); var bmHash = this.GetHash(spec.GetBitmap()); List <Spectrogram.Spectrogram> spectrograms = new List <Spectrogram.Spectrogram>(); foreach (var son in listSongs) { (int sampleRateSong, double[] audioSong) = WavFile.ReadMono(FileUtils.GetRepoMusicPath(son.SongKey)); var specSong = new Spectrogram.Spectrogram(sampleRateSong / 2, fftSize: (16384 / 8), stepSize: (2500 * 5), maxFreq: 2200); specSong.Add(audioSong); spectrograms.Add(specSong); } int equalElements = 0; foreach (var sp in spectrograms) { equalElements += bmHash.Zip(this.GetHash(sp.GetBitmap()), (i, j) => i == j).Count(eq => eq); } var con = Convert.ToInt32(equalElements / spectrograms.Count); successViewModel.Percentage = Convert.ToInt32((con * 100) / bmHash.Count); return(successViewModel); } catch (Exception ex) { throw new Exception(Messages.Generic_Error); } }
public void Test_AGC_off() { string wavFilePath = "../../../../../data/qrss-10min.wav"; (int sampleRate, double[] L) = WavFile.ReadMono(wavFilePath); int fftSize = 8192; var spec = new Spectrogram(sampleRate, fftSize, stepSize: 2000, maxFreq: 3000); spec.Add(L); spec.SaveImage("qrss-agc-off.png", intensity: 3); }
async void Start() { string key = Environment.GetEnvironmentVariable("SKYPE_KEY"); if (string.IsNullOrEmpty(key)) { Debug.Log("Please set an environment variable named 'SKYPE_KEY' to your Skype api key"); return; } // First retrieve a time-restricted key to use to access the API (will need to write code // to refresh this later). _http = new HttpClient(); _http.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", key); Debug.Log(key); var url = string.Format("https://api.cognitive.microsoft.com/sts/v1.0/issueToken"); Debug.Log(url); var resp = await _http.PostAsync(url, null); resp.EnsureSuccessStatusCode(); var token = await resp.Content.ReadAsStringAsync(); _ws = new ClientWebSocket(); Debug.Log(token); _ws.Options.SetRequestHeader("Authorization", "Bearer " + token); try { await _ws.ConnectAsync(new Uri(speechurl), CancellationToken.None); //await _ws.ConnectAsync(new Uri("http://localhost:54545"), CancellationToken.None); } catch (WebSocketException ex) { Debug.Log(ex.Message + " error code: " + ex.WebSocketErrorCode); return; } Debug.Log("successfully connected"); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed //Task.Run(ReceiveAsync); ReceiveAsync(); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed // as soon as we are connected send the WAVE header.. ArraySegment <byte> data = new ArraySegment <byte>(WavFile.GetWaveHeader(0)); await _ws.SendAsync(data, WebSocketMessageType.Binary, true, CancellationToken.None); Debug.Log("Sent WAVE header"); }
public void Test_SFF_LinearBigMaxFreq() { // test creating SFF file from 16-bit 48kHz mono WAV file (int sampleRate, double[] audio) = WavFile.ReadMono("../../../../../data/03-02-03-01-02-01-19.wav"); Assert.AreEqual(48000, sampleRate); int fftSize = 1 << 12; var spec = new Spectrogram(sampleRate, fftSize, stepSize: 300, maxFreq: 7999); spec.Add(audio); spec.SaveData("testDoorBig.sff"); }
public WavView(FileSystemEntry entry, Func <IntPtr, Game> createGame) { _file = WavFile.FromFileSystemEntry(entry); CreateGame = h => { _game = createGame(h); var source = _game.Audio.PlayFile(entry.FilePath, true); source.Play(); return(_game); }; }
public void Test_Mel_Spectrogram() { (int sampleRate, double[] audio) = WavFile.ReadMono("../../../../../data/cant-do-that-44100.wav"); int fftSize = 4096; var spec = new Spectrogram(sampleRate, fftSize, stepSize: 500); spec.Add(audio); spec.SaveImage("halNotMel.png", 4, true); Bitmap bmp = spec.GetBitmapMel(250, 4, true); bmp.Save("../../../../../dev/graphics/halMel.png", ImageFormat.Png); }
public static BitArray Decompose(IDemodulator demodulator, WavFile wavFile) { var samples = wavFile.Data.ToShortArray(); samples = new Trimmer().Trim(samples); var hpFilter = new HighPassFilter( cutoffFrequency: demodulator.CarrierFrequency / 2.0, sampleRate: demodulator.SampleRate ); // samples = hpFilter.FilterSamples(samples); samples = new Normalizer().PeakNormalize(samples); // samples = new PhaseFixer().FixPhase(samples, (int)demodulator.SampleRate, 2); // var soundBytes = samples.ToByteArray(); var processedSound = new WavFile(wavFile.SampleRate, soundBytes); using (FileStream fs = new FileStream($"PROCESSED.wav", FileMode.Create)) { BinaryWriter bw = new BinaryWriter(fs); bw.Write(processedSound.ToBytes()); } // var waveDecomposer = new WaveDecomposer(demodulator); var dataSegments = waveDecomposer.FindDataSegments(samples); BitArray data = null; foreach (var segment in dataSegments) { var bits = demodulator.ReadBits(segment.DataSamples, segment.ZerosValue, segment.OnesValue, segment.BytesToRead); if (data == null) { data = new BitArray(bits); } else { data = data.MergeWith(bits); } } return(data); }
public AudioContent(WavFile wavFile) { this.FileType = AudioFileType.Wav; this.AudioFormat = new AudioFormat(); this.AudioFormat.Channels = wavFile.NumChannels; this.AudioFormat.SampleRate = (int)wavFile.SampleRate; this.AudioFormat.AverageBytesPerSecond = (int)wavFile.ByteRate; this.AudioFormat.BlockAlign = wavFile.BlockAlign; this.AudioFormat.BitsPerSample = wavFile.BitsPerSample; this.LoopStart = 0; this.LoopEnd = wavFile.Data.Length / wavFile.BlockAlign; this.Duration = new TimeSpan(0, 0, 0, 0, (int)(((double)this.LoopEnd / (double)wavFile.SampleRate + 0.0005) * 1000)); this.Data = wavFile.Data; }
public VisitorPatternMain() { // var document = new HtmlDocument(); // document.AddNode(new HeadingNode()); // document.AddNode(new AnchorNode()); // // document.Execute(new PlainTextOperation()); // document.Execute(new HighlightOperation()); var wav = WavFile.Read(""); wav.ApplyFilter(new ReduceNoiseFilterOperation()); wav.ApplyFilter(new PitchShiftFilterOperation()); }
public void UMatrixTest() { using (var fileStream = File.OpenRead(@"C:\Users\Jery\Downloads\ES_Action Intro Scene 12 - Andreas Ericson.wav")) { var wav = new WavFile(fileStream); var s = 2; var r = 6; var n = 16; var sequel = new double[n + 1, n + 1]; var sequelProducer = new CombWave.UMatrix(wav.Samples.Skip(100).Take(n).Select((t, i) => new DataPoint(i, t.FirstChannel)).ToList(), s, r); for (int i = 0; i <= n; ++i) for (int j = 0; j <= n; ++j) sequel[i, j] = sequelProducer[i, j]; PrintMatrix(sequel); } }
private void btnLoadWavFile_Click(object sender, EventArgs e) { if (openWavFileDialog.ShowDialog() == DialogResult.OK) { using (var file = openWavFileDialog.OpenFile()) { Text = openWavFileDialog.FileName; WaveFile = new WavFile(file); } } }