public void Run() { for (var i = 0; i < Settings.BlockCount; i++) { sequencer.FillMidiEventQueue(true); synthesizer.GetNext(); writer.Write(synthesizer.sampleBuffer); } }
public void Run() { for (var i = 0; i < Settings.BlockCount; i++) { sequencer.Render(left, right); for (var t = 0; t < Settings.BlockSize; t++) { writeBuffer[2 * t] = left[t]; writeBuffer[2 * t + 1] = right[t]; } writer.Write(writeBuffer); } }
public void Convert(ISampleWriter output, WaveFormat format, bool loudmax, CancellationToken cancel) { try { using (var bass = new BASSMIDI(format)) { ISampleSource bassSource; /*if (loudmax) bassSource = new AntiClipping(bass, 0.1); * else bassSource = bass;*/ bassSource = bass; //Why the hell was it running loudmax twice lol float[] buffer = new float[2048 * 16]; long prevWriteTime = 0; double time = 0; int read; foreach (MIDIEvent e in events) { cancel.ThrowIfCancellationRequested(); time += e.DeltaTime; converted = time; var writeTime = (long)(time * format.SampleRate); var offset = (int)((writeTime - prevWriteTime) * 2); prevWriteTime = writeTime; while (offset > 0) { if (offset < buffer.Length) { bassSource.Read(buffer, 0, offset); output.Write(buffer, 0, offset); offset = 0; } else { bassSource.Read(buffer, 0, buffer.Length); output.Write(buffer, 0, buffer.Length); offset -= buffer.Length; } } if (e is NoteOnEvent) { var ev = e as NoteOnEvent; bass.SendEventRaw((uint)(ev.Channel | 0x90 | (ev.Key << 8) | (ev.Velocity << 16)), 0); } else if (e is NoteOffEvent) { var ev = e as NoteOffEvent; bass.SendEventRaw((uint)(ev.Channel | 0x80 | (ev.Key << 8)), 0); } else if (e is PolyphonicKeyPressureEvent) { var ev = e as PolyphonicKeyPressureEvent; bass.SendEventRaw((uint)(ev.Channel | 0xA0 | (ev.Key << 8) | (ev.Velocity << 16)), 0); } else if (e is ControlChangeEvent) { if (Properties.Settings.Default.RVOverrideToggle) { for (int i = 0; i <= 15; i++) { bass.SendReverbEvent(i, Properties.Settings.Default.ReverbValue); bass.SendChorusEvent(i, Properties.Settings.Default.ChorusValue); } } var ev = e as ControlChangeEvent; bass.SendEventRaw((uint)(0xB0 | (ev.Controller << 8) | (ev.Value << 16)), ev.Channel + 1); } else if (e is ProgramChangeEvent) { var ev = e as ProgramChangeEvent; bass.SendEventRaw((uint)(ev.Channel | 0xC0 | (ev.Program << 8)), 0); } else if (e is ChannelPressureEvent) { var ev = e as ChannelPressureEvent; bass.SendEventRaw((uint)(ev.Channel | 0xD0 | (ev.Pressure << 8)), 0); } else if (e is PitchWheelChangeEvent) { var ev = e as PitchWheelChangeEvent; var val = ev.Value + 8192; bass.SendEventRaw((uint)(ev.Channel | 0xE0 | ((val & 0x7F) << 8) | (((val >> 7) & 0x7F) << 16)), 0); } } bass.SendEndEvent(); while ((read = bassSource.Read(buffer, 0, buffer.Length)) != 0) { output.Write(buffer, 0, read); } } } catch (OperationCanceledException) { } }