{"id":1205,"date":"2021-01-31T22:21:13","date_gmt":"2021-01-31T21:21:13","guid":{"rendered":"https:\/\/next-hack.com\/?p=1205"},"modified":"2021-02-20T10:48:53","modified_gmt":"2021-02-20T09:48:53","slug":"usvc-tutorial-6-sound-part-2","status":"publish","type":"post","link":"https:\/\/next-hack.com\/index.php\/2021\/01\/31\/usvc-tutorial-6-sound-part-2\/","title":{"rendered":"uSVC Tutorial 6: Sound (part 2)"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Introduction<\/h3>\n\n\n\n<p>Last time we started our journey about producing sounds on uSVC. We hope that you played in the meantime with the various patch commands! If you are curious about some effects you might achieve, you can download the source code of uSVC Tetris, and check the patches.c file.<\/p>\n\n\n\n<p>In the previous part, we just used patches and default sounds. Despite them being very flexible, sometimes you might need a PCM audio sample: a shot, an explosion, a speech, etc. Thankfully, uChip supports PCM audio samples, which allows for more realistic sounds. The issue here is balancing the audio quality, with flash usage. Yes, high sample rates get more natural and pleasing sounds, but will literally eat up all the available flash memory, leaving very few space for graphics, game data (maps, initial sprite positons, etc.), and code.<\/p>\n\n\n\n<p>uSVC has support for 8-bit audio samples only, so you cannot trade resolution with flash usage, so you can only reduce length or sample rate. In some cases, reducing length is not possible, so you can only reduce the flash usage by acting on the sample rate. uSVC supports arbitrary sample rate, so in this sense you have a lot of flexibility.<\/p>\n\n\n\n<p>Note that each PCM sound can have its own sample rate. This is very useful, as some sounds effect are still good even at lower sample rates, while other require higher value. This allows for a better optimization of the memory usage. You should check on a case-by-case basis the minimum acceptable sample rate for each sound you want to play.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Optimizing the sample<\/h3>\n\n\n\n<p>The first optimization step is to remove any silence part at the beginning or at the end of the sample. Note that at 30ksps, even a 0.1-s silence corresponds to 3kB of wasted data! Note also, that for silence we do not necessarily mean 0-valued samples, but also those parts that have a very low volume, which are unlikely to be appreciated by the player during game, when other effects or music are played.<\/p>\n\n\n\n<p>If silence occurs in the middle of the sample (e.g. when you have a speech made by two words), consider instead of having two separate samples. For instance if you have a car-game, and you want a voice saying: \u201cready, set, go!\u201d, it would be a lot better if you had 3 distinct sounds, one for each word.<\/p>\n\n\n\n<p>To trim (remove silence) and cut audio samples, we suggest Audacity.<\/p>\n\n\n\n<p>Sometimes you\u2019ll find some sound effects which are too low in volume. It is always better to get full-volume sounds, and let the uSVC sound engine to eventually reduce the volume, if in your game you need a quieter one. Therefore, you\u2019ll need to normalize the audio sample to the maximum undistorted volume. This will allow to achieve an audio sample that has at least an 8-bit resolution (better resolution is not needed as uSVC sound engine works with 8-bit samples). This is almost always true, because you\u2019ll almost always start with 16-bit wave files.<\/p>\n\n\n\n<p>Another optimization is using patches. Say you have one sample, that needs to be repeated (at different volumes \u2013 e.g. to simulate echo \u2013 or at different pitches), instead of using the repeated sound, you could use a single sound, and repeat it through patch commands. Or if you have a rocket, or a bomb sound, that for instance, changes pitch during time, instead of saving the whole sound duration, one could save just a small fraction, have it looping, and change the effect pitch during playback with time using patch commands.<\/p>\n\n\n\n<p>The last optimization is of course a tradeoff between quality and space. The higher the quality, the higher the memory taken by the sound effect. However, the full 30ksps capability is not always required for an acceptable quality, and we suggest using Audacity, to get a first preview about the quality of your sample at different sample rates. Keep in mind, that the final quality will be lower, as Audacity at minimum use 16-bit samples, whereas uSVC features 8-bit audio.<\/p>\n\n\n\n<p>However, nothing can optimize like a series of patch commands. With experience, you might realize that several effects can be reproduced with a good fidelity using only the default sounds and a series of patch commands, without requiring PCM samples.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Optimization Example<\/h4>\n\n\n\n<p>For this tutorial, we will use a wav file you can find on opengameart.com. We will modify it to remove unnecessary parts, reduce the sample rate and finally add some patch commands customize it.<\/p>\n\n\n\n<p>Let\u2019s download the file <a href=\"https:\/\/opengameart.org\/content\/sound-effects-sfx008\">https:\/\/opengameart.org\/content\/sound-effects-sfx008<\/a>, unzip it, and open the file FX71.mp3 in Audacity. You should get something like what is shown below.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"926\" height=\"707\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-1.png\" alt=\"\" class=\"wp-image-1206\" srcset=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-1.png 926w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-1-300x229.png 300w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-1-768x586.png 768w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-1-870x664.png 870w\" sizes=\"(max-width: 926px) 100vw, 926px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>As you might see, this audio is all but optimized: it has a silence part at the beginning, and its volume is quite low.<\/p>\n\n\n\n<p>First let\u2019s mix the audio to mono (using \u201ctracks-&gt;mix-&gt;mix stereo down to mono\u201d menu). You should now get a mono audio sample.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"926\" height=\"707\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-2.png\" alt=\"\" class=\"wp-image-1207\" srcset=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-2.png 926w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-2-300x229.png 300w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-2-768x586.png 768w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-2-870x664.png 870w\" sizes=\"(max-width: 926px) 100vw, 926px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Then, let\u2019s normalize the audio, so it is at its full volume.<\/p>\n\n\n\n<p>So, select from the Effect volume, the \u201cNormalize\u201d. The following window will appear:<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"474\" height=\"178\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-normalize.png\" alt=\"\" class=\"wp-image-1208\" srcset=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-normalize.png 474w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-normalize-300x113.png 300w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Press ok. The audio will appear now as fully amplified:<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"898\" height=\"153\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-normalizedAudio.png\" alt=\"\" class=\"wp-image-1209\" srcset=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-normalizedAudio.png 898w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-normalizedAudio-300x51.png 300w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-normalizedAudio-768x131.png 768w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-normalizedAudio-870x148.png 870w\" sizes=\"(max-width: 898px) 100vw, 898px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Then, let\u2019s remove the silence. You can do it by hand, or you can use the Truncate Silence from the Effect menu. The following window will appear:<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"474\" height=\"337\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-truncateSilence.png\" alt=\"\" class=\"wp-image-1210\" srcset=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-truncateSilence.png 474w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-audacity-truncateSilence-300x213.png 300w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>We set the duration to 0.01 and threshold to -40dB. These values vary on case-by-case basis.<\/p>\n\n\n\n<p>If you press ok, you get something like:<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"926\" height=\"707\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-silence-truncated.png\" alt=\"\" class=\"wp-image-1211\" srcset=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-silence-truncated.png 926w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-silence-truncated-300x229.png 300w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-silence-truncated-768x586.png 768w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-silence-truncated-870x664.png 870w\" sizes=\"(max-width: 926px) 100vw, 926px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>As you can see, the number of samples has been reduced.<\/p>\n\n\n\n<p>Now, uSVC does produce 44100 Hz audio. You can still use them, but it would be a waste of memory, because the sound engine would skip some samples. Better to already reduce the sample rate.<\/p>\n\n\n\n<p>If you set 30000 on the project rate you would still use about 11000 samples (11kB). In our case we reduce the project rate to 15000 Hz, so that we get about 6000 samples (6kB).<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"926\" height=\"707\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-silence-15ksps.png\" alt=\"\" class=\"wp-image-1212\" srcset=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-silence-15ksps.png 926w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-silence-15ksps-300x229.png 300w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-silence-15ksps-768x586.png 768w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-silence-15ksps-870x664.png 870w\" sizes=\"(max-width: 926px) 100vw, 926px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Now export to a wav file (Menu File-&gt;Export-&gt;Export as Wav), and save it as a 16 bit signed wav.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Exporting the Audio to a C File <\/h3>\n\n\n\n<p>It is time to open the <a href=\"https:\/\/next-hack.com\/index.php\/2020\/09\/18\/uchip-game-map-editor\/\" target=\"_blank\" rel=\"noreferrer noopener\">uChip Game Map Editor<\/a> and convert the file to a C header.<\/p>\n\n\n\n<p>To convert the file, select from the \u201cUtilities\u201d menu, \u201cExport Wav To C\u201d. Open the wav you just created, and a window asking for the variable name will appear:<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"476\" height=\"117\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-exportWaveData.png\" alt=\"\" class=\"wp-image-1214\" srcset=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-exportWaveData.png 476w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-exportWaveData-300x74.png 300w\" sizes=\"(max-width: 476px) 100vw, 476px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>In the example we leave waveData, however in your game you should make sure you get a unique variable for each sound effect. Once you press ok, the editor will ask where you want to save the exported file. After you confirm, you\u2019ll get the confirmation about the successful conversion. Let\u2019s open it! The file resembles the structure of exported tiles or sprites. There is a section you should put in a header file, and a section you should put in a C file, as shown below:<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"864\" height=\"190\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-newWaveExported.png\" alt=\"\" class=\"wp-image-1215\" srcset=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-newWaveExported.png 864w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-newWaveExported-300x66.png 300w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-newWaveExported-768x169.png 768w\" sizes=\"(max-width: 864px) 100vw, 864px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Adding the Exported File to the Project<\/h3>\n\n\n\n<p>Let\u2019s use (a copy of) the project you made for the last tutorial, and let\u2019s modify it so that it includes the new sample.<\/p>\n\n\n\n<p>In our example games, we always include all the sound effects in a single file. This will create a huge file, but it will help you in reducing the number of files, and, the need to include them all in your project. You can have a single couple of header and c files for each sample, but, unless you put these files in a separate directory, your project structure would be quite a mess.<\/p>\n\n\n\n<p>We have no soundData.c and soundData.h files yet in our project. Let\u2019s create them by right clicking on the project name in the solution explorer, and selecting Add, New Items, C and include File, respectively for soundData.c and soundData.h files.<\/p>\n\n\n\n<p>&nbsp;In these files, copy what it is suggested in the image above (like we did for the tiles and sprites) and save them. Furthermore, in main.h, include the file soundData.h, by writing, after the last #include line, the line #include \u201csoundData.h\u201d.<\/p>\n\n\n\n<p>SoundData.h should be like the picture below.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"440\" height=\"204\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-soundDataH.png\" alt=\"\" class=\"wp-image-1216\" srcset=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-soundDataH.png 440w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-soundDataH-300x139.png 300w\" sizes=\"(max-width: 440px) 100vw, 440px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Similarly, soundData.c should be like this:<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"470\" height=\"136\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-soundDataC.png\" alt=\"\" class=\"wp-image-1217\" srcset=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-soundDataC.png 470w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-soundDataC-300x87.png 300w\" sizes=\"(max-width: 470px) 100vw, 470px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Playing the Sound Effect<\/h3>\n\n\n\n<p>To use the new sound, we need to put its reference, length, and sample per second in the soundWaveList array. To do this, open soundWaveList.c and add a new entry, like we did below.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"546\" height=\"452\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-soundWaveListEntry.png\" alt=\"\" class=\"wp-image-1218\" srcset=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-soundWaveListEntry.png 546w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-soundWaveListEntry-300x248.png 300w\" sizes=\"(max-width: 546px) 100vw, 546px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Now, we need to add an entry to the patch list. If we are going to play the sound as is, i.e. without modifications, then you just simply need to create an entry in the patches array, without actually creating a new patch.<\/p>\n\n\n\n<p>We did this by adding the highlighted region below:<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"799\" height=\"109\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-patchEntry.png\" alt=\"\" class=\"wp-image-1219\" srcset=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-patchEntry.png 799w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-patchEntry-300x41.png 300w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-patchEntry-768x105.png 768w\" sizes=\"(max-width: 799px) 100vw, 799px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Let\u2019s take a look at the various parameters.<\/p>\n\n\n\n<p>The first parameter is 0 by default. The second points to the eleventh element in the soundWaveList array (<code>DEFAULT_SOUND_NUMBER<\/code> is 10). The third parameter is <code>NULL<\/code>. For now we do not use a patch. The other two parameters are the loop start and stop, respectively. The loop stop is set to the number of samples in the sound effect, so that, when the mixer tries to play that sample, it will roll back to the sample number indicated by the \u201cstart\u201d value, which is actually the last sample of the sound effect. This has the purpose to play the effect only once (if, for instance, you set 0, the whole effect would play in a loop, forever).<\/p>\n\n\n\n<p>Now, in the previous tutorial, we triggered an FX before the while(1), in particular the effects 0 and 1.<\/p>\n\n\n\n<p>Now we want to trigger a PCM audio, with the exact sample rate frequency, so we need to substitute the line with the following:<\/p>\n\n\n\n<p><code>triggerFx(2, 255, FX_FLAGS_SPECIFY_SAMPLE_FREQUENCY, 0x10000);<\/code><\/p>\n\n\n\n<p>Note that we also added the flag <code>FX_FLAGS_SPECIFY_SAMPLE_FREQUENCY<\/code>, which remember the sound engine that the PCM sample is using a different sample frequency, specified in the soundWaveList array (15000).<\/p>\n\n\n\n<p>If you compile and upload the example in debug mode, you should hear the sound effects as soon as uChip resets.<\/p>\n\n\n\n<p>Let\u2019s create a patch that will modify the sound, to add something more interesting, like the repetition of the sound, like if it was a burst shot.<\/p>\n\n\n\n<p>For this purpose, we add a patch like below:<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"902\" height=\"273\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-newPatch.png\" alt=\"\" class=\"wp-image-1220\" srcset=\"https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-newPatch.png 902w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-newPatch-300x91.png 300w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-newPatch-768x232.png 768w, https:\/\/next-hack.com\/wp-content\/uploads\/2021\/01\/sixth-newPatch-870x263.png 870w\" sizes=\"(max-width: 902px) 100vw, 902px\" \/><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>If you change the first parameter of the triggerFx to 3 (i.e. that points to the new effects in the patches array), compile and upload in debug mode, you should hear a multiple shot, 3 rounds. The first one, played at the specified sample rate (it is automatically triggered by triggerFx), and the other two at a lower pitch, triggered by the patch commands <code>PC_WAVE<\/code> and <code>PC_PITCH<\/code>.<\/p>\n\n\n\n<p>You might wonder how did we choose the <code>PC_PITCH<\/code> parameter (30 and 28) in <code>multipleRoundsPatch<\/code>. The original sound is a 15ksps, and its first instance is played with an increment of 0.5, thanks to the flag <code>FX_FLAGS_SPECIFY_SAMPLE_FREQUENCY<\/code>. In fact, 30000 Hz (uSVC mixer sample rate) multiplied by 0.5 yields 15000Hz. The increment of the other two depends on the note indicated as a parameter. These corresponds to the specified increment you might find in stepTable.c. In that file we simply chose the note corresponding to an increment of about 0.4 (12000 sps) and 0.35 (10500 sps).\u00a0<\/p>\n\n\n\n<p>As a last remark, let\u2019s check how much flash we used, and how much we saved.<\/p>\n\n\n\n<p>The total duration of this patch is about 0.7s. If we did this using a single PCM sound effect, we would have used about 10.5kB, instead of less than 6kB, which is what we are using now. The flash occupation would have been even larger if we kept 30ksps and the \u201csilence\u201d section on the original sound file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusions<\/h3>\n\n\n\n<p>This concludes this second tutorial on sound. Now you are able to play arbitrary PCM samples, for more realistic and higher quality samples! In the next tutorial we will finally deal with music!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Last time we started our journey about producing sounds on uSVC. We hope that you played in the meantime with the various patch commands! If you are curious about some effects you might achieve, you can download the source&#8230; <a class=\"read-more-button\" href=\"https:\/\/next-hack.com\/index.php\/2021\/01\/31\/usvc-tutorial-6-sound-part-2\/\">(READ MORE)<\/a><\/p>\n","protected":false},"author":2,"featured_media":1206,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[32,27],"tags":[],"class_list":["post-1205","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-all-projects","category-usvc"],"_links":{"self":[{"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/posts\/1205"}],"collection":[{"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/comments?post=1205"}],"version-history":[{"count":3,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/posts\/1205\/revisions"}],"predecessor-version":[{"id":1223,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/posts\/1205\/revisions\/1223"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/media\/1206"}],"wp:attachment":[{"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/media?parent=1205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/categories?post=1205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/tags?post=1205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}