Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird rendering time consuming / midi rendering efficiency with Kontakt #15

Closed
ZhaoJY1 opened this issue Nov 26, 2020 · 5 comments
Closed

Comments

@ZhaoJY1
Copy link

ZhaoJY1 commented Nov 26, 2020

Hallo,

I encounter some rendering time consuming problem. In my own implement code, I wanted to render a midi file of approximately 4 minitues. And it just stucks at the engine.render(end_time) step. So I tested with following appended code for different intended rendering time length, and found that:

  • when render for 5 seconds, rendering takes about 2 seconds
  • when render for 10 seconds, rendering takes about 11 seconds
  • when render for 20 seconds, rendering takes about 44-47 seconds

So, if render for some 300 seconds, the render time consuming would blow up and it simply looks like the program stucks.

I also tried with a real midi file which contains not so much "blank area", but got the same effect.

What could have gone wrong?

code:

import numpy as np
import os
import pretty_midi
import soundfile as sf
import time

import dawdreamer as daw

SAMPLE_RATE = 44100
BUFFER_SIZE = 512
SYNTH_PLUGIN = os.path.abspath('testVST/DSK The Grand.dll') # plugin path

print('making engine...')
engine = daw.RenderEngine(SAMPLE_RATE, BUFFER_SIZE)

print('making processor...')
synth = engine.make_plugin_processor("synth", SYNTH_PLUGIN)

graph = [
    (synth, []),
]

synth.add_midi_note(60, 127, 0., 1.)  # note, velocity, start time sec, duration sec
synth.add_midi_note(67, 127, 0.5, .25)
# midi_path = os.path.abspath('MIDI/Track043_singleTrack.mid')
# pm = pretty_midi.PrettyMIDI(midi_path)
# end_time = pm.get_end_time()
# print('end time: {}'.format(end_time))
# synth.load_midi(midi_path)
print('loading graph...')
assert(engine.load_graph(graph))
print('rendering...')
start = time.time()
engine.render(10.)    # test e.g. 5, 10, 20... seconds
end = time.time()
print('Rendering time {}'.format(end - start))
audio = engine.get_audio()
audio = np.array(audio, np.float32).transpose()
sf.write('test_synth_basic.wav', audio, SAMPLE_RATE)

print("All Done!")
@DBraun
Copy link
Owner

DBraun commented Nov 27, 2020

Thank you very much for catching this. I made a few mistakes in the RecorderProcessor.h class. I will try to fix them now.

DBraun pushed a commit that referenced this issue Nov 27, 2020
…Bug fix for exponential slow-down in render function (github issue #15).
@DBraun
Copy link
Owner

DBraun commented Nov 27, 2020

I think I got it. Can you give the latest update a try? 5ab8e4b

I used your script and can render 120 seconds in 0.79 seconds.

@ZhaoJY1
Copy link
Author

ZhaoJY1 commented Nov 29, 2020

Hallo,

thanks a lot for so quick debuging. Yes, I tested it with my implementation, it works now fine and efficiently!!!

@DBraun
Copy link
Owner

DBraun commented Nov 30, 2020

Great!

@DBraun DBraun closed this as completed Nov 30, 2020
@youknowwyz
Copy link

I have run your code to render a midi file, but I got an all zero WAV file. What could have gone wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants