Sonic Pi - en to zh-CN translation catalogue (364 entries)

en: 1 Welcome to Sonic Pi
zh-CN: 1 欢迎来到 Sonic Pi

en: Welcome friend :-)
zh-CN: 盆友，欢迎您的到来！:-)

en: But wait, how rude of me! Let me introduce myself - I'm [Sam Aaron](https://twitter.com/samaaron) - the chap that created Sonic Pi. You can find me at [@samaaron](http://twitter.com/samaaron) on Twitter and I'd be more than happy to say hello to you. You might also be interested in finding out more about my [Live Coding Performances](https://youtube.com/samaaron) where I code with Sonic Pi live in front of audiences.
zh-CN: 先等一下，我有点急躁了~让我先介绍一下我自己吧——我是[Sam Aaron](https://twitter.com/samaaron)，我创造了Sonic Pi。这是我的Twitter：[@samaaron](https://twitter.com/samaaron)，我很想和你打声招呼。你也许也会有兴趣来观看我直播[表演编写代码](https://youtube.com/samaaron)。

en: If you have any thoughts, or ideas for improving Sonic Pi - please pass them on - feedback is so helpful. You never know, your idea might be the next big feature!
zh-CN: 如果你对Sonic Pi有任何想法或建议——请把它们发过来——反馈是很有帮助的。你永远不知道你的建议会不会就是下一个版本的一大特色！

en: This tutorial is divided up into sections grouped by category. Whilst I've written it to have an easy learning progression from start to finish, feel very free just to dip in and out of sections as you see fit. If you feel that there's something missing, do let me know and I'll consider it for a future version.
zh-CN: 本教程是通过章节来划分的。同时，我也写了一个从头到尾的简易学习教程，你可以自由的在你想看的章节中来回穿梭。如果你发现Sonic Pi缺点什么，一定要告诉我！我会考虑把它们加入未来的版本中。

en: Finally, watching others live code is a really great way to learn. I regularly stream live on [https://youtube.com/samaaron](http://youtube.com/samaaron) so please do drop by, say hi and ask me lots of questions :-)
zh-CN: 最后，观看他人直播写代码也是一个很好的学习方式。我时常在[http://youtube.com/samaaron](http://youtube.com/samaaron)上直播，欢迎来观看并且询问问题 :-)

en: OK, let's get started...
zh-CN: 让我们开始吧……

en: 1.1 Live Coding
zh-CN: 1.1 即时代码

en: Live Coding
zh-CN: 即时代码

en: One of the most exciting aspects of Sonic Pi is that it enables you to write and *modify code live* to make music, just like you might perform live with a guitar. This means that given some practice you can take Sonic Pi on stage and gig with it.
zh-CN: Sonic Pi的一大特性是使你能够即时编写和*修改代码*来演奏音乐，就像在你可以现场演奏一把吉他一样。 换句话说，经过一定的练习，你可以把Sonic Pi 带上舞台并且拿它来演出。

en: Free your mind
zh-CN: 放轻松

en: Before we get into the real details of how Sonic Pi works in the rest of this tutorial, I'd like to give you an experience of what it's like to live code. Don't worry if you don't understand much (or any) of this. Just try to hold onto your seats and enjoy...
zh-CN: 在我们探索Sonic Pi的详细使用方法之前，我想先让你体验一下即时代码的感受。如果你没有明白代码的绝大（或者全部）部分，别担心，先坐下来静静享受吧...

en: A live loop
zh-CN: 一个简单的循环

en: Let's get started, copy the following code into an empty buffer:
zh-CN: 让我们开始吧。 把下面的代码复制到一个空的编辑器里：

en: Now, press the `Run` button and you'll hear a nice fast bass drum beating away. If at any time you wish to stop the sound just hit the `Stop` button. Although don't hit it just yet... Instead, follow these steps:
zh-CN: 现在，按`运行`按钮，你会听到一个好听的快速击打的低音鼓。你可以在任何时候按`停止`按钮来停止。但现在先别急停止，先试试这些步骤:

en: Make sure the bass drum sound is still running
zh-CN: 确认低音鼓仍然在运行

en: Change the `sleep` value from `0.5` to something higher like `1`.
zh-CN: 将`sleep`的值从`0.5`改成一个更大的，比如`1`。

en: Press the `Run` button again
zh-CN: 再次点击“运行”按钮

en: Notice how the drum speed has changed.
zh-CN: 注意鼓速度的变化。

en: Finally, *remember this moment*, this is the first time you've live coded with Sonic Pi and it's unlikely to be your last...
zh-CN: 最后，记住这个时刻。这是你第一次用Sonic Pi 编写音乐，我相信这也绝不是你最后一次。

en: Ok, that was simple enough. Let's add something else into the mix. Above `sample :bd_haus` add the line `sample :ambi_choir, rate: 0.3`. Your code should look like this:
zh-CN: OK，这真的是太简单啦！让我们在混响中添加一些其他东西。在‘sample :bd_haus’上面添加一行：`sample :ambi_choir, rate: 0.3`。你的代码就变成这样：

en: Now, play around. Change the rates - what happens when you use high values, or small values or negative values? See what happens when you change the `rate:` value for the `:ambi_choir` sample just slightly (say to `0.29`). What happens if you choose a really small `sleep` value? See if you can make it go so fast your computer will stop with an error because it can't keep up (if that happens, just choose a bigger `sleep` time and hit `Run` again).
zh-CN: 现在，开始播放吧。改变rates(音调)，看看rate设为很高或者很低甚至为负数时会发生什么？看看我们把`:ambi_choir`的`rate:`调小一点(调成‘0.29’？)会发生什么？把`sleep`的值调得很小又如何呢？如果你把`sleep` 设置的很低，你的电脑可能会崩溃（如果真的崩溃了，只要设高一点儿，然后重新运行就可以啦)。

en: Try commenting one of the `sample` lines out by adding a `#` to the beginning:
zh-CN: 试着把一个`sample`代码行注释掉（在这一行前加一个`#`）：

en: Notice how it tells the computer to ignore it, so we don't hear it. This is called a comment. In Sonic Pi we can use comments to remove and add things into the mix.
zh-CN: 注意：这是告诉电脑忽略这条语句，所以我们这条语句我们是听不到的。我们称之为注释。在Sonic Pi中我们可以用注释来疏略一条语句。

en: Finally, let me leave you something fun to play with. Take the code below, and copy it into a spare buffer. Now, don't try to understand it too much other than see that there are two loops - so two things going round at the same time. Now, do what you do best - experiment and play around. Here are some suggestions:
zh-CN: 最后，然我给你留点好玩的。复制下面的代码到空白区域。现在，不要想太多，只要知道这是两个循环就行了——这两个循环同时运行。现在，拿这两个循环做实验吧！下面是一些建议：

en: Try changing the blue `rate:` values to hear the sample sound change.
zh-CN: 试着更改蓝色的 `rate:`的值听听有什么改变。

en: Try changing the `sleep` times and hear that both loops can spin round at different rates.
zh-CN: 试着改变‘sleep’的时间让两个循环以不同的速度旋转。

en: Try uncommenting the sample line (remove the `#`) and enjoy the sound of the guitar played backwards.
zh-CN: 试着取消注释（删除‘#’符号）享受吉他倒着弹的效果吧。

en: Try changing any of the blue `mix:` values to numbers between `0` (not in the mix) and `1` (fully in the mix).
zh-CN: 试着改变任何蓝色的 ‘mix` 的值为0（不在mix中）到1（完全在mix中）之间的任何值。

en: Remember to press `Run` and you'll hear the change next time the loop goes round. If you end up in a pickle, don't worry - hit `Stop`, delete the code in the buffer and paste a fresh copy in and you're ready to jam again. Making mistakes is how you'll learn the quickest...
zh-CN: 记住点击‘run’按钮后改动才会生效。如果你听糊涂了，你可以点击‘stop'按钮停止，删除原来的代码，复制一份新的代码，然后继续听的一塌糊涂。犯错是最快的学习方式。

en: Now, keep playing and experimenting until your curiosity about how this all actually works kicks in and you start wondering what else you can do with this. You're now ready to read the rest of the tutorial.
zh-CN: 现在，继续听和做实验直到你的好奇心完全被它所吸引并且急切的想知道我还能用它做什么。至此你已经准备好阅读下面的教程了。

en: So what are you waiting for...
zh-CN: 所以还等什么呢……

en: 1.2 Exploring the Interface
zh-CN: 探索界面

en: The Sonic Pi Interface
zh-CN: Sonic Pi的主界面

en: Sonic Pi has a very simple interface for coding music. Let's spend a little time exploring it.
zh-CN: Sonic Pi有着非常简洁的主界面。让我们花一点时间了解一下吧。

en: *A* - Play Controls
zh-CN: *A* - 播放控制

en: *B* - Editor Controls
zh-CN: *B* - 代码编辑窗口控制

en: *C* - Info and Help
zh-CN: *C* - 详细信息和帮助

en: *D* - Code Editor
zh-CN: *D* - 代码编辑窗口

en: *E* - Prefs Panel
zh-CN: *E* - 偏好设置

en: *F* - Log Viewer
zh-CN: *F* - 日志窗口

en: *G* - Help System
zh-CN: *G* - 帮助系统

en: *H* - Scope Viewer
zh-CN: *H* - 波形查看器

en: *I* - Cue Viewer
zh-CN: *I* - 查看Cue

en: A. Play Controls
zh-CN: A. 播放控制

en: These pink buttons are the main controls for starting and stopping sounds. There's the *Run* button for running the code in the editor, *Stop* for stopping all running code, *Save* for saving the code to an external file and *Record* to create a recording (a WAV file) of the sound playing.
zh-CN: 这些粉色的按钮是控制音乐播放和停止的主控制按钮。*Run*按钮是用来运行代码的，*Stop* 按钮是用来停止代码运行的，*Save*是用来把代码保存成一个文件，*Record*按钮是把音乐录制到文件中（后缀为wav的文件）。

en: B. Editor Controls
zh-CN: B. 代码编辑窗口控制

en: These orange buttons allow you to manipulate the code editor. The *Size +* and *Size -* buttons allow you to make the text bigger and smaller.
zh-CN: 你可以用这些橙色的按钮对代码编辑器进行操作。*Size +*和*Size -*能让你调大或调小文本字体。

en: C. Info and Help
zh-CN: C. 详细信息和帮助

en: These blue buttons give you access to information, help and preferences. The *Info* button will open up the information window which contains information about Sonic Pi itself - the core team, history, contributors and community. The *Help* button toggles the help system (*G*) and the *Prefs* button toggles the preferences window which allows you to control some basic system parameters.
zh-CN: 这些蓝色按钮可以用来打开详细信息窗口，帮助窗口和偏好设置窗口。*Info*按钮会打开详细信息窗口，它包含了Sonic Pi团队，贡献者和社区的详细信息。*Help*按钮打开帮助系统，*Prefs*按钮打开偏好设置按钮，它允许你控制一些基本的系统参数。

en: D. Code Editor
zh-CN: D. 代码编辑窗口

en: This is the area where you'll write your code and compose/perform music. It's a simple text editor where you can write code, delete it, cut and paste, etc. Think of it like a very basic version of Word or Google Docs. The editor will automatically colour words based on their meaning in the code. This may seem strange at first, but you'll soon find it very useful. For example, you'll know something is a number because it is blue.
zh-CN: 在这里可以写属于你自己的音乐代码。同时，在这里你也可以删除，复制以及粘贴代码。你可以把它想象类似于Google文档一样的简单编辑器。代码会根据具体意义进行变色。这种五颜六色的代码刚开始看起来有点奇怪，但之后你会发现它真的很有用！举个栗子，蓝色代表数字。

en: E. Prefs Panel
zh-CN: E. 偏好设置面板

en: Sonic Pi supports a number of tweakable preferences which can be accessed by toggling the *prefs* button in the Info and Help button set. This will toggle the visibility of the Prefs Panel which includes a number of options to be changed. Examples are forcing mono mode, inverting stereo, toggling log output verbosity and also a volume slider and audio selector on the Raspberry Pi.
zh-CN: Sonic Pi支持许多可调的偏好设置，你可以在*prefs*按钮中找到这些设置。例如：强制单声道模式，反转立体声，详细日志开关，音量调整滑块，声道选择器等。

en: F. Log Viewer
zh-CN: F. 日志查看器

en: When you run your code, information about what the program is doing will be displayed in the log viewer. By default, you'll see a message for every sound you create with the exact time the sound was triggered. This is very useful for debugging your code and understanding what your code is doing.
zh-CN: 当你运行代码的时候，程序执行的详细信息将会显示在日志查看器中。默认情况下，你会看到每一种声音产生的具体时间。这对你调试代码以及理解代码具体做了什么非常有帮助。

en: G. Help System
zh-CN: G. 帮助系统

en: One of the most important parts of the Sonic Pi interface is the help system which appears at the bottom of the window. This can be toggled on and off by clicking on the blue *Help* button. The help system contains help and information about all aspects of Sonic Pi including this tutorial, a list of available synths, samples, examples, FX and a full list of all the functions Sonic Pi provides for coding music.
zh-CN: Sonic Pi最重要的模块之一就是窗口底部的帮助系统。你可以通过蓝色的*Help*按钮开启或关闭它。这个帮助系统包括Sonic Pi各方面的帮助信息，包括：本次教程，一系列可用的合成器，声音样本，例子，音效以及Sonic Pi提供的全部功能。

en: H. Scope Viewer
zh-CN: H. 波形查看器

en: The scope viewer allows you to see the sound you're hearing. You can easily see that the saw wave looks like a saw and that the basic beep is a curvey sine wave. You can also see the difference between loud and quiet sounds by the size of the lines. There are 3 scopes to play with - the default is a combined scope for the left and right channels, there is a stereo scope which draws a separate scope for each channel. Finally there is a Lissajous curve scope which will show the phase relationship between the left and right channels and allows you to draw pretty pictures with sound (https://en.wikipedia.org/wiki/Lissajous_curve).
zh-CN: 波形查看器可以以图形的方式展现你听到的声音。你能轻易的看到锯齿波（就像一把锯子）以及基本的嘟嘟声（优美的正弦波）。你也可以通过波形的尺寸判断吵闹的或者安静的声音。这里有三种波形可供选择：默认波形是左右声道波形的共同绘制而成的，立体声波形：每个声道的波形单独绘制，最后是李萨如曲线波形：显示的是左右声道的相位关系，你可以通过李萨如图形画出漂亮的音乐图像。

en: I. Cue Viewer
zh-CN: I. 查看Cue

en: 1.3 Learning through Play
zh-CN: 1.3 边玩边学习

en: Learning through Play
zh-CN: 边玩边学习

en: Sonic Pi encourages you to learn about both computing and music through play and experimentation. The most important thing is that you're having fun, and before you know it you'll have accidentally learned how to code, compose and perform.
zh-CN: Sonic Pi鼓励你通过边玩边实验来学习编码音乐。当然最重要的是：你开心就好;-),在你真正了解它之前，你将不知不觉的学会如何写代码，作曲和表演。

en: There are no mistakes
zh-CN: 怎么折腾都不会出错

en: Whilst we're on this subject, let me just give you one piece of advice I've learned over my years of live coding with music - *there are no mistakes, only opportunities*. This is something I've often heard in relation to jazz but it works equally well with live coding. No matter how experienced you are - from a complete beginner to a seasoned live coder, you'll run some code that has a completely unexpected outcome. It might sound insanely cool - in which case run with it. However, it might sound totally jarring and out of place. It doesn't matter that it happened - what matters is what you do next with it. Take the sound, manipulate it and morph it into something awesome. The crowd will go *wild*.
zh-CN: 既然我们正在讨论这个问题，以我这么多年来码音乐的经验，让我来给你一些建议吧：不要怕犯错，勇于尝试。这是我弹爵士乐的时候听到最多的一句话，当然它同样适用于编码。无论你在编码方面的经验如何，无论你是菜鸟还是大神，你都会写出一些出乎你意料之外的结果。你的音乐可能听起来酷炫炸了-那很棒。但也有可能听起来很不协调而且奇奇怪怪。不过没关系，重要的是你接下来怎么做。拿起你的代码，对它进行一顿骚操作，让它脱胎换骨。人群会噪起来的。

en: Start Simple
zh-CN: 从简单开始

en: When you're learning, it's tempting to want to do amazing things *now*. However, just hold that thought and see it as a distant goal to reach *later*. For now, instead think of the *simplest* thing you could write which would be fun and rewarding that's a small step towards the amazing thing you have in your head. Once you have an idea about that simple step, then try and build it, play with it and then see what new ideas it gives you. Before long you'll be too busy having fun and making real progress.
zh-CN: 当我们研究它的时候，我们总是想马上实现一个伟大的作品。但是，让我们先打住这种想法，把它看成一个将来要实现的长远的目标。现在，不如写一些你能写的简单有趣的代码来激励你自己，这也是实现伟大作品的一小步。当你对实现这一小步有了想法之后，你可以尝试着去实现它，然后播放它，看看它会给带来什么新点子。不久你就会为了不断寻找乐趣而实现真正的进步。

en: Just make sure to share your work with others!
zh-CN: 记得和他人分享你的乐趣哦!

en: 2 Synths
zh-CN: 2 合成器

en: Synths
zh-CN: 合成器

en: OK, enough of the intros - let's get into some sound.
zh-CN: OK，介绍差不多结束了 - 让我们来点音乐吧。

en: In this section we'll cover the basics of triggering and manipulating synths. Synth is short for synthesiser which is a fancy word for something which creates sounds. Typically synths are quite complicated to use - especially analog synths such as Eurorack modules connected together by a mess of wires. However, Sonic Pi gives you much of that power in a very simple and approachable manner.
zh-CN: 在这章我们会学到触发和操作合成器的基础知识。Synth是synthesiser 的缩写，用来表示某种能产生声音的东西。一般情况下，合成器使用起来很复杂，特别是模拟合成器，例如由一堆电线连接在一起的Eurorack模块。但是，Sonic Pi 会以简单，人性化的方式提供合成器的大部分功能。

en: Don't be fooled by the immediate simplicity of Sonic Pi's interface. You can get very deep into very sophisticated sound manipulation if that's your thing. Hold on to your hats...
zh-CN: 不要被Sonic Pi 及其简介的界面所迷惑。如果你想做，你可以用它来实现很复杂的声音操作。保持良好的状态...

en: 2.1 Your First Beeps
zh-CN: 2.1 你的第一个蜂鸣声

en: Your First Beeps
zh-CN: 你的第一个蜂鸣声

en: Take a look at the following code:
zh-CN: 看看下面的代码：

en: This is where it all starts. Go ahead, copy and paste it into the code window at the top of the app (the big white space under the Run button). Now, press Run...
zh-CN: 让我们先从这里开始。行动吧，复制代码，然后点击‘Run’按钮运行一下。。。

en: Beep!
zh-CN: 蜂鸣声！

en: Intense. Press it again. And again. *And again...*
zh-CN: 真刺激。再点一下，再点一下，*再点一下...*

en: Can you hear the difference? Try a lower number:
zh-CN: 你能听出来不同吗？试一下更低的数字：

en: So, lower numbers make lower pitched beeps and higher numbers make higher pitched beeps. Just like on a piano, the keys at the lower part of the piano (the left hand side) play lower notes and the keys on the higher part of the piano (the right hand side) play higher notes.
zh-CN: 那么，数值越低的数字会制造音高越低的蜂鸣声，而数值越高的数字会制造音高越高的蜂鸣声。就像在钢琴上，在钢琴低一些地方（左手边）的键演奏更低的音，而在钢琴高一些地方（右手边）的键演奏更高的音。

en: It turns out that the C of the 4th octave (C in English notation) is identified by the number 60. `play 60` therefore plays the C of the 4th octave. To play the next piano key to the right, you have to add 1 to 60 and then type `play 61`, which in this case is the black key of the C sharp. To play the D, the next key to the right, `play 62`.
zh-CN: 结果就是第四个八度的C用数字60来表示。“play 60”也就因此是演奏第四个八度的C。要弹右边紧接着的钢琴键，你必须往60上加个1然后敲出“play 61”，它在这里是黑键C升。要弹D，即右边一个键，“play 62”。

en: *Don't worry* if this means nothing to you - it didn't to me when I first started. All that matters right now is that you know that *low numbers make lower beeps* and *high numbers make higher beeps*.
zh-CN: 如果这对你来说难以理解——我一开始也没弄清楚——*别担心*。现在最重要的是你要知道 *低的数字发出的蜂鸣音更低* 和 *高的数字发出的蜂鸣音更高 *。

en: Chords
zh-CN: 和弦

en: Playing a note is quite fun, but playing many at the same time can be even better. Try it:
zh-CN: 演奏单个音符很有趣吧，但如果能同时演奏多个音符的话，那就更有趣了，试试下面的操作：

en: Jazzy! So, when you write multiple `play`s, they all play at the same time. Try it for yourself - which numbers sound good together? Which sound terrible? Experiment, explore and find out for yourself.
zh-CN: 棒极了!所以，当你写多个`play`的时候，它们都是同时播放的。自己试试吧——哪些数字放在一起听起来不错？哪些听起来糟糕？自己去尝试，去探索，去发现。

en: Melody
zh-CN: 旋律

en: So, playing notes and chords is fun - but how about a melody? What if you wanted to play one note after another and not at the same time? Well, that's easy, you just need to `sleep` between the notes:
zh-CN: 所以, 演奏音符与和弦是很有趣的——但是怎么演奏旋律呢？如果你想一个接一个的播放音符, 而不是在同一时间播放呢？那很简单, 你只需在音符之间`sleep`一下:

en: How lovely, a little arpeggio. So what does the `1` mean in `sleep 1`? Well it means the *duration of the sleep*. It actually means sleep for one beat, but for now we can think about it as sleeping for 1 second. So, what if we wanted to make our arpeggio a little faster? Well, we need to use shorter sleep values. What about a half i.e. `0.5`:
zh-CN: 多么可爱的一个琶音。那么`sleep 1`中的`1`意味着什么呢？这意味着*音符的持续时间*。它实际上意味着音符持续一个节拍，但现在我们可以把它想象为1秒后停止。那么，如果我们想让琶音快一点呢？我们需要使用较短的睡眠值。比如一半，即`0.5`：

en: Notice how it plays faster. Now, try for yourself, change the times - use different times and notes.
zh-CN: 注意它的播放速度变得有多快。现在，请你自己试试，改变一下时间——使用不同的时间和音符。

en: One thing to try is in-between notes such as `play 52.3` and `play 52.63`. There's absolutely no need to stick to standard whole notes. Play around and have fun.
zh-CN: 一件可以尝试的事情是带小数的音符，如`play 52.3`和`play 52.63`。完全没有必要拘泥于标准的整数音符。玩得开心。

en: Traditional Note Names
zh-CN: 传统音符名称

en: For those of you that already know some musical notation (don't worry if you don't - you don't need it to have fun) you might want to write a melody using note names such as C and F# rather than numbers. Sonic Pi has you covered. You can do the following:
zh-CN: 对于那些已经知道一些音乐记谱法的人（如果不知道也不用担心——并不需要你了解它），你可能想用诸如C和F#之类的音符名而不是数字来写一首旋律。Sonic Pi同样为你了提供解决办法。你可以做到以下几点：

en: Remember to put the colon `:` in front of your note name so that it goes pink. Also, you can specify the octave by adding a number after the note name:
zh-CN: 记住把冒号`:`放在你的音符前面，使它变成粉红色。此外，可以通过在音符名称之后添加数字来指定八度音阶：

en: If you want to make a note sharp, add an `s` after the note name such as `play :Fs3` and if you want to make a note flat, add a `b` such as `play :Eb3`.
zh-CN: 如果你想让一个音符变为升调，在这个音符名称后面加上一个`s`，比如`play:Fs3`，如果你想让一个音符变为降调，则加一个`b`，比如`play :Eb3`。

en: 2.2 Synth Options
zh-CN: 2.2 合成器选项

en: Synth Options: Amp and Pan
zh-CN: 合成器选项: Amp 和 Pan

en: As well as allowing you to control which note to play or which sample to trigger, Sonic Pi provides a whole range of options to craft and control the sounds. We'll be covering many of these in this tutorial and there's extensive documentation for each in the help system. However, for now we'll introduce two of the most useful: *amplitude* and *pan*. First, let's look at what options actually are.
zh-CN: 除了允许您控制播放哪个音符或触发哪个示例之外，Sonic Pi还提供了一系列选项来制作和控制声音。我们将在本教程中介绍其中的许多内容，并且在帮助系统中有详细的文档。不过，我们现在要介绍是最有用的两个选项：*声音增幅*和*左右声道平移*。首先，让我们看看这些选项到底是什么。

en: Options
zh-CN: 选项

en: Sonic Pi supports the notion of options (or opts for short) for its synths. Opts are controls you pass to `play` which modify and control aspects of the sound you hear. Each synth has its own set of opts for finely tuning its sound. However, there are common sets of opts shared by many sounds such as `amp:` and envelope opts (covered in another section).
zh-CN: Sonic Pi支持合成器选项的概念（以下简称选项）。选项是你传向`play`命令的控制，它可以修改和控制你听到的声音。每一个合成器都有自己的一套选项来精确调整它的声音。然而，有一些常见的设置选项是许多声音共有的，如`amp:`（增幅）和波封设置选项(将在另一节中介绍)。

en: Opts are passed to calls to `play` by using a comma `,` and then the name of the opt such as `amp:` (don't forget the colon `:`) and then a space and the value of the opt. For example:
zh-CN: 合成器选项通过逗号`,`传递给`play`调用，紧跟着的是选项的名称，例如`amp:`（不要忘记冒号`:` ），接着是空格和选项的值。举例如下：

en: (Note that `cheese:` isn't a valid opt, we're just using it as an example).
zh-CN: (请注意这里的`cheese:`并不是一个有效的选项，我们只是用它作为一个例子)。

en: You can pass multiple opts by separating them with a comma:
zh-CN: 你需要传递多个选项时，可以用逗号分隔：

en: The order of the opts doesn't matter, so the following is identical:
zh-CN: 选项的顺序是无关紧要的，因此以下内容相同:

en: Opts that aren't recognised by the synth are just ignored (like `cheese` and `beans` which are clearly ridiculous opt names!)
zh-CN: 不被合成器识别的选项会被忽略 (就像 `cheese`[奶酪] 和 `beans`[豌豆], 这显然只是些可笑的选项名称!)

en: If you accidentally use the same opt twice with different values, the last one wins. For example, `beans:` here will have the value 2 rather than 0.5:
zh-CN: 如果你意外地对同一个选项赋予两次不同的值，最后一次赋值将会被应用。下面的例子中，`beans:`的值将是2，而不是0.5 ：

en: Many things in Sonic Pi accept opts, so just spend a little time learning how to use them and you'll be set! Let's play with our first opt: `amp:`.
zh-CN: Sonic Pi 中的很多东西接受选项的控制，所以你只需花点时间去学习怎么使用它们，就能够设置好！让我们来玩一玩我们的第一个合成器选项：`amp:`.

en: Amplitude
zh-CN: 振幅

en: Amplitude is a computer representation of the loudness of a sound. A *high amplitude produces a loud sound* and a *low amplitude produces a quiet sound*. Just as Sonic Pi uses numbers to represent time and notes, it uses numbers to represent amplitude. An amplitude of 0 is silent (you'll hear nothing) whereas an amplitude of 1 is normal volume. You can even crank up the amplitude higher to 2, 10, 100. However, you should note that when the overall amplitude of all the sounds gets too high, Sonic Pi uses what's called a compressor to squash them all to make sure things aren't too loud for your ears. This can often make the sound muddy and strange. So try to use low amplitudes, i.e. in the range 0 to 0.5 to avoid compression.
zh-CN: 振幅是声音响度的计算机表示。*高振幅产生的声音大*和*低振幅产生的声音小*。就像Sonic Pi用数字来表示时间和音符一样，它也用数字来表示振幅。振幅为0就是静音(你什么也听不到)，而振幅为1是正常音量。你甚至可以把振幅调到2,10,100。然而，你应该注意，当所有声音的整体振幅变得过高时，Sonic Pi会使用所谓的压缩器来压缩它们，以确保传到你耳朵的声音不会太大。这往往会使声音变得浑浊和奇怪。所以尽量使用低振幅，即在0到0.5的范围内，以避免被压缩。

en: Amp it up
zh-CN: 放大它

en: To change the amplitude of a sound, you can use the `amp:` opt. For example, to play at half amplitude pass 0.5:
zh-CN: 要改变声音的振幅，你可以使用`amp:`选项。例如，赋值0.5，播放的振幅减半：

en: To play at double amplitude pass 2:
zh-CN: 赋值2，播放的增幅加倍：

en: The `amp:` opt only modifies the call to `play` it's associated with. So, in this example, the first call to play is at half volume and the second is back to the default (1):
zh-CN: `amp:` 选项只修改与之关联的`play`调用 。因此, 在本例中, 第一个play调用的是音量减半，第二个play则返回到默认音量(1):

en: Of course, you can use different `amp:` values for each call to play:
zh-CN: 当然，你也可以为每一个play的调用，使用不同的`amp:`值：

en: Panning
zh-CN: 声道平移

en: Another fun opt to use is `pan:` which controls the panning of a sound in stereo. Panning a sound to the left means that you hear it out of the left speaker, and panning it to the right means you hear it out of your right speaker. For our values, we use a -1 to represent fully left, 0 to represent center and 1 to represent fully right in the stereo field. Of course, we're free to use any value between -1 and 1 to control the exact positioning of our sound.
zh-CN: 另一个有趣的选项是`pan:`，它控制着立体声声音的平移。向左平移一个声音意味着你将从左边的扬声器中听到它，向右平移意味着你将从右边的扬声器中听到它。对于我们的设定，我们用-1表示完全左声道，0表示中心，1表示完全右声道。当然，我们可以随意使用-1到1之间的任何值来控制声音的精确位置。

en: Let's play a beep out of the left speaker:
zh-CN: 让我们从左扬声器中播放蜂鸣声:

en: Now, let's play it out of the right speaker:
zh-CN: 现在，让我们从右扬声器中播放：

en: Finally let's play it back out of the center of both (the default position):
zh-CN: 最后，让我们从两扬声器的中心(默认位置)播放出来:

en: Now, go and have fun changing the amplitude and panning of your sounds!
zh-CN: 现在，去享受改变振幅和平移声音的乐趣吧!

en: 2.3 Switching Synths
zh-CN: 2.3 开关合成器

en: Switching Synths
zh-CN: 开关合成器

en: So far we've had quite a lot of fun making beeps. However, you're probably starting to get bored of the basic beep noise. Is that all Sonic Pi has to offer? Surely there's more to live coding than just playing beeps? Yes there is, and in this section we'll explore some of the exciting range of sounds that Sonic Pi has to offer.
zh-CN: 到目前为止，我们已经做了很多有趣的蜂鸣声。然而，你可能开始对这基本的蜂鸣音感到厌烦。这就是Sonic Pi所能提供的一切吗？除了播放蜂鸣声之外，还有更多的东西吗？当然有啦，在这一节中，我们将探索Sonic Pi提供的超级厉害的的音色范围。

en: Sonic Pi has a number of different instruments it calls synths (which is *short for synthesisers*). Whereas samples represent pre-recorded sounds, synths are capable of generating new sounds depending on how you control them (which we'll explore later in this tutorial). Sonic Pi's synths are very powerful and expressive and you'll have a lot of fun exploring and playing with them. First, let's learn how to select the current synth to use.
zh-CN: Sonic Pi有一系列被称为synth的乐器，*这是合成器的英文简称*。比较之下，sample只是预先录制好的声音，但是synth能够根据你的控制，产生新的声音(我们将在本教程后面讨论)。Sonic Pi的合成器非常强大且富有表现力，你会有很多乐趣探索和发挥他们。首先，让我们学习如何选择当前要使用的synth。

en: Buzzy saws and prophets
zh-CN: Buzzy saws 和 prophets

en: A fun sound is the *saw wave* - let's give it a try:
zh-CN: 一个有趣的声音是*锯齿波* - 让我们尝试一下：

en: Let's try another sound - the *prophet*:
zh-CN: 让我们试试另一种声音 - *prophet*：

en: How about combining two sounds. First one after another:
zh-CN: 把两种声音结合起来怎么样，试试一个接一个播放：

en: Now multiple sounds at the same time (by not sleeping between successive calls to `play`):
zh-CN: 现在多个声响同时发声（但连续调用的“play”之间没有休停的代码）：

en: use_synth :tb303
    play 38
    use_synth :dsaw
    play 50
    use_synth :prophet
    play 57
zh-CN: use_synth :tb303
    play 38
    sleep 0.25
    use_synth :dsaw
    play 50
    use_synth :prophet
    play 57

en: Notice that the `use_synth` command only affects the following calls to `play`. Think of it like a *big switch* - new calls to `play` will play whatever synth it's currently pointing to. You can move the switch to a new synth with `use_synth`.
zh-CN: 请注意，`use_synth`命令只影响此后调用的`曲目(play+)`。你可以把它想象成一个*大开关*——新调用的`曲目(play+)`都将使用它当前指向的合成器。你可以使用`use_synth`将开关指向到一个新的合成器音效。

en: Discovering Synths
zh-CN: 探索合成器

en: To see which synths Sonic Pi has for you to play with take a look at the Synths option in the menu at the bottom of this help screen (between Examples & Fx). There are over 20 to choose from. Here are a few of my favourites:
zh-CN: 要查看Sonic Pi有哪些合成器可以让你玩，可以看看最左边的下拉菜单（ FX 之前）中的Synths选项。有超过20种合成器可供选择。以下是我的最爱：

en: Now play around with *switching synths during your music*. Have fun combining synths to make new sounds as well as using different synths for different sections of your music.
zh-CN: 现在*开关你音乐中的合成器(synths)*来玩一下吧。组合不同的合成器(synths)来创造不同的声音，并且在你的音乐的不同章节使用不同的合成器(synths)，玩的愉快。

en: 2.4 Duration with Envelopes
zh-CN: 2.4 波封(envelope)下的声音持续

en: Duration with Envelopes
zh-CN: 波封(envelope)下的声音持续

en: In an earlier section, we looked at how we can use the `sleep` command to control when to trigger our sounds. However, we haven't yet been able to control the duration of our sounds.
zh-CN: 在前面的一节中，我们看到了如何使用`sleep`命令来控制何时触发我们的声音。然而，我们还不知道如何来控制我们的声音的持续时间。

en: In order to give us a simple, yet powerful means of *controlling the duration* of our sounds, Sonic Pi provides the notion of an *ADSR amplitude envelope* (we'll cover what ADSR means later in this section). An amplitude envelope offers two useful aspects of control:
zh-CN: 为了给我们提供一种简单而强大的方法来*控制我们的声音的持续时间*，Sonic Pi提出了*ADSR振幅波封(ADSR amplitude envelope)*的概念(我们将在本节稍后介绍ADSR的含义)。振幅波封提供了两种实用性的控制:

en: control over the duration of a sound
zh-CN: 控制声音的持续时间

en: control over the amplitude of a sound
zh-CN: 控制声音的振幅

en: Duration
zh-CN: 持续时间(Duration)

en: The duration is the length the sound lasts for. A longer duration means that you hear the sound for longer. Sonic Pi's sounds all have a controllable amplitude envelope, and the total duration of that envelope is the duration of the sound. Therefore, by controlling the envelope you control the duration.
zh-CN: duration指的是声音持续的时长。一个更长的持续时间意味着你能听到这个声音更久。Sonic Pi中的声音都有一个可控制的振幅波封(amplitude envelope)，该波封(envelope)的总持续时间就是声音的持续时间。因此，通过控制波封(envelope)，你就可以控制音的持续时间(duration)。

en: The ADSR envelope not only controls duration, it also gives you *fine control over the amplitude of the sound*. All audible sounds start and end silent and contain some non-silent part in-between. Envelopes allow you to slide and hold the amplitude of non-silent parts of the sound. It's like giving someone instructions on how to turn up and down the volume of a guitar amplifier. For example you might ask someone to "start at silence, slowly move up to full volume, hold it for a bit, then quickly fall back to silence." Sonic Pi allows you to program exactly this behaviour with envelopes.
zh-CN: ADSR波封不仅控制音的持续时间，还给你*对声音振幅的良好控制*。所有可以听见的声音都由无声开始和结束，中间包含一些有声的部分。你可以用波封流畅提升然后保持有声部分声音的振幅。这就好像你在告诉一个人怎么拧吉他扩音器的音量旋钮。比如你可能会要求一个人“一开始要安静，慢慢推到最大音量，维持一会，然后迅速变回无声。” Sonic Pi 便可让你利用波封把这个命令精确编码出来。

en: Just to recap, as we have seen before, an amplitude of 0 is silence and an amplitude of 1 is normal volume.
zh-CN: 简单来讲，正如我们之前看到的，振幅(amplitude)为0表示静音，振幅(amplitude)为1表示正常音量。

en: Now, let us look at each of the parts of the envelopes in turn.
zh-CN: 现在，让我们来一个一个看一下波封(envelopes)中的每个部分。

en: Release Phase
zh-CN: 声音释放阶段

en: The only part of the envelope that's used by default is the release time. This is the time it takes for the synth's sound to fade out. All synths have a release time of 1 which means that by default they have a duration of 1 beat (which at the default BPM of 60 is 1 second):
zh-CN: 波封唯一一个初始的参数就是释音时间（Release Time)。它是声音淡出所需要的时间。所有合成音释音时间的初始参数都是“1”， 这指示着它会用一拍的时间淡出（初始的BPM是60）：

en: The note will be audible for 1 second. Go ahead and time it :-) This is short hand for the longer more explicit version:
zh-CN: 这音符会播一秒钟。计时一下吧。 :-) 这是缩写的；比较完整的写法是：

en: Notice how this sounds exactly the same (the sound lasts for one second). However, it's now very easy to change the duration by modifying the value of the `release:` opt:
zh-CN: 注意这个声音和之前是完全一样的（都持续了一分钟）。然而现在通过改变“释放（release)”来改变声音的长短是非常容易的。选择：

en: We can make the synth sound for a very short amount of time by using a very small release time:
zh-CN: 我们可以通过一个非常小的释放时间来制造一个非常短的合成器声音：

en: The duration of the release of the sound is called the *release phase* and by default is a linear transition (i.e. a straight line). The following diagram illustrates this transition:
zh-CN: 释放所需的时间被称为“释放阶段”，它的初始设置是一个一次函数（直线）。下面是图片解释：

en: The vertical line at the far left of the diagram shows that the sound starts at 0 amplitude, but goes up to full amplitude immediately (this is the attack phase which we'll cover next). Once at full amplitude it then moves in a straight line down to zero taking the amount of time specified by `release:`. *Longer release times produce longer synth fade outs.*
zh-CN: 图表最左边的直立线显示，声音从0波幅开始，立即升到满波幅（这是接下来介绍的起音阶段）。达到满波幅后，声音会以 `release: ` 指定的时间（释放时间）内，沿着直线下降到0。*施放时间越长，合成器淡出的时间会越长*

en: You can therefore change the duration of your sound by changing the release time. Have a play adding release times to your music.
zh-CN: 因此，改释放时间，就可以换声音的持续时间。试一下在你的音乐中添加施放时间吧。

en: Attack Phase
zh-CN: 起音阶段

en: By default, the *attack phase* is 0 for all synths which means they move from 0 amplitude to 1 immediately. This gives the synth an initial percussive sound. However, you may wish to fade your sound in. This can be achieved with the `attack:` opt. Try fading in some sounds:
zh-CN: 默认的起音时间时0，代表波幅会从0立即升到1，声音像打鼓一样。但你可能要让声音淡入。如果要这样，你可以用 `attack: ` 的选定。试一下把这些声音淡入一下：

en: You may use multiple opts at the same time. For example for a short attack and a long release try:
zh-CN: 你可以同时用几个选项来修改声音。例如，如果要短的起音和长的释放音，可以用：

en: This short attack and long release envelope is illustrated in the following diagram:
zh-CN: 下图说明了这种起音短暂而释音绵长的波封：

en: Of course, you may switch things around. Try a long attack and a short release:
zh-CN: 当然，也可以把起音和释放时间互换。试一下较长的起音时间和较短的释放时间：

en: Finally, you can also have both short attack and release times for shorter sounds.
zh-CN: 最后，如果要比较短的声音，可以用短的起音和释放时间。

en: Sustain Phase
zh-CN: 维持阶段

en: In addition to specifying attack and release times, you may also specify a sustain time to control the *sustain phase*. This is the time for which the sound is maintained at full amplitude between the attack and release phases.
zh-CN: 除了指定起音和释放时间之外，您还可以指定一个维持时间来控制“维持阶段”。 即声音在起音和释放阶段之间保持最大振幅的时间。

en: The sustain time is useful for important sounds you wish to give full presence in the mix before entering an optional release phase. Of course, it's totally valid to set both the `attack:` and `release:` opts to 0 and just use the sustain to have absolutely no fade in or fade out to the sound. However, be warned, a release of 0 can produce clicks in the audio and it's often better to use a very small value such as 0.2.
zh-CN: 在进入可选的释放阶段之前，延音时间对于希望在混音中充分体现的重要声音很有用。当然，将“ attack：”和“ release：”选项都设置为0是完全有效的，只是使用延音绝对不会使声音淡入或淡出。但是请注意，释放0会产生音频的喀哒声，通常最好使用很小的值，例如0.2。

en: Decay Phase
zh-CN: 衰减阶段

en: For an extra level of control, you can also specify a decay time. This is a phase of the envelope that fits between the attack and sustain phases and specifies a time where the amplitude will drop from the `attack_level:` to the `decay_level:` (which unless you explicitly set it will be set to the `sustain_level:`). By default, the `decay:` opt is 0 and both the attack and sustain levels are 1 so you'll need to specify them for the decay time to have any effect:
zh-CN: 对于更准确的控制，你也可以指定一个衰减时间(decay time)。这是波封在起音(attack)和延持(sustain)之间的一个阶段，振幅将从起音音幅“attack_level:” 下降至衰减音幅“decay_level:” （除非你明确指定它，否则将会被设置为 “sustain_level:”）。默认状态下，“decay:” 选项值为0，起音和持续时间的值都为1，所以为了让衰减时间生效，你需要去指定它们的值：

en: Decay Level
zh-CN: 衰减阶段

en: One last trick is that although the `decay_level:` opt defaults to be the same value as `sustain_level:` you can explicitly set them to different values for full control over the envelope. This allows you to to create envelopes such as the following:
zh-CN: 最后一个技巧：尽管衰减音幅“decay_level:”选项默认值和延持音幅“sustain_level:”一样，你也可以把它们明确设置为不同的值用以全方面地控制波封。这意味着你可以做出下面这样的波封：

en: It's also possible to set the `decay_level:` to be higher than `sustain_level:`:
zh-CN: 将 `decay_level:` 设置得比 `sustain_level:` 高也是可能的：

en: ADSR Envelopes
zh-CN: ADSR 波封

en: So to summarise, Sonic Pi's ADSR envelopes have the following phases:
zh-CN: 所以小结一下，Sonic Pi的ADSR波封有以下阶段：

en: *attack* - time from 0 amplitude to the `attack_level`,
zh-CN: * attack *-从0振幅到`attack_level`的时间，

en: *decay* - time to move amplitude from `attack_level` to `decay_level`,
zh-CN: * decay *-将幅度从“ attack_level”移到“ decay_level”的时间，

en: *sustain* - time to move the amplitude from `decay_level` to `sustain_level`,
zh-CN: * sustain *-将幅度从“ decay_level”移到“ sustain_level”的时间，

en: *release* - time to move amplitude from `sustain_level` to 0
zh-CN: *release*-将幅度从“ sustain_level”移至0的时间

en: It's important to note that the duration of a sound is the summation of the times of each of these phases. Therefore the following sound will have a duration of 0.5 + 1 + 2 + 0.5 = 4 beats:
zh-CN: 需要注意的是，声音的持续时间是每个阶段时间的总和。因此，以下声音的持续时间为 0.5 + 1 + 2 + 0.5 = 4 拍：

en: Now go and have a play adding envelopes to your sounds...
zh-CN: 现在动手拿你的声音耍耍波封...

en: 3 Samples
zh-CN: 3个样品

en: Samples
zh-CN: 采样器

en: Another great way to develop your music is to use pre-recorded sounds. In great hip-hop tradition, we call these pre-recorded sounds *samples*. So, if you take a microphone outside, go and record the gentle sound of rain hitting canvas, you've just created a sample.
zh-CN: 发展音乐的另一种好方法是使用预先录制的声音。在伟大的嘻哈传统中，我们将这些预先录制的声音称为“样本”。因此，如果您将麦克风带到室外，然后去录制雨水轻拂帆布的声音，那么您就创建了一个样本。

en: Sonic Pi lets you do lots of fun things with samples. Not only does it ship with 130 public domain samples ready for you to jam with, it lets you play and manipulate your own. Let's get to it...
zh-CN: Sonic Pi使您可以通过样本做很多有趣的事情。它不仅提供130个公共领域样本供您使用，还可以播放和操纵自己的样本。让我们开始吧...

en: 3.1 Triggering Samples
zh-CN: 3.1 触发示例

en: Triggering Samples
zh-CN: 触发示例

en: Playing beeps is only the beginning. Something that's a lot of fun is triggering pre-recorded samples. Try it:
zh-CN: 发出哔声仅仅是开始。更有趣的是触发预先保存的样本。试试吧：

en: Sonic Pi includes many samples for you to play with. You can use them just like you use the `play` command. To play multiple samples and notes just write them one after another:
zh-CN: Sonic Pi包含许多示例供您使用。您可以像使用play命令一样使用它们。要播放多个样本和音符，只需一个接一个地写它们：

en: If you want to space them out in time, use the `sleep` command:
zh-CN: 如果您想及时地将它们间隔开，请使用`sleep`命令：

en: Notice how Sonic Pi doesn't wait for a sound to finish before starting the next sound. The `sleep` command only describes the separation of the *triggering* of the sounds. This allows you to easily layer sounds together creating interesting overlap effects.
zh-CN: 请注意，Sonic Pi如何在开始下一个声音之前不等待声音结束。睡眠命令`sleep`仅描述声音的*触发*分离。这使您可以轻松地将声音叠加在一起，创建有趣的重叠效果。

en: Discovering Samples
zh-CN: 探索示例

en: There are two ways to discover the range of samples provided in Sonic Pi. First, you can use this help system. Click on Samples in the menu at the bottom of this help screen, choose your category and then you'll see a list of available sounds.
zh-CN: 有两种方法可以发现Sonic Pi中提供的样本范围。首先，您可以使用此帮助系统。单击窗口底部菜单，选择"示例"，再选择一个分类，您会看到可用声音的列表。

en: Alternatively you can use the *auto-completion system*. Simply type the start of a sample group such as: `sample :ambi_` and you'll see a drop-down of sample names appear for you to select. Try the following category prefixes:
zh-CN: 或者，您可以使用*自动补全系统*。只需输入示例组的开头，例如：`sample：ambi_`，您会看到一个下拉的示例名称供您选择。尝试以下类别前缀：

en: Now start mixing samples into your compositions!
zh-CN: 现在开始将示例混合到您的作品中！

en: 3.2 Sample Parameters
zh-CN: 3.2 示例参数

en: Sample Parameters: Amp and Pan
zh-CN: 示例参数：放大器和平移

en: As we saw with synths, we can easily control our sounds with parameters. Samples support exactly the same parameterisation mechanism. Let's revisit our friends `amp:` and `pan:`.
zh-CN: 正如我们在合成器上看到的那样，我们可以轻松地通过参数控制声音。示例支持完全相同的参数化机制。让我们重温我们的朋友“ amp：”和“ pan：”。

en: Amping samples
zh-CN: 激爽示例

en: You can change the amplitude of samples with exactly the same approach you used for synths:
zh-CN: 您可以使用与合成器完全相同的方法来更改样本的幅度：

en: Panning samples
zh-CN: 平移样本

en: We're also able to use the `pan:` parameter on samples. For example, here's how we'd play the amen break in the left ear and then half way through play it again through the right ear:
zh-CN: 我们还可以在样本上使用` pan:`参数。例如，以下是我们先给左耳演奏the amen break，然后再演奏进行到一半时通过右耳再次演奏的方式：

en: Note that 0.877 is half the duration of the `:loop_amen` sample in seconds.
zh-CN: 注意0.877（以秒为单位）是`：loop_amen`采样持续时间的一半。

en: Finally, note that if you set some synth defaults with `use_synth_defaults` (which we will discuss later), these will be ignored by `sample`.
zh-CN: 请注意，最后如果您使用`use_synth_defaults`设置了一些合成器默认值（我们将在后面讨论），则它们将被`sample`忽略。

en: 3.3 Stretching Samples
zh-CN: 3.3 拉伸示例

en: Stretching Samples
zh-CN: 拉伸示例

en: Now that we can play a variety of synths and samples to create some music, it's time to learn how to modify both the synths and samples to make the music even more unique and interesting. First, let's explore the ability to *stretch* and *squash* samples.
zh-CN: 现在我们可以演奏各种合成器和示例来创建音乐，现在该学习如何修改合成器和示例以使音乐更加独特和有趣。首先，让我们探索“拉伸”和“挤压”示例的能力。

en: Sample Representation
zh-CN: 示例表示

en: Samples are pre-recorded sounds stored as numbers which represent how to move the speaker cone to reproduce the sound. The speaker cone can move in and out, and so the numbers just need to represent how far in and out the cone needs to be for each moment in time. To be able to faithfully reproduce a recorded sound the sample typically needs to store many thousands of numbers per second! Sonic Pi takes this list of numbers and feeds them at the right speed to move your computer's speaker in and out in just the right way to reproduce the sound. However, it's also fun to change the speed with which the numbers are fed to the speaker to change the sound.
zh-CN: 样本是预先录制的声音，存储为数字，代表如何移动扬声器音频以再现声音。扬声器音频可以移入和移出，因此数字只需要表示每个时间锥入和移出圆锥的距离。为了能够忠实地再现录制的声音，样本通常需要每秒存储数千个数字！ Sonic Pi会获取此数字列表，并以正确的速度馈送它们，从而以正确的方式移入和移出计算机扬声器，以再现声音。但是，改变将数字馈送到扬声器以改变声音的速度也很有趣。

en: Changing Rate
zh-CN: 变化率

en: Let's play with one of the ambient sounds: `:ambi_choir`. To play it with the default rate, you can pass a `rate:` opt to `sample`:
zh-CN: 让我们播放一种环境声音：`：ambi_choir`。要使用默认速率播放，您可以将“ rate：”选项传递给“ sample”：

en: This plays it at normal rate (1), so nothing special yet. However, we're free to change that number to something else. How about `0.5`:
zh-CN: 它以正常速率（1）播放，因此没有什么特别的。但是我们可以自由地将该数字更改为其他数字，例如 0.5呢：

en: Woah! What's going on here? Well, two things. Firstly, the sample takes twice as long to play, secondly the sound is an octave lower. Let's explore these things in a little more detail.
zh-CN: 哇！这里发生了什么？好吧，两件事。首先，示例的播放时间是其两倍，其次声音降低了八度。让我们更详细地探讨这些事情。

en: Let's stretch
zh-CN: 让我们伸展一下

en: A sample that's fun to stretch and compress is the Amen Break. At normal rate, we might imagine throwing it into a *drum 'n' bass* track:
zh-CN: 一个可以愉快的拉伸和压缩的样本是Amen Break。以正常的速度，我们可能会想象将其放入一个* drum'n'bass *音轨中：

en: However by changing the rate we can switch up genres. Try half speed for *old school hip-hop*:
zh-CN: 但是，通过更改速率，我们可以切换流派。为旧式嘻哈音乐尝试一半速度：

en: If we speed it up, we enter *jungle* territory:
zh-CN: 如果加快速度，则输入* jungle *：

en: Now for our final party trick - let's see what happens if we use a negative rate:
zh-CN: 现在是我们最后的最后的花招-让我们看看如果使用负速率会发生什么：

en: A Simple Explanation of Sample Rate
zh-CN: 采样率的简单解释

en: A useful way to think of samples is as springs. Playback rate is like squashing and stretching the spring. If you play the sample at rate 2, you're *squashing the spring* to half its normal length. The sample therefore takes half the amount of time to play as it's shorter. If you play the sample at half rate, you're *stretching the spring* to double its length. The sample therefore takes twice the amount of time to play as it's longer. The more you squash (higher rate), the shorter it gets, the more you stretch (lower rate), the longer it gets.
zh-CN: 想到示例的一种有用方法是弹簧。播放速度就像挤压和拉伸弹簧一样。如果以速率2播放示例，则将弹簧压缩为正常长度的一半。因此，采样时间越短，其播放时间就减少一半。如果您以一半的速率播放示例，那么您将“拉伸弹簧”以使其长度加倍。因此，采样时间越长，其播放时间就增加一倍。压榨越多（速率越高），它越短，拉伸越多（速率越低），它就越长。

en: Compressing a spring increases its density (the number of coils per cm) - this is similar to the sample sounding *higher pitched*. Stretching the spring decreases its density and is similar to the sound having a *lower pitch*.
zh-CN: 压缩弹簧会增加其密度（每厘米的线圈数量） - 这与示例高音的声响[高音]类似。拉伸弹簧会降低其密度，类似于具有 [低音] 的声音。

en: The Maths Behind Sample Rate
zh-CN: 采样率背后的数学

en: (This section is provided for those that are interested in the details. Please feel free to skip it...)
zh-CN: （本节是为那些对细节感兴趣的人提供的。请随时跳过...）

en: As we saw above, a sample is represented by a big long list of numbers representing where the speaker should be through time. We can take this list of numbers and use it to draw a graph which would look similar to this:
zh-CN: 正如我们在上面看到的，示例由一长串长长的数字表示，这些数字代表播放器随时间推移，应该在的位置。我们可以使用这串数字来绘制一个像这样的图：

en: You might have seen pictures like this before. It's called the *waveform* of a sample. It's just a graph of numbers. Typically a waveform like this will have 44100 points of data per second (this is due to the Nyquist-Shannon sampling theorem). So, if the sample lasts for 2 seconds, the waveform will be represented by 88200 numbers which we would feed to the speaker at a rate of 44100 points per second. Of course, we could feed it at double rate which would be 88200 points per second. This would therefore take only 1 second to play back. We could also play it back at half rate which would be 22050 points per second taking 4 seconds to play back.
zh-CN: 您可能以前看过这样的图。它叫做样本的*波形*。它实际上是由一堆数字组成的。通常，这样的波形每秒将有44100个数据点（这是由于Nyquist-Shannon采样定理所致）。因此，如果采样持续2秒钟，则波形将由88200个数字表示，我们将以每秒44100点的速度将其馈送到扬声器。当然，我们可以以每秒88200点的双倍速率馈送。这样的话就只需要1秒钟即可播放完同样一段采样。我们也可以让播放的速率降低一半，即每秒22050点，需要4秒钟才能播放完毕。

en: The duration of the sample is affected by the playback rate:
zh-CN: 示例的持续时间受播放速率的影响：

en: Doubling the playback rate halves the playback time,
zh-CN: 播放速率加倍可将播放时间减半，

en: Halving the playback rate doubles the playback time,
zh-CN: 将播放速率减半会使播放时间加倍，

en: Using a playback rate of one fourth quadruples the playback time,
zh-CN: 使用四分之一的播放速度是播放时间的四倍，

en: Using a playback rate of 1/10 makes playback last 10 times longer.
zh-CN: 使用1/10的播放速率可使播放时间延长10倍。

en: We can represent this with the formula:
zh-CN: 我们可以用以下公式表示：

en: Changing the playback rate also affects the pitch of the sample. The frequency or pitch of a waveform is determined by how fast it moves up and down. Our brains somehow turn fast movement of speakers into high notes and slow movement of speakers into low notes. This is why you can sometimes even see a big bass speaker move as it pumps out super low bass - it's actually moving a lot slower in and out than a speaker producing higher notes.
zh-CN: 更改播放速率也会影响采样的音高。波形的频率或基音由其上下移动的速度决定。我们的大脑不知怎么地把说话人的快速移动变成高音，把说话人的慢速移动变成低音。这就是为什么有时你甚至可以看到一个大低音扬声器，因为它泵出超低音-它实际上移动慢得多，进出比一个扬声器产生更高的音符。

en: If you take a waveform and squash it it will move up and down more times per second. This will make it sound higher pitched. It turns out that doubling the amount of up and down movements (oscillations) doubles the frequency. So, *playing your sample at double rate will double the frequency you hear it*. Also, *halving the rate will halve the frequency*. Other rates will affect the frequency accordingly.
zh-CN: 如果您将一个波形压缩，它在每秒会上下移动更多地次数。这使得它听起来音调更高。让波形上下振动的总数加速一倍可以让频率翻倍。所以，*使用双倍的速率播放您的示例，您将听到双倍的频率*。同样，*使用一半的速率将会降低一半的频率*。其它速率也会相应地影响频率。

en: 3.4 Enveloped Samples
zh-CN: 3.4 波封设置后样本(Enveloped samples)

en: Enveloped Samples
zh-CN: 波封设置后的样本(Enveloped Samples)

en: It is also possible to modify the *duration* and *amplitude* of a sample using an ADSR envelope. However, this works slightly differently to the ADSR envelope available on synths. Sample envelopes only allow you to reduce the amplitude and duration of a sample - and never to increase it. The sample will stop when either the sample has finished playing or the envelope has completed - whichever is first. So, if you use a very long `release:`, it won't extend the duration of the sample.
zh-CN: 用 ADSR 波封去调整样本的 *持续时间(duration)* 和 *振幅(amplitude)* 也是同样可能的。然而，这会和运用在合成音上的 ADSR 波封有些许不同。样本波封只允许你减少样本的振幅和持续时间——而永远无法增加。这段样本将会在样本本身播放结束或波封完成的时候结束——这取决于哪种情况先发生。所以说，如果你选用一个很长的“release:”，也并不会增加样本的持续时间。

en: Amen Envelopes
zh-CN: Amen 波封

en: Let's return to our trusty friend the Amen Break:
zh-CN: 让我们回到我们信赖的伙伴Amen Break：

en: With no opts, we hear the full sample at full amplitude. If we want to fade this in over 1 second we can use the `attack:` param:
zh-CN: 不做设置，我们听到全振幅下完整的样本。如果我们想让它1秒钟内淡入，我们用“attack:”参数：

en: For a shorter fade in, choose a shorter attack value:
zh-CN: 至于短些的淡入，选一个短些的起音参数值：

en: Auto Sustain
zh-CN: 自动延音

en: Where the ADSR envelope's behaviour differs from the standard synth envelope is in the *sustain* value. In the standard synth envelope, the sustain defaulted to 0 unless you set it manually. With samples, the sustain value defaults to an *automagical* value - the time left to play the rest of the sample. This is why we hear the full sample when we pass no defaults. If the attack, decay, sustain and release values were all 0 we'd never hear a peep. Sonic Pi therefore calculates how long the sample is, deducts any attack, decay and release times and uses the result as your sustain time. If the attack, decay and release values add up to more than the duration of the sample, the sustain is simply set to 0.
zh-CN: ADSR 波封的表现和标准合成音波封不同之处在于*延持(sustain)*值。在标准合成音波封里，延持默认值是0，除非你手动设置。对于样本，延持值默认为*魔力自动(automagical)*值——余下的演奏样本剩余部分的时间。这就是为什么当我们没有输入任何首选项我们还能听到完整样本。要是起音、衰减、延持和释音的值都是0，那永远只会是一片死寂。所以Sonic Pi计算样本长度，推断出一些起音、衰退和释音，用这个结果作延持时间。如果起音、衰退和释音的值加起来总和多于样本持续时间，延持(sustain)会被简单设为0.

en: Fade Outs
zh-CN: 淡出

en: To explore this, let's consider our Amen break in more detail. If we ask Sonic Pi how long the sample is:
zh-CN: 探索一波这个选项，我们来细致斟酌一下我们的Amen break。如果我们问Sonic Pi这个样本有多长：

en: It will print out `1.753310657596372` which is the length of the sample in seconds. Let's just round that to `1.75` for convenience here. Now, if we set the release to `0.75`, something surprising will happen:
zh-CN: 它会输出“1.753310657596372”，也就是以秒为单位的样本长度。这里为了方便我们姑且把它约为1.75。好，如果我们把释音设置成“0.75”，惊人的事情会发生：

en: It will play the first second of the sample at full amplitude before then fading out over a period of 0.75 seconds. This is the *auto sustain* in action. By default, the release always works from the end of the sample. If our sample was 10.75 seconds long, it would play the first 10 seconds at full amplitude before fading out over 0.75s.
zh-CN: 这行代码会以全振幅演奏样本的第一秒，而后在0.75秒内淡出。这是*自动延持(auto sustain)*的实践。初始状态下，释音通常从样本的结尾生效。如果我们的样本时长为10.75秒，程序会以全振幅演奏前10秒，而后在0.75秒内淡出。

en: Remember: by default, `release:` fades out at the end of a sample.
zh-CN: 记住：初始状态下，“release:”在样本结尾淡出。

en: Fade In and Out
zh-CN: 淡入和淡出

en: We can use both `attack:` and `release:` together with the auto sustain behaviour to fade both in and out over the duration of the sample:
zh-CN: 我们可以同时用“attack:”和“release:”这两个参数和自动延持行为一起在样本持续演奏时淡入和淡出：

en: As the full duration of the sample is 1.75s and our attack and release phases add up to 1.5s, the sustain is automatically set to 0.25s. This allows us to easily fade the sample in and out.
zh-CN: 采样整个有1.75秒长，我们的起音和释音阶段加起来有1.5秒长，延持就因此自动设置为0.25秒长。这样我们就可以轻松的让采样样本淡入和淡出。

en: Explicit sustain
zh-CN: 明确的sustain

en: We can easily get back to our normal synth ADSR behaviour by manually setting `sustain:` to a value such as 0:
zh-CN: 我们可以很简单的把synth的ADSR模式调回原样，只需要手动把`sustain:`设置为0：

en: Now, our sample only plays for 0.75 seconds in total. With the default for `attack:` and `decay:` at 0, the sample jumps straight to full amplitude, sustains there for 0s then releases back down to 0 amplitude over the release period - 0.75s.
zh-CN: 现在我们的样本总共只有区区0.75秒长了。因为`attack:`和`decay:`的值都默认为0，这个样本会直接跳到最大响度，在那里毫不停留，然后在0.75秒内迅速释音到0响度。

en: Percussive cymbals
zh-CN: 打击乐锣

en: We can use this behaviour to good effect to turn longer sounding samples into shorter, more percussive versions. Consider the sample `:drum_cymbal_open`:
zh-CN: 我们可以好好利用前述的特性，将时间长的采样变得更短，更有打击感。可以尝试使用采样 `:drum_cymbal_open`:

en: sample :drum_cymbal_open
zh-CN: 样本：鼓_镲片_开放

en: You can hear the cymbal sound ringing out over a period of time. However, we can use our envelope to make it more percussive:
zh-CN: 可以听到镲片会持续震动一段时间。我们可以通过波封改变声音：

en: You can then emulate hitting the cymbal and then dampening it by increasing the sustain period:
zh-CN: 然后你可以模拟击打铙钹，并且通过增加sustain的时长来抑制它的效果：

en: sample :drum_cymbal_open, attack: 0.01, sustain: 0.3, release: 0.1
zh-CN: 样本 ：drum_cymbal_open，起音：0.01, 延音：0.3，释放：0.1

en: Now go and have fun putting envelopes over the samples. Try changing the rate too for really interesting results.
zh-CN: 那就去享受把波封用在样本上的乐趣吧。为了得到更有趣的结果，你可以试着改变速率。

en: 3.5 Partial Samples
zh-CN: 3.5 部分样本

en: Partial Samples
zh-CN: 部分样本

en: This section will conclude our exploration of Sonic Pi's sample player. Let's do a quick recap. So far we've looked at how we can trigger samples:
zh-CN: 这一节我们将结束对Sonic Pi'样本播放器的探索。让我们快速回顾一下。到目前为止，我们已经了解了如何触发样本：

en: We then looked at how we can change the rate of samples such as playing them at half speed:
zh-CN: 然后我们研究了如何改变样本的速率，比如以半速播放：

en: Next, we looked at how we could fade a sample in (let's do it at half speed):
zh-CN: 接下来，我们看看如何淡入一个样本(我们以半速来做)：

en: sample :loop_amen, rate: 0.5, attack: 1
zh-CN: 样本：loop_amen，速率：0.5，起音：1

en: We also looked at how we could use the start of a sample percussively by giving `sustain:` an explicit value and setting both the attack and release to be short values:
zh-CN: 我们还研究了如何通过给出一个显式的“延音”值并将起音和释音设置为短值，来打击振动地使用样本的开始：

en: sample :loop_amen, rate: 2, attack: 0.01, sustain: 0, release: 0.35
zh-CN: 样本：loop_amen，速率：2，起音：0.01，延音：0，释音：0.35

en: However, wouldn't it be nice if we didn't have to always start at the beginning of the sample? Wouldn't it also be nice if we didn't have to always finish at the end of the sample?
zh-CN: 但是，如果我们能不用总是从样本的开始来作为开端，不会很好吗？如果我们能不必总是在样本的末尾结束，那岂不也很好？

en: Choosing a starting point
zh-CN: 选择起点

en: It is possible to choose an arbitrary starting point in the sample as a value between 0 and 1 where 0 is the start of the sample, 1 is the end and 0.5 is half way through the sample. Let's try playing only the last half of the amen break:
zh-CN: 可以在样本中选择0到1之间的任意起点，其中0是样本的起点，1是终点，0.5是样本的一半。我们来试着只打amen的后半段：

en: sample :loop_amen, start: 0.5
zh-CN: 样本：loop_amen，起始值：0.5

en: How about the last quarter of the sample:
zh-CN: 关于最后1 / 4的样本：

en: sample :loop_amen, start: 0.75
zh-CN: 样本：loop_amen，起始值：0.75

en: Choosing a finish point
zh-CN: 选择终点

en: Similarly, it is possible to choose an arbitrary finish point in the sample as a value between 0 and 1. Let's finish the amen break half way through:
zh-CN: 类似地，也可以在样本中选择0到1之间的任意结束点。让我们完成amen突破一半：

en: sample :loop_amen, finish: 0.5
zh-CN: 样本：loop_amen，结束：0.5

en: Specifying start and finish
zh-CN: 指定开始和结束位置

en: Of course, we can combine these two to play arbitrary segments of the audio file. How about only a small section in the middle:
zh-CN: 当然，我们可以结合这两个去播放音频文件的任意片段。中间的一小部分如何：

en: sample :loop_amen, start: 0.4, finish: 0.6
zh-CN: 样本：loop_amen，起始：0.4，结束：0.6

en: What happens if we choose a start position after the finish position?
zh-CN: 如果我们把起始位置放在在结束位置之后，会发生什么呢？

en: sample :loop_amen, start: 0.6, finish: 0.4
zh-CN: 样本：loop_amen，起始：0.6，结束：0.4

en: Cool! It plays it backwards!
zh-CN: 太棒了！它会回放！

en: Combining with rate
zh-CN: 与速率结合

en: We can combine this new ability to play arbitrary segments of audio with our friend `rate:`. For example, we can play a very small section of the middle of the amen break very slowly:
zh-CN: 我们可以将这种播放任意音频片段的新能力与我们的朋友`rate:`相结合。比如说，我们可以很慢地播放amen中间暂停的一小段：

en: Combining with envelopes
zh-CN: 与包络结合

en: Finally, we can combine all of this with our ADSR envelopes to produce interesting results:
zh-CN: 最后，我们可以将所有这些与我们的ADSR包络相结合，制作有趣的效果：

en: Now go and have a play mashing up samples with all of this fun stuff...
zh-CN: 马上来试一试将这些有趣的东西混合在一起的采样......

en: 3.6 External Samples
zh-CN: 3.6 外部采样

en: External Samples
zh-CN: 外部采样

en: Whilst the built-in samples can get you up and started quickly, you might wish to experiment with other recorded sounds in your music. Sonic Pi totally supports this. First though, let's have a quick discussion on the portability of your piece.
zh-CN: 虽然内置的采样可以让你快速上手，但你可能希望在你的音乐中尝试使用其他录制的声音。Sonic Pi 完全支持这一点。不过首先，需要先来讨论一下你的作品的便携性。

en: Portability
zh-CN: 便携性

en: When you compose your piece purely with built-in synths and samples, the code is all you need to faithfully reproduce your music. Think about that for a moment - that's amazing! A simple piece of text you can email around or stick in a [Gist](https://gist.github.com) represents everything you need to reproduce your sounds. That makes it *really easy to share* with your friends as they just need to get hold of the code.
zh-CN: 当你纯粹只用内置的合成器和采样来创作作品的时候，代码包括了忠实再现你的音乐的全部。想一想--这太神奇了! 你通过电子邮件或粘贴在[Gist](https://gist.github.com)中的一段简单文字，就包括你需要重现你的作品的一切。这样一来，你与朋友们可以*很容易分享*，因为他们只需要获得代码就可以了。

en: However, if you start using your own pre-recorded samples, you lose this portability. This is because to reproduce your music other people not only need your code, they need your samples too. This limits the ability for others to manipulate, mash-up and experiment with your work. Of course this shouldn't stop you from using your own samples, it's just something to consider.
zh-CN: 但是，如果你开始使用自己预先录制的采样，你就会失去这种便携性。这是因为要再现你的音乐，其他人不仅需要你的代码，还需要你的采样。这就限制了别人对你的作品进行操作、混搭和实验的能力。当然这不应该阻止你使用自己的采样，这只是需要考虑的问题。

en: Local Samples
zh-CN: 本地采样

en: # Raspberry Pi, Mac, Linux
    sample "/Users/sam/Desktop/my-sound.wav"
    # Windows
    sample "C:/Users/sam/Desktop/my-sound.wav"
zh-CN: # 树莓派，苹果系统，Linux系统
    sample "/Users/sam/Desktop/my-sound.wav"
    # WIndows系统
    sample "C:/Users/sam/Desktop/my-sound.wav"

en: Sonic Pi will automatically load and play the sample. You can also pass all the standard params you're used to passing `sample`:
zh-CN: Sonic Pi 将自动加载和播放样本。你还可以传递所有用于传递"`sample`的标准参数：

en: # Raspberry Pi, Mac, Linux
    sample "/Users/sam/Desktop/my-sound.wav", rate: 0.5, amp: 0.3
    # Windows
    sample "C:/Users/sam/Desktop/my-sound.wav", rate: 0.5, amp: 0.3
zh-CN: # 在Raspberry Pi, Mac, Linux中
    sample "/Users/sam/Desktop/my-sound.wav", rate: 0.5, amp: 0.3
    # 在Windows中
    sample "C:/Users/sam/Desktop/my-sound.wav", rate: 0.5, amp: 0.3

en: 3.7 Sample Packs
zh-CN: 3.7 采样包

en: Sample Packs
zh-CN: 采样包

en: **Note: this section of the tutorial covers the advanced topic of working with large directories of your own samples. This will be the case if you've downloaded or bought your own sample packs and wish to use them within Sonic Pi.**
zh-CN: **注意：这部分教程包含了关于处理大量自定义采样文件的操作，只有在你下载或购买了自己的采样包，并且想在Sonic Pi中使用的时候，才需要参考这部分内容。**

en: **Feel free to skip this if you're happy working with the built-in samples.**
zh-CN: **如果你用内置采样包就能玩得很开心，就跳过这部分教程吧。**

en: When working with large folders of external samples it can be cumbersome to have to type the whole path every time to trigger an individual sample.
zh-CN: 当你要大量使用外置采样文件的时候，每次都输入相应文件的完整路径会非常麻烦。

en: For example, say you have the following folder on your machine:
zh-CN: 例如你想在自己的机器上找到如下文件夹：

en: When we look inside that folder we find the following samples:
zh-CN: 我们打开这个文件夹后可以找到下面这些采样：

en: Typically in order to play the piano sample we can use the full path:
zh-CN: 要播放钢琴采样时，我们可以用完整的路径：

en: sample "/path/to/my/samples/120_Bb_piano1.wav"
zh-CN: 采样样本 "/path/to/my/samples/120_Bb_piano1.wav"

en: If we want to then play the guitar sample we can use its full path too:
zh-CN: 又或者如果我们要播放吉他采样，也可以用完整的路径：

en: sample "/path/to/my/samples/120_Bb_guit.wav"
zh-CN: 采样样本 "/path/to/my/samples/120_Bb_guit.wav"

en: However, both of these calls to sample requires us to *know* the names of the samples within our directory. What if we just want to listen to each sample in turn quickly?
zh-CN: 但是，使用这些采样需要我们事先*知道*我们目录中采样的名字。如果我们只是想快速地从头到尾听一遍每个采样，该怎么做呢？

en: Indexing Sample Packs
zh-CN: 索引采样包

en: If we want to play the first sample in a directory we just need to pass the directory's name to `sample` and the index `0` as follows:
zh-CN: 如果我们想播放一个目录下的第一个采样，只需要像这样，在'sample'后加上目录名和索引号'0' ：

en: sample "/path/to/my/samples/", 0
zh-CN: 采样样本 "/path/to/my/samples/", 0

en: We can even make a shortcut to our directory path using a variable:
zh-CN: 我们还可以利用变量来快速调用某个文件路径：

en: Now, if we want to play the second sample in our directory, we just need to add 1 to our index:
zh-CN: 如果我们想播放目录中的第二个采样，只需要在索引号后加1：

en: Notice that we no longer need to know the names of the samples in the directory - we just need to know the directory itself (or have a shortcut to it). If we ask for an index which is larger than the number of samples, it simply wraps round just like Rings. Therefore, whatever number we use we're guaranteed to get one of the samples in that directory.
zh-CN: 注意我们已经不需要知道目录中采样的文件名，只需要知道文件夹的路径（或者有一个指向它的快捷方式）。如果我们输入了一个比文件数目更大的索引号，它会又从头开始算起，就像ring列表一样。因此不管我们输入什么样的索引号，总能得到目录中的某个采样。

en: Filtering Sample Packs
zh-CN: 过滤采样包

en: Usually indexing is enough, but sometimes we need more power to sort and organise our samples. Luckily many sample packs add useful information in the filenames. Let's take another look at the sample file names in our directory:
zh-CN: 通常用索引就够了，但有时我们还需要更强大的方式来分类整理我们的采样文件。有很多采样包会在文件名中附带有用的信息，让我们再仔细看看目录中的采样文件名：

en: Notice that in these filenames we have quite a bit of information. Firstly, we have the BPM of the sample (beats per minute) at the start. So, the piano sample is at 120 BPM and our first three melodies are at 100 BPM. Also, our sample names contain the key. So the guitar sample is in Bb and the melodies are in A#. This information is very useful for mixing in these samples with our other code. For example, we know we can only play the piano sample with code that's in 120 BPM and in the key of Bb.
zh-CN: 可以看到这些文件名包含了不少信息。首先在开始处可以看到采样的BPM（每分钟节拍数）。所以钢琴采样的BPM是120，而我们前面的三段旋律BPM是100。还可以看到文件名标明了采样的调性。比如吉他采样是Bb调，而我们旋律是A#调。我们在代码中编入这些采样时，这些信息是很有用的。比如说，我们可以知道只能在BPM为120且调性为Bb的旋律中使用这个钢琴采样。

en: It turns out that we can use this particular naming convention of our sample sets in the code to help us filter out the ones we want. For example, if we're working at 120 BPM, we can filter down to all the samples that contain the string `"120"` with the following:
zh-CN: 实际上我们可以利用采样包的这个命名规则，在代码中过滤筛选出我们想要的采样。例如，如果我们当前的BPM是120，我们可以过滤出所有文件名中含有"120"的采样文件：

en: This will play us the first match. If we want the second match we just need to use the index:
zh-CN: 这样会播放第一个符合这个条件的采样。如果想用第二个符合条件的采样，只需要加入索引号：

en: We can even use multiple filters at the same time. For example, if we want a sample whose filename contains both the substrings `"120"` and `"A#"` we can find it easily with the following code:
zh-CN: 甚至还能同时使用多个过滤规则。例如，如果我们想要文件名同时包含了"120"和"A#"的采样，我们可以用下面的代码来过滤：

en: Finally, we're still free to add our usual opts to the call to `sample`:
zh-CN: 最后我们还是可以自由地加上sample常用的选项：

en: Sources
zh-CN: 采样来源

en: The sample filter pre-arg system understands two types of information: *sources* and *filters*. Sources are information used to create the list of potential candidates. A source can take two forms:
zh-CN: 采样过滤器的前置参数系统可以解析两种类型的信息：*采样来源（sources）*和*过滤选项（filters）*。采样来源信息可以用来产生一系列的备选采样，采样来源可以有两种形式：

en: `"/path/to/samples"` - a string representing a valid path to a directory
zh-CN: `"/path/to/samples"` - 代表采样文件路径的字符串

en: `"/path/to/samples/foo.wav"` - a string representing a valid path to a sample
zh-CN: `"/path/to/samples/foo.wav"` - 代表某个路径下的采样文件的字符串

en: For example, take a look at the following code:
zh-CN: 观察一下下面的代码：

en: Here, we're combining the contents of the samples within two directories and adding a specific sample. If `"/path/to/my/samples/"` contained 3 samples and `"/path/to/my/samples2/"` contained 12, we'd have 16 potential samples to index and filter (3 + 12 + 1).
zh-CN: 我们可以用这种方式把两个目录中包含的采样和另一个特定的采样都加入到备选列表中，如果`"/path/to/my/samples/"`中有3个采样， `"/path/to/my/samples2/"` 中有12个采样，那么我们的备选列表中就有3+12+1个采样，可以用前面讲过的索引和过滤器的方式来处理它们。

en: By default, only the sample files within a directory are gathered into the candidate list. Sometimes you might have a number of nested folders of samples you wish to search and filter within. You can therefore do a recursive search for all samples within all subfolders of a particular folder by adding `**` to the end of the path:
zh-CN: 默认情况只有直接包含在目录下面的采样文件会包含到列表中，但有时候你可能会想要搜索和过滤子文件夹中包含的采样文件，你可以在某个文件路径后加`**`来实现：

en: Take care though as searching through a very large set of folders may take a long time. However, the contents of all folder sources are cached, so the delay will only happen the first time.
zh-CN: 但是要注意，搜索大量的文件夹可能会耗费很长的时间。不过所有的采样来源会写入到缓存中，所有只有第一次搜索会耗时间。

en: Finally, note that the sources *must go first*. If no source is given, then the set of built-in samples will be selected as the default list of candidates to work with.
zh-CN: 最后需要注意的是采样来源的参数*要放在最前面*。如果没有设定来源，就会使用内置的采样库作为备选列表。

en: Filters
zh-CN: 过滤器

en: Once you have a list of candidates you may use the following filtering types to further reduce the selection:
zh-CN: 拥有一个备选列表后，你可以用下面的过滤类型进一步缩小选择范围：

en: `"foo"` Strings will filter on substring occurrence within file name (minus directory path and extension).
zh-CN: `"foo"`会过滤出文件名中含有对应字符串的采样（不包括文件路径和扩展名）。

en: `/fo[oO]/` Regular Expressions will filter on pattern matching of file name (minus directory path and extension).
zh-CN: `/fo[oO]/`正则表达式会过滤出匹配相应规则的文件名（不含文件路径和扩展名）。

en: `:foo` - Keywords will filter candidates on whether the keyword is a direct match of the filename (minus directory path and extension).
zh-CN: `:foo` 这个形式会过滤出完全匹配关键词的采样文件名（不含文件路径和扩展名）。

en: `1` - Numbers will select the candidate with that index (wrapping round like a ring if necessary).
zh-CN: `1`会以索引号形式在备选列表中选出相应的采样（采用ring的方式循环选择）。

en: For example, we can filter over all the samples in a directory containing the string `"foo"` and play the first matching sample at half speed:
zh-CN: 例如，我们可以从一个目录中包含的所有采样中过滤出文件名含有`"foo"`的采样，并播放第一个匹配的采样，用原来的一半速度：

en: See the help for `sample` for many detailed usage examples. Note that the ordering of the filters is honoured.
zh-CN: 具体的使用例子可以参考`sample`函数的文档，注意过滤器的顺序会影响结果。

en: Composites
zh-CN: 复合参数

en: Finally, you may use lists wherever you may place a source or filter. The list will be automatically flattened and the contents will be treated as regular sources and filters. Therefore the following calls to `sample` are semantically equivalent:
zh-CN: 采样来源和过滤器都可以用列表的形式来表示，列表会自动打散，里面的元素会像普通的采样来源和过滤器一样被读取，因此以下的几个`sample`例子表示的是同样的意思：

en: Wrapping Up
zh-CN: 小结

en: This was an advanced section for people that need real power to manipulate and use sample packs. If most of this section didn't make too much sense, don't worry. It's likely you don't need any of this functionality just yet. However, you'll know when you do need it and you can come back and re-read this when you start working with large directories of samples.
zh-CN: 这部分内容是给那些想要更有效地使用采样包的人参考的，如果你啥都看不明白也没关系，很可能你目前根本用不着这些内容。未来你有可能有需要，你可以重新回来看看这部分关于如何使用大量采样包的内容。

en: 4 Randomisation
zh-CN: 4 随机化

en: Randomisation
zh-CN: 随机化

en: A great way to add some interest into your music is using some random numbers. Sonic Pi has some great functionality for adding randomness to your music, but before we start we need to learn a shocking truth: in Sonic Pi *random is not truly random*. What on earth does this mean? Well, let's see.
zh-CN: 要让你的音乐变得更有趣，加入一些随机数是和好的办法。Sonic Pi有很多功能可以为你的音乐加入随机性，但开始之前我们要认清一个现实：Sonic Pi中*所有的随机并不是真的随机*！那到底是什么啊？让我们来看看。

en: Repeatability
zh-CN: 可再现性

en: A really useful random function is `rrand` which will give you a random value between two numbers - a *min* and a *max*. (`rrand` is short for ranged random). Let's try playing a random note:
zh-CN: `rrand`是一个很有用的随机函数，它会在两个数字之间随机生成一个数，即*上限*和*下限*，（`rrand`是"ranged random"的缩写）。试一下演奏一个随机音符：

en: Ooh, it played a random note. It played note `83.7527`. A nice random note between 50 and 95. Woah, wait, did I just predict the exact random note you got too? Something fishy is going on here. Try running the code again. What? It chose `83.7527` again? That can't be random!
zh-CN: 看，出来了一个随机的音，相应midi音符是`83.7527`，是介于50和95之间的随机数。但是等等，难道我能预测出你得到的随机数吗？这个事情很可疑。试试再运行一次这段代码。什么？又是`83.7527`？这不是随机数啊！

en: The answer is that it is not truly random, it's pseudo-random. Sonic Pi will give you random-like numbers in a repeatable manner. This is very useful for ensuring that the music you create on your machine sounds identical on everybody else's machine - even if you use some randomness in your composition.
zh-CN: 这问题的答案就是这不是真的随机数，是"伪随机"（pseudo-random）。Sonic Pi用了一种可以再现的方式，给了你一个看起来像随机数的数。这个机制可以保证你在自己机器上创作的音乐在别人的机器上听起来也是一样的，即使你在创作中加入了随机性。

en: Of course, in a given piece of music, if it 'randomly' chose `83.7527` every time, then it wouldn't be very interesting. However, it doesn't. Try the following:
zh-CN: 当然，在某段特定的音乐里，如果你的"随机数"每次都是`83.7527`，那肯定会很无聊。但实际上并不会。试试下面的代码：

en: Yes! It finally sounds random. Within a given *run* subsequent calls to random functions will return random values. However, the next run will produce exactly the same sequence of random values and sound exactly the same. It's as if all Sonic Pi code went back in time to exactly the same point every time the Run button was pressed. It's the Groundhog Day of music synthesis!
zh-CN: 对！这听起来很随机。在某次特定的*运行*中，先后使用随机函数得可以得到一系列随机数，但是下一次运行这段代码的时候，还会得到同样的一系列随机数，所以每次运行听起来都是一样的。就好像Sonic Pi每次运行都会回到你第一次按下"运行"按钮的那个时间点。去看看《今天暂时停止》（Groundhog Day, 1993）这部电影吧，这样的事情就发生在音乐合成中！

en: Haunted Bells
zh-CN: 连绵不绝的钟声（示例代码：Haunted Bells）

en: A lovely illustration of randomisation in action is the haunted bells example which loops the `:perc_bell` sample with a random rate and sleep time between bell sounds:
zh-CN: 示例代码中的haunted bells用非常可爱的方式演示了随机化，它用随机的采样率和间隔时间反复播放 `:perc_bell`这个采样：

en: Random cutoff
zh-CN: 随机截止频率

en: Another fun example of randomisation is to modify the cutoff of a synth randomly. A great synth to try this out on is the `:tb303` emulator:
zh-CN: 关于随机化另一个有趣的例子是随机设定一个合成器的截止频率，合成器`:tb303`模拟器是一个很好的实验对象：

en: Random seeds
zh-CN: 随机种子

en: So, what if you don't like this particular sequence of random numbers Sonic Pi provides? Well it's totally possible to choose a different starting point via `use_random_seed`. The default seed happens to be 0, so choose a different seed for a different random experience!
zh-CN: 如果你实在不喜欢Sonic Pi给你生成的这一组随机数怎么办？你完全可以通过`use_random_seed`选择另一个产生随机数的"种子"。默认的种子编号是0，选一个别的数字就可以体验到完全不一样的随机体验!

en: Consider the following:
zh-CN: 试试下面的例子：

en: Every time you run this code, you'll hear the same sequence of 5 notes. To get a different sequence simply change the seed:
zh-CN: 你每次运行这段代码会听到同样的5个音符。如果你想要随机产生5个不一样的音符，换一个随机种子就可以：

en: This will produce a different sequence of 5 notes. By changing the seed and listening to the results you can find something that you like - and when you share it with others, they will hear exactly what you heard too.
zh-CN: 这段代码会生成完全不同的5个音符。多试试几个不同的随机种子，你总能找到让你满意的结果，而当你与别人分享代码时，他们会听到同样的随机结果。

en: Let's have a look at some other useful random functions.
zh-CN: 我们再来看看另一些有用的随机函数。

en: choose
zh-CN: choose函数

en: A very common thing to do is to choose an item randomly from a list of known items. For example, I may want to play one note from the following: 60, 65 or 72. I can achieve this with `choose` which lets me choose an item from a list. First, I need to put my numbers in a list which is done by wrapping them in square brackets and separating them with commas: `[60, 65, 72]`. Next I just need to pass them to `choose`:
zh-CN: 我们经常要做的一件事就是从一些已知的元素中随机选择一个。比如说，我可能会想要在60,65和72这三个音中随机选一个来演奏。这个时候就可以通过`choose`来实现。首先我需要把这三个音放到一个列表中，用方括号把它们包起来，再用逗号做分隔即可（注意要用英文的方括号和逗号）：`[60, 65, 72]`，然后我只需要把这个列表交给`choose`:

en: ![Sam Aaron Live Coding](../../../etc/doc/images/tutorial/articles/A.02-live-coding/sam-aaron-live-coding.png)
zh-CN: ![即时代码](../../../etc/doc/images/tutorial/articles/A.02-live-coding/sam-aaron-live-coding.png)

en: Many musicians can look at a musical score and hear the music in their head without having to play it. This is a very useful skill and it's well worth incorporating into your live coding practice sessions. The important point is to be able to have some understanding of what the code is going to sound like. You don't need to be able to hear it exactly in your head, but instead it's useful to know if the code is going to be fast, slow, loud, rhythmic, melodic, random, etc. The final goal is then to be able to reverse this process - to be able to hear music in your head and know what code to write to make it. It may take you a long time to master this, but once you do, you'll be able to improvise on stage and express your ideas fluently.
zh-CN: 很多音乐家可以在脑海中把看到的乐曲谱子想象着播放出来。这个技能非常有用，也非常值得你在即时用代码写音乐的时候融合进去。重点是你应该能够大体知道你写下的代码会产生出什么样的声音。你不需要像音乐家一样，在脑海中把它们完美的想象出来，但至少，知道你自己写下的代码会听起来是快，慢，响，有节奏感，有旋律感，很随机，等等。这一系列的最终目的是能够把这套东西反过来——在你的脑海中先产生音乐，然后用相应的代码来把它实现出来。想要完全掌握这项技能需要你下一定功夫，但是你一旦掌握了，就能在现场表演的时候很好的即兴创作，和表达你的音乐点子啦！

en: Some of the built-in synths already include a detune option that does exactly this in one synth. Try playing with the `detune:` opt of `:dsaw`, `:dpulse` and `:dtri`.
zh-CN: 有几个软件本身附带的合成器，已经包含了一个detune的模式，这模式和现在这一个合成器表达出来是一样的。试试看用`detune:`模式来播放`:dsaw`，`:dpulse`和`:dtri`。

en: In this example we introduce a basic loop called :jungle which picks a random drum hit from our audio sample, waits for an eighth of a second and then picks another drum hit. This results in an endless stream of random drum beats to dance to whilst you experience what a loop is.
zh-CN: 在这个例子中，我们来看一看一个叫做:jungle的简单循环。这个循环会从我们的采样中随机播放一个击鼓的声音，接着等候八分之一秒，再随机播放一个击鼓声音。这个的效果就是一系列有节奏的、无穷无尽的随机鼓声，很适合你一边跳着舞，一边感受一下循环能干啥。
