合成一首歌曲时,音符之间的精确延时 [英] Accurate delays between notes when synthesising a song

查看:383
本文介绍了合成一首歌曲时,音符之间的精确延时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写C ++ code起着两个数字音频(合成音乐)和MIDI音乐在同一时间(使用RtMidi库)。数​​字化音乐将发挥出电脑的音频设备,但MIDI音乐可以发挥出外部合成。我想玩同时使用数字化仪器和MIDI乐器一首歌曲,而我不能确定这两个音频流同步的最佳方式:

I'm writing C++ code which plays both digital audio (synthesised music) and MIDI music at the same time (using the RtMidi library.) The digitised music will play out of the computer's audio device, but the MIDI music could play out of an external synthesiser. I want to play a song that uses both digitised instruments and MIDI instruments, and I am not sure of the best way to synchronise these two audio streams:


  • 这是不可能使用像睡眠()作为延迟时间是既不平衡,太长了我的需求(这是一毫秒的量级)。如果睡眠()定期为5毫秒,只有当1ms的等待功能请求,由此产生的乐曲速度会关闭,除非它是准确的每一个,它被称为时间,速度将是不平衡的。

  • 计数放入音频缓冲器的样本数为音符之间的数字音频的超精确的定时(的一个样本的最小延迟 - 在48kHz的0.02ms),但该定时不能用于MIDI。因为音频缓冲音符在脉冲串(在一个时间填满一个音频缓冲器,尽可能快地)中合成所以这导致了一堆的MIDI音符被与每一个数字音频缓冲器需要时间在它们之间没有延迟播放重新填充。

  • 现场演奏MIDI数据没有时序信息,所以记只要它发送播放。因此,一个音符无法安排在稍后的时间玩,所以我需要在正确的时间准确地发送MIDI事件自己。

目前我使用了nanosleep() - 它只有Linux,而不是Windows下工作 - 等待音符之间正确的时间。这使得无论是数字音频和MIDI的数据保持同步,因此产生的节奏很不均匀不过了nanosleep()不是很一致。

Currently I am using nanosleep() - which only works under Linux, not Windows - to wait for the correct time between notes. This allows both the digital audio and the MIDI data to remain synchronised, however nanosleep() is not very consistent so the resulting tempo is very uneven.

任何人都可以想办法留住这两个数字音频笔记还有MIDI数据之间的精确定时?

Can anyone think of a way to retain accurate timing between notes for both the digital audio as well as the MIDI data?

推荐答案

如果你愿意使用Boost,它的 CPU- precision定时器。如果没有,在Windows上有功能的 QueryPerformanceCounter的 QueryPerformanceFrequency的,它可用于基于CPU的时间,这肯定会适合所有您的需求。有很多定时器类实现的网络上,他们中的一些在Windows和* IX系统都工作。

If you are willing to use Boost, it has CPU-precision timers. If not, on Windows there are functions QueryPerformanceCounter and QueryPerformanceFrequency, which can be used for CPU-based timing, which will certainly suit all of your needs. There are plenty of Timer classes implementations around the web, some of them working both on windows and *ix systems.

这篇关于合成一首歌曲时,音符之间的精确延时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆