Function Repository Resource:

MusicalScaleSample

Source Notebook

Generate samples of several musical scales

Contributed by: Claudio Lobo Chaib Filho

ResourceFunction["MusicalScaleSample"][scale]

generates a sound sample from a specified scale.

ResourceFunction["MusicalScaleSample"][scale,"Instrument"arg]

generates a sound sample for "Instrument".

ResourceFunction["MusicalScaleSample"][scale,"NoteInterval"arg]

uses "NoteInterval" to accelerate or decelerate the track by changing the time between notes.

ResourceFunction["MusicalScaleSample"][scale,"Tone"arg]

specifies the "Tone" of the musical sample.

ResourceFunction["MusicalScaleSample"][scale,"Octaves"arg]

specifies the "Octaves" of the musical sample.

ResourceFunction["MusicalScaleSample"][scale,"SoundVolume"arg]

specifies the "SoundVolume" of the musical sample.

ResourceFunction["MusicalScaleSample"][scale,"Playing"arg]

specifies the method of "Playing" the musical sample.

Details and Options

ResourceFunction["MusicalScaleSample"] can be used to generate samples of simple and fast musical scales (most of them are ethnic and cultural scales, in addition to the more common Greek scales) or more complete and personalized ones.
The following arguments are defined as default by the function:
Instrument"Guitar"
NoteInterval0.3
Tone"F2"
Octaves2
SoundVolume1
Playing"Organic"
There are 30 different scales that work in the first argument of the function. They can be chosen from the following:
"MajorPentatonic""JazzMinor""Persian"
"MinorPentatonic""BluesScale""EastIndianPurvi"
"NeopolitanMajor""Chromatic""Oriental"
"NeopolitanMinor""Overtone""GagakuRyoSenPou"
"HungarianMajor""WholeTone""Zokugaku"
"HungarianMinor""Enigmatic""InSenPou"
"HungarianGypsy""Symmetrical""Okinawa"
"HarmonicMajor""Arabian""DiminishedWholeTone"
"HarmonicMinor""Balinese""EightToneSpanish"
"DoubleHarmonic""Byzantine""Prometheus"
By default, the "Instrument" chosen is the "Guitar" since the source of the scales presented here came from the study of the guitar. Other instruments can be specified using the "Instrument" option, possible values of which can be chosen from the list described in the "Details & Options" section of SoundNote.
The default interval between notes is 0.3 seconds, but other timings (in seconds) may be specified via the "NoteInterval" option.
Optionally, one can select the "Tone" of the musical scale, and any tone from the first to the fifth octave (60 different tones) can be selected. By default, the tone is "F2", as it is the first fret of a guitar’s arm. The selectable tones are:
"C1""Ab2""E4"
"Db1""A2""F4"
"D1""Bb2""Gb4"
"Eb1""B2""G4"
"E1""C3""Ab4"
"F1""Db3""A4"
"Gb1""D3""Bb4"
"G1""Eb3""B4"
"Ab1""E3""C5"
"A1""F3""Db5"
"Bb1""Gb3""D5"
"B1""G3""Eb5"
"C2""Ab3""E5"
"Db2""A3""F5"
"D2""Bb3""Gb5"
"Eb2""B3""G5"
"E2""C4""Ab5"
"F2""Db4""A5"
"Gb2""D4""Bb5"
"G2""Eb4""B5"
When ResourceFunction["MusicalScaleSample"] is used in conjunction with the Sound command in order to simultaneously play multiple overlaped musical samples, the "NoteInterval" specified in the function is overridden by the duration of the sound with the Sound command.
The default number of "Octaves" that participate in the sample is 2, because as a matter of sonority, the change from one octave to another is important; it also represents the complete vertical movement in the arm of a guitar, which covers two octaves. However, "Octaves" may be specified to be 1, 2 (default) or 3. For example, the default tone is "F2" and the number of standard octaves is 2, so the standard music samples of the function can have notes from "F2" to "B3", that is, covering the second and third octaves. Although the highest selectable tone in the "Tone" argument is "B5", when you choose 3 octaves as argument, the scale may have a range from "B5" (the fifth octave note) to "Bb8" (the penultimate note of eighth octave).
OctavesMax range of notes
112
224
336
It is possible to change the volume of the musical sample using the "SoundVolume" option. This is similar to SoundVolume values and is useful for more complex creations of musical samples.
The musical scale can be played with the "Playing" option by specifying the values "Organic" (default) or "Mechanical". The form "Organic" is one made with a certain minimum variation in the time of each note to have a smoother and more natural sonority (almost as a person would). The form "Mechanical" plays with all notes played exactly with the same "NoteInterval" already set, the way a machine would do. "Playing""Mechanical" makes the music sample always have the same duration when generated.

Examples

Basic Examples (1) 

Get musical scale samples by name:

In[1]:=
ResourceFunction["MusicalScaleSample"]["MajorPentatonic"]
Out[1]=
In[2]:=
ResourceFunction["MusicalScaleSample"]["HarmonicMinor"]
Out[2]=
In[3]:=
ResourceFunction["MusicalScaleSample"]["Chromatic"]
Out[3]=

Scope (7) 

Specify an instrument:

In[4]:=
ResourceFunction["MusicalScaleSample"]["NeopolitanMinor", "Instrument" -> "SteelGuitar"]
Out[4]=

Specify a note interval along with an instrument:

In[5]:=
ResourceFunction["MusicalScaleSample"]["Overtone", "NoteInterval" -> 0.22, "Instrument" -> "Crystal"]
Out[5]=

Specify a tone, note interval, and instrument:

In[6]:=
ResourceFunction["MusicalScaleSample"]["EastIndianPurvi", "Tone" -> "F3", "NoteInterval" -> 0.26, "Instrument" -> "Sitar"]
Out[6]=

Specify a tone, number of octaves, a note interval, and an instrument:

In[7]:=
ResourceFunction["MusicalScaleSample"]["Okinawa", "Tone" -> "Gb2", "Octaves" -> 3, "NoteInterval" -> 0.42, "Instrument" -> "Agogo"]
Out[7]=

Specify a tone, number of octaves, a note interval, instrument, and the sound volume:

In[8]:=
ResourceFunction["MusicalScaleSample"]["MinorPentatonic", "Tone" -> "A2", "Octaves" -> 1, "NoteInterval" -> 0.35, "Instrument" -> "Organ", "SoundVolume" -> 1/3]
Out[8]=

Specify a tone, number of octaves, a note interval, instrument, sound volume and method of playing:

In[9]:=
ResourceFunction["MusicalScaleSample"]["WholeTone", "Tone" -> "C2", "Octaves" -> 3, "NoteInterval" -> 0.2, "Instrument" -> "Trumpet", "SoundVolume" -> 2/3, "Playing" -> "Mechanical"]
Out[9]=

Play all notes of the chosen scale and configuration by setting "NoteInterval" to 0:

In[10]:=
ResourceFunction["MusicalScaleSample"]["HungarianGypsy", "NoteInterval" -> 0]
Out[10]=

Applications (2) 

Extend the sound

Use Sound and Table to extend the length of the musical sample:

In[11]:=
Sound@Table[
  ResourceFunction["MusicalScaleSample"]["DiminishedWholeTone"], 3]
Out[11]=

Sequency of scales and instruments

Use Sound and Table to play many sequences of different scales and instruments on the same sample:

In[12]:=
Sound@Table[
  ResourceFunction["MusicalScaleSample"][i, "Tone" -> "A2", "Octaves" -> 1, "NoteInterval" -> 0.23, "Instrument" -> "Piano"], {i, {"Enigmatic", "HungarianMinor", "Arabian"}}]
Out[12]=
In[13]:=
Sound@Table[
  ResourceFunction["MusicalScaleSample"]["MajorPentatonic", "NoteInterval" -> 0.15, "Instrument" -> i], {i, {"PanFlute", "ElectricPiano", "Bass"}}]
Out[13]=

Use Sound to construct a sequence of instruments and scales, both varying:

In[14]:=
Sound[{ResourceFunction["MusicalScaleSample"]["BluesScale", "Tone" -> "C2", "NoteInterval" -> 0.33, "Instrument" -> "Piano"], ResourceFunction["MusicalScaleSample"]["JazzMinor", "NoteInterval" -> 0.2, "Instrument" -> "GuitarHarmonics"]}]
Out[14]=

Properties and Relations (2) 

Overlapping instruments

Play samples with many instruments together, each one with own time and cadency:

In[15]:=
Sound[{Sound[
   ResourceFunction["MusicalScaleSample"]["Zokugaku", "Instrument" -> "Crystal"], {0, 13}], Sound[ResourceFunction["MusicalScaleSample"]["Zokugaku", "Instrument" -> "VoiceAahs"], {3, 20}]}]
Out[15]=

Play a sample made with synchronized multiple musical samples and many optional:

In[16]:=
Sound[{Sound[
   ResourceFunction["MusicalScaleSample"]["MinorPentatonic", "Tone" -> "C2", "Instrument" -> "Accordion", "SoundVolume" -> 3/4,
     "Playing" -> "Mechanical"], {0, 15}], Sound[ResourceFunction["MusicalScaleSample"]["MinorPentatonic", "Tone" -> "C2", "Instrument" -> "Harpsichord", "Playing" -> "Mechanical"], {0, 15}]}]
Out[16]=

Possible Issues (2) 

Instrumentation tone reach

Naturally some instruments cannot reach some low tones:

In[17]:=
ResourceFunction["MusicalScaleSample"]["WholeTone", "Tone" -> "C1", "Instrument" -> "Flute"]
Out[17]=

Naturally some instruments cannot reach some high tones:

In[18]:=
ResourceFunction["MusicalScaleSample"]["Overtone", "Tone" -> "B5", "Instrument" -> "GuitarHarmonics"]
Out[18]=

Shorter samples

It is not possible to reduce the timing of the simpler sample without changing the speed of the melody. The simplest form is about 10 seconds long and each note interval is 0.3 seconds; if you wish to make a smaller sound length, the note interval must be reduced:

In[19]:=
ResourceFunction["MusicalScaleSample"]["NeopolitanMinor"][[;; 5]]
Out[19]=

Time of evaluation

Most scales evaluate in less than one second. One exception is the "Chromatic" scale with 3 octaves as argument, since it has 12 musical notes per octave and many possible combinations:

In[20]:=
ResourceFunction["MusicalScaleSample"]["Chromatic", "Octaves" -> 3] // AbsoluteTiming
Out[20]=

Neat Examples (3) 

An example of a few instruments playing together harmoniously:

In[21]:=
Sound@Table[
  Sound[ResourceFunction["MusicalScaleSample"]["InSenPou", "Instrument" -> i], {0, 11}], {i, {"Percussion", "GuitarMuted", "Bass"}}]
Out[21]=

An example of musical sample with many instruments, each one with different timing, scales, octaves and sound volumes:

In[22]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/0ba6be90-6c4c-4b31-a8a3-051e67b2da3b"]
Out[22]=

A neat example of a melody with a base in percussion that extends the entire track, and different instruments and scales that take turns sequentially:

In[23]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/fe00330a-7216-4714-8a73-85defb691d86"]
Out[23]=

Publisher

Claudio Lobo Chaib Filho

Version History

  • 1.0.0 – 29 July 2019

Source Metadata

Author Notes

Play with 30 musical scales samples, including various ethnic and cultural scales (Balinese, Japanese, European and classical), with samples built quickly and directly.
Build more complex and elaborate musical scale samples with many different sonority possibilities. Choose the tone, speed, among other options. Use various instruments already available in the Wolfram Language allied to common scales established in the world and regional music.

License Information