Wolfram Research

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

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.
The following arguments are defined as default by the function:
Instrument : "Guitar"
NoteInterval : 0.3
Tone : "F2"
Octaves : 2
SoundVolume : 1
Playing : "Organic"
The scales (30 different scales) that work in the first argument of the function can be chosen from the following table:
"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"
As function standard, the "Instrument" chosen is the “Guitar”, since the source of the scales presented here came from the study of the guitar, but any instrument can be chosen, in the form of an option to the function from the list described in the section Details & Options on SoundNote command.
The default interval between notes ("NoteInterval") is 0.3 seconds, but any timing (in seconds) can be chosen as an option in the function.
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 became overrided by the duration of the sound with the Sound command.
The default number of "Octaves" that participate in the sample is 2 for the function, because as a matter of sonority, the change from one octave to another is important, and also because it represents the complete vertical movement in the arm of a guitar, which covers two octaves. However, it is possible by an option in the function to change the number of octaves in the sample to 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" note (fifth octave note) to "Bb8" (penultimate note of eighth octave).
Octaves Max range of notes
1 12
2 24
3 36
It is possible to change the volume of the musical sample (“SoundVolume”) as an option, useful for more complex creations of musical samples. Similar to SoundVolume values.
The musical scale can be played (“Playing“) with the options: “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“ is with all notes played exactly with the same “NoteInterval“ already set, the way a machine would do (this form makes the music sample always have the same duration when generated).

Examples

Basic Examples

Get a musical scale sample by name:

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

Scope

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

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 on the same sample many sequences of different scales and instruments:

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

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

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 reduce):

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

Time of evaluation

All scales do evaluate in less then 1 second, except the “Chromatic” scale with 3 octaves as argument, since has 12 musical notes per octave and many possible combinations:

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

Neat Examples

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]=

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

In[22]:=
Sound[{Sound[
   ResourceFunction["MusicalScaleSample"]["GagakuRyoSenPou", "Octaves" -> 3, "Instrument" -> "SteelGuitar", "SoundVolume" -> 4/5, "Playing" -> "Mechanical"], {0, 10}], Sound[ResourceFunction["MusicalScaleSample"]["InSenPou", "Tone" -> "F4", "SoundVolume" -> 4/5, "Playing" -> "Mechanical"], {10, 17}], Sound[ResourceFunction["MusicalScaleSample"]["Okinawa", "Tone" -> "F3", "Instrument" -> "Glockenspiel", "SoundVolume" -> 3/5, "Playing" -> "Mechanical"], {5, 13}], Sound[ResourceFunction["MusicalScaleSample"]["Oriental", "Octaves" -> 1, "Instrument" -> "Percussion", "SoundVolume" -> 3/4, "Playing" -> "Mechanical"], {10, 20}]}]
Out[22]=

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]:=
Sound@Flatten[{Table[
    Sound[ResourceFunction["MusicalScaleSample"]["Balinese", "Tone" -> "F3", "Octaves" -> 3, "Instrument" -> "Percussion", "SoundVolume" -> 3/5], i], {i, {{0, 10}, {10, 20}, {20, 30}}}], Table[Sound[
     ResourceFunction["MusicalScaleSample"]["Balinese", "Instrument" -> "Percussion", "SoundVolume" -> 3/5], j], {j, {{0, 10}, {10, 20}, {20, 30}}}], Sound[ResourceFunction["MusicalScaleSample"]["Enigmatic", "Tone" -> "F3", "Instrument" -> "Harp", "SoundVolume" -> 4/5], {0, 10}], Sound[ResourceFunction["MusicalScaleSample"]["Byzantine", "Octaves" -> 1, "Instrument" -> "ElectricGuitar", "SoundVolume" -> 4/5], {10, 20}], Sound[ResourceFunction["MusicalScaleSample"]["Prometheus", "Tone" -> "F3", "Instrument" -> "Organ", "SoundVolume" -> 4/5], {20, 30}]}]
Out[23]=

Resource History

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 Mathematica allied to common scales established in the world and regional music.

License Information