Back

Sampler

Pass in an object which maps the note's pitch or midi value to the file, then you can play the tone and stop of that note like other instruments. By automatically repitching the samples, it is possible to play pitches which were not explicitly included which can save loading time.

You can an instance of the music object when you need it like this:

 sampler = music.CreateSampler(object)


Example


function OnStart()
{
  music = app._381()
  sampler = music.CreateSampler({
   files: {
    A1: "a1.mp3",
    A2: "a2.mp3"
   },
   folder: "/Docs/Music/Snd"
  })

  music.SetOnLoaded(() => {
   sampler.PlayStopTone(["C1", "E1", "G1", "B1"], 0.5)
  })
}

  Copy   Copy All    Run   


You can find a few instrument samples(check samples folder):  sampler.PlayTone(notes, time, velocity)

Trigger the play of the note. Velocity optional default 1

note: The note to play.

time: When the note should be play.

velocity: The velocity scaler determines how "loud" the note will be played.


 sampler.PlayStopTone(note, duration, time, velocity)

Trigger the play of the note after stop.

note: The note to play.

duration: How long the note should be held for before play the stop. This value must be greater than 0.

time: When the note should be play.

velocity: The velocity the note should be play at.


 sampler.StopTone(time)

Stop the note portion of the envelope.

time: If no time is given, the stop happens immediatly.


 sampler.SetAttack(number)

When PlayTone is called, the attack time is the amount of time it takes for the envelope to reach it's maximum value.


 sampler.SetVolume(decibels)

The volume of the output in decibels.


 sampler.SetRelease(number)

After StopTone is called, the envelope's value will fall to it's miminum value over the duration of the release time.


 sampler.Set(oscillatorType)

Set multiple properties at once with an object.


 sampler.GetName()

Return sampler name.


 sampler.Get()

Get the object's attributes.


 sampler.Dispose()

Clean up.


 sampler._synth

Return Tone.Sampler class from Tonejs


Synth, AM, FM, Membrane, Metal, Duo, Pluck, Mono, Noise
{
 files:
  {note: "fileName.mp3"},
  folder: "/sdcard/myfolder" or "Snd"
}
{
  attack: TIME,
  release: TIME,
  volume: DECIBELS,
  curve: DECIBELS
}
Frequency can be described similar to time, except ultimately the values are converted to frequency instead of seconds. A number is taken literally as the value in hertz. Additionally any of the Time encodings can be used. Note names in the form of NOTE OCTAVE (i.e. C4) are also accepted and converted to their frequency value.
Time can be described in a number of ways. Read more Range: 0..1
Range: 0..2
Range: 0..5
Decibels are a logarithmic unit of measurement which is useful for volume because of the logarithmic way that we perceive loudness. 0 decibels means no change in volume. -10db is approximately half as loud and 10db is twice is loud.