Hi,
Sorry, my request might sound like a very stupid one, and maybe this is not the correct place to ask, but I'm struggling to actually play the waveform generated by Meltysynth.
What I'm trying to do:
- generate a midi file in memory
- render it with Meltysynth into a memory stream
- finally play the stream
What I've achieved so far:
private static void PlayMeltysynthChord()
{
var sampleRate = 44100;
var synthesizer = new Synthesizer(@"..\Resources\Raw\Abbey-Steinway-D-v1.9.sf2", sampleRate);
synthesizer.NoteOn(0, 60, 100);
synthesizer.NoteOn(0, 63, 100);
synthesizer.NoteOn(0, 66, 100);
var mono = new float[3 * sampleRate];
synthesizer.RenderMono(mono);
var byteArray = new byte[mono.Length * 4];
Buffer.BlockCopy(mono, 0, byteArray, 0, byteArray.Length);
var wav = new WavePcmFormat(byteArray, numChannels: 1, sampleRate: (uint)sampleRate, bitsPerSample: 16);
var rawDataWithHeader = wav.ToBytesArray();
var stream = new MemoryStream(rawDataWithHeader);
var player = new System.Media.SoundPlayer(stream);
player.Play();
}
The 'WavePCMFormat' method inserts the .wav header to the data. The result I get is a few seconds of white noise, so I assume there is something wrong in the transformation of the rendered PCM to the .wav stream.
Any help is welcome... Thanks in advance
Hi,
Sorry, my request might sound like a very stupid one, and maybe this is not the correct place to ask, but I'm struggling to actually play the waveform generated by Meltysynth.
What I'm trying to do:
What I've achieved so far:
The 'WavePCMFormat' method inserts the .wav header to the data. The result I get is a few seconds of white noise, so I assume there is something wrong in the transformation of the rendered PCM to the .wav stream.
Any help is welcome... Thanks in advance