2015-09-30 14 views
2

我不知道是否有方法在r中編寫腳本來創建音樂。像編碼程序(SuperCollider或更少的編碼,但仍然是純數據),我想知道是否有方法在R中生成聲音。是否可以在R中編碼音樂並播放它? (Mac OS X)

其實,我知道這是非常好的How can I play birthday music using R?。但我想要做和絃和多樂器組合。可能嗎?

在R中播放音樂的方式比生日快樂鏈接更簡單嗎?

+0

如何進行播放生日音樂? –

+0

[tuneR軟件包](https://cran.r-project.org/web/packages/tuneR/index.html),例如https://rpubs.com/bbolker/4113 –

+0

有一段時間沒有更新,但是:https://github.com/Dasonk/musicmakeR出現了問題,但我相信Dason會接受一個拉取請求到目前爲止:https://github.com/Dasonk/musicmakeR/issues/3 –

回答

1

在R中可以編程使用調音器庫

首先,你需要爲每一個音符創建簡單的正弦波並連接所有的筆記爲載體創作音樂。

現在調會準備好,你可以使用不同的聲音處理技術,如音色,過濾等

實例創建一個簡單的A4筆記編輯您的聲音:

library(tuneR)  #import the tuneR library 
setWavPlayer("audacious") 
f=440     #frequency of A4 note 
sr=8000 
bits=16 
secs=2    #length of the note set to 2 
amp=1 
t=seq(0, secs, 1/sr) 
y= amp*sin(2*pi*f*t) #make a sinewave with above attributes 
s=floor(2^(bits-2)*y) #floor it to make it an integer value 
u=Wave(s, samp.rate=sr, bit=bits) #make a wave structure 
play(u) 

要連接兩個票據x和y,我們簡單地使用向量記號:

z=c(x,y) 
w= Wave(z, samp.rate=sr, bit-bits) 

同時播放兩個音符(例如播放和絃)

z=x+y 
w= Wave(z, samp.rate=sr, bit-bits) 
+0

這不起作用。我有此錯誤: 'SH:大膽:如果您使用的是Windows命令不found' –

+0

,只需刪除該行 如果您使用的是Mac,大膽改變爲「afplay」 基本上,這條線設置一個播放器播放波形文件。我使用Ubuntu並與一個名爲「大膽」的播放器一起玩 – rakshith1124

+0

我正在使用MAC,現在我有這個:'錯誤:'.path.package'已經失效。 改爲使用'path.package'。 查看幫助(「Defunct」) 警告消息: In setWavPlayer(「afplay」): ============================ ========================================================= 莫恩不運行給定的命令。 確保它可以用作'command soundfile.wav'然後再試一次。 欲瞭解更多信息,請鍵入'?setWavPlayer'。 ================================================= ===========================' –

0

就目前而言,這是我想出來的最好的:

library("audio") 
library(tuneR)  #import the tuneR library 
for (i in 1:10) { 
yo=abs(round(rnorm(1,400,500))) 
f=yo     #frequency of A4 note 
sr=1000000 
bits=116 
secs=5    #length of the note set to 2 
amp=1 
t=seq(0, secs, 1/sr) 
y= amp*sin(2*pi*f*t) #make a sinewave with above attributes 
s=floor(2^(bits-2)*y) #floor it to make it an integer value 
# u=Wave(s, samp.rate=sr, bit=bits) #make a wave structure 
u=audioSample(x = s, rate = sr,bits = bits) 
audio::play(u) 
} 
相關問題