Data AcQuisition And Real-Time Analysis
Scope - Spectrum - Spectrogram - Signal Generator
Software for Windows
Science with your Sound Card!
The following is from the Daqarta Help system:



Spectrum Analyzer

Signal Generator

(Absolutely FREE!)


Pitch Tracker


DaqMusiq Generator
(Free Music... Forever!)

Engine Simulator

LCR Meter

Remote Operation

DC Measurements

True RMS Voltmeter

Sound Level Meter

Frequency Counter
    Spectral Event

    MHz Frequencies

Data Logger

Waveform Averager


Post-Stimulus Time
Histogram (PSTH)

THD Meter

IMD Meter

Precision Phase Meter

Pulse Meter

Macro System

Multi-Trace Arrays

Trigger Controls


Spectral Peak Track

Spectrum Limit Testing

Direct-to-Disk Recording



Frequency response

Distortion measurement

Speech and music

Microphone calibration

Loudspeaker test

Auditory phenomena

Musical instrument tuning

Animal sound

Evoked potentials

Rotating machinery


Product test

Contact us about
your application!

MIDI Buffer Array Direct Access

Changes: Bbvb.i0, Bwvb.i0, Bdvb.i0, BmN.i0

MIDI Input Buffer Access:

The Direct Entry command allows a MIDI Changes script to use MIDI note input buffers as general-purpose integer arrays. They are particularly useful for holding lists of arbitrary values for random selection.

Although each buffer normally holds up to 256 note values in the range of 0-127, you can choose to store arbitrary 8-bit values there, which can be treated as signed or unsigned.

Alternatively, you can choose to store up to 128 16-bit values or up to 64 32-bit values.

There is no option to store fixed-point real values in MIDI buffers, but you can access macro array buffers from MIDI scripts. See Macro Buffer Access, below.

Use Bbvb.i0=n to store an arbitrary 8-bit (byte) value n at index i0 in buffer b of voice v. Note that this direct access method is not allowed with Voice Patterns (Velocity, Note, or Chord), which have their own access commands.

Index i0 may range from 0-255. It may be an immediate constant or any valid expression. Voice and buffer numbers are normally single-digit constants, but if you want to control them via Changes scripts you can replace them with expressions surrounded by carets like <UA+UB>. (You may also need to surround i0 with carets when reading a direct access value... see below.)

The n data value can also be an immediate constant or any valid expression. If it is larger than 255 (or, if signed, outside the range of -128 to +127), only the low 8 bits are stored and any higher bits are ignored. Most MIDI values are unsigned, in the 0-127 range. +/-Note and Pan position are signed, in the range of -64 to +63. Thus, a single byte will hold most values.

For data values in the 0-127 range, this command would appear to be eqivalent to the single-value Buffer Fill command BFvb.i0=n. However, since that command is designed for note pattern entry, it also keeps track of the start and end position pointers, extending the played region as needed. The Direct Array Access commands don't affect the pointers since they assume other uses.

Similarly, use Bwvb.i0=n to store an arbitrary 16-bit (word) value at index i0, which may range from 0-127. Signed values for n must be in the range of -32768 to +32767, while unsigned values may range from 0-65535. The most likely use for 16-bit data arrays is to store 12-bit Scales (1-4095).

Likewise, use Bdvb.i0=n to store an arbitrary 32-bit (double-word) value at index i0, which may range from 0-63. You would need 32-bit data to store random value seeds for forcing certain "repeatable random" operations. But you can also use this to extend the number of general-purpose signed integer User Variables beyond UA to UZ.

Reading MIDI Buffer Values:

To read the data from the arrays, use the same general formats as above, but on the right side. For example, to set UA with the 3rd word from voice 1, buffer 2, you would use:


The lowercase 'w' indicates that the word will be read as an unsigned 16-bit (word) integer in the range 0-65535. Alternatively, you could read the same location as a signed integer in the range -31768 to +32767 using an uppercase 'W':


To set UA to a signed 32-bit double-word from randomly-selected positions 0-31 in the same buffer, you could use:


You can also read unsigned 32-bit values using a lowercase 'd', but signed integer MIDI user variables like UA only hold positive values up to 2^31-1, and unsigned reals like Ua only hold positive integers up to 65535. But random seeds can accept any 32-bit value, so you could use:


For an 8-bit (byte) unsigned integer in the same index range, you could use:


For an 8-bit signed integer you could use:


Alternatively, if you know the data is all in the 0-127 range you could omit the 'b' or 'B' and use:


Note: Any of the above examples can use an expression for the index, but you will need to distinguish it from the use of the the indexed buffer value as part of the expression. For example, consider


As written, 196*UB+UC will be used as the index. If you want to use just 196 as the index, and use the buffer value at that index in the rest of the expression, you should enclose the index with carets:


Data Size Considerations:

A MIDI buffer doesn't "remember" what data sizes were stored into it; that's up to you. If you store (say) 16 double-words at index 0 to 15, they take up the first 64 bytes of the buffer (16 elements times 4 bytes per element). If you attempt to read 16 words from the same index range, you'll be getting low and high pieces of the first 8 double-words. Word 0 will be the low word of double-word 0, while word 1 will be the high word.

If you read 16 bytes you'll be getting byte-sized pieces of the first 4 double-words, least-significant byte first.

If you pay careful attention to indexing, you can mix different data sizes in the same buffer. For example, if you need to store 16 bytes, 16 words, and 16 double-words, you can store the bytes at indices 0-15. Storing words next, they would start at byte 16, but since word index values are twice as big that would be equivalent to word 8, so the word indices would run from 8-23. The next word index would be 24 (byte 48), which is equivalent to double-word 12, so those would run from index 12 to 27.

However, the above trickery is best saved for a last resort. With 32 buffers available (4 for each of 8 voices) you can usually find plenty of free space.

Macro Buffer Access:

Daqarta's macro system includes 8 arrays (buffers Buf0-Buf7), each holding up to 1024 fixed-point real numbers with 32-bit integer and 32-bit fraction portions. These buffers are normally written and manipulated by macros, but MIDI scripts can load them from text files, and can read and write individual values by referring to the buffer number N (0-7) and index i0 (0-1023) via:


For example, to set the value of UA into Buf0 at index 321, use:


To read the value of Buf0 at that index and set it to UA, use:


The buffer number N is normally given as an immediate digit 0-7, as in the above example. You can use a variable or expression instead by surrounding it with carets. The effective buffer number will be automatically limited to the 0-7 range. Example:


The i0 index can also be replaced with an expression, which will automatically be limited to 0-1023. Examples:



However, note that in the latter case of reading a buffer value, the expression for the index may need to be distinguished from the use of the indexed buffer value as part of an overall expression. Consider


As written, 196*UB+UC will be used as the index. If you want to use just 196 as the index, and use the buffer value at that index in the rest of the expression, you should enclose the index with carets:


Note that unlike MIDI buffers, there are no data size considerations when using macro buffers with MIDI scripts: Macro buffer elements can hold any MIDI variable of any width, signed or unsigned.

Also unlike MIDI buffers, since macro buffers hold fixed-point values you can use them to set unsigned fractional-value variables like oscillator (LFO) frequencies, or user variables Ua through Uz.

Note that Daqarta's fixed-point MIDI variables only support values from 0 to 65535.99999, but script expression evaluation maintains the same 64-bit resolution as the macro buffers during calculations, until the final assignment.

One place a large buffer holding large values is very useful is for randomly selecting a Scale from a list of preferred scales. Suppose you have (say) 300 scales in your list, loaded to macro Buf0. You can select one at random and set all voices to use it via:


By comparison, a MIDI buffer only holds 256 bytes. Since Scale values are 0-4095 you'd need to use 16-bit word access, which would limit the buffer to 128 values.

Another application for a large list of large values would be to store seed values for a DaqMusiq performance like GlossyFish or GlossyFishSticks. The starting seed controls the entire performance, so if you save the seeds of favorite performances to a file, you can easily modify the script to load the file and randomly select from the list to produce a "shuffle" that plays only your favorites.

Unlike MIDI buffers and User Variables, macro buffers are not automatically cleared at the start of each MIDI performance. This enables a macro to pass much more information to a MIDI script than is supported by the m0 to m9 special variables intended for that purpose.

See also Buffer File Load, Changes Script Buffer Operations, Changes Script Overview, Changes Script Editor, MIDI Voice Setup Dialogs, Pitch-to-MIDI dialog, Pitch Track Toolbox - Overview


Questions? Comments? Contact us!

We respond to ALL inquiries, typically within 24 hrs.
Over 30 Years of Innovative Instrumentation
© Copyright 2007 - 2017 by Interstellar Research
All rights reserved