Programmer Guide/Command Reference/SEGMENT: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
 
(56 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
Evaluate a segment expression.
The <code>SEGMENT</code> command evaluates a segment expression in various ways returning a string indicating the ''begin'' (<var>bseg</var>), the ''end'' (<var>eseg</var>) and the ''length'' (<var>lseg</var>) of the segment addressed by the respective segment expression.


;Usage 1:<code>SEGMENT <var>segexpr</var> [/S | /?]</code>
<var>bseg</var> <var>eseg</var> <var>lseg</var>
:;<var>segexpr<var>:the segment expression to be evaluated
:;<code>/S</code>, <code>/?</code>:silent error handling; generate warnings rather than errors.
:This command evaluates the segment expression <var>segexpr</var>, using the sampling rate (''sr'' in Hz) and the length (''l'' in samples) of the current soundfile (see [[../LOAD|LOAD SOUNDFILE]]).


;Usage 2:<code>SEGMENT <var>segexpr sr l</var> [/S | /?]</code>
== {{anchor|usage1|Based on the current sound file}} ==
:;<var>sr</var>:sampling rate in Hz
:;<var>l</var>:maximum signal duration in samples
:This command evaluates the segment expression <var>segexpr</var>, using the specified parameters <var>sr</var> and <var>l</var>.


;Usage 3:<code>SEGMENT <var>segexpr xmlfile srattr segtag idattr pattr lattr</var></code>
Evaluate the segment expression <var>segexpr</var>, using the sampling rate and the length of the [[Programmer_Guide/Concepts/Current_Soundfile|current sound file]] (see [[../LOAD|LOAD SOUNDFILE]]):
:;<var>xmlfile<var>:a [[Programmer_Guide/Shell_Items/File|xml-file item]] containing the metadata; the selected element must contain soundfile metadata and the segment definitions must be stored as child elements
:;<var>srattr</var>:the xml attribute of the selected element containing the sampling rate (in Hz)
:;<var>segtag</var>:the xml element tag used for segment definitions
:;<var>idattr, pattr, lattr</var>:the xml attributes used in the segment definition elements to specifiy the segment id (<var>idattr</var>) and its starting position (<var>pattr</var>) and length (<var>lattr</var>)
:This command evaluates the segment expression <var>segexpr</var>, using the sampling rate and the segment definitions stored in the [[Programmer_Guide/Shell_Items/File|xml-file item]].  


SEGMENT <var>segexpr</var> [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent | /?]] ]
:;<var>segexpr</var>:the segment expression to be evaluated
:;[[Programmer_Guide/Command_Reference_Options/Silent|<code>/Silent</code>]], <code>/?</code>:silent error handling; generate warnings rather than errors.


|use
== {{anchor|usage2|Based on supplied data}} ==
|-
:<code>
:;<var>segexpr</var>:segment expression (see description)
;Result 1:<code>begin end length</code> (evaluated expression in samples) or an '''empty string''' (on error)
;Description 1:The expression is evaluated using the sampling rate and length of the current soundfile. If no soundfile is selected (see [[../LOAD|LOAD SOUNDFILE]] or the expression is ill-formed, the command fails.
:
==SEGMENT==


Convert a segment expression into it's equivalent in samples or extract a segment expression from a segment element in an XML file item. If an XML file is specified, then the currently selected audio set is searched for an element with the tag <var>segTag</var> and the id <var>idAttr</var>.
Evaluate the segment expression <var>segexpr</var>, using the specified sampling rate and length.


=====Usage:=====
SEGMENT <var>segexpr</var> <var>sr</var> <var>l</var> [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent | /?]] ]
 
:;<var>segexpr</var>:the segment expression to be evaluated
<code><var>var</var> := SEGMENT <var>segmentExpression</var> [ <var>samplingRate</var> <var>sampleCount</var> ] [ /S ]</code>
:;<var>sr</var>:sampling rate in Hz
 
:;<var>l</var>:maximum signal duration in samples
<code><var>var</var> := SEGMENT <var>segmentExpression</var> <var>xmlFile</var> <var>srAttr</var> <var>segTag</var> <var>idAttr</var> <var>pAttr</var> <var>lAttr</var> [ /S ]</code>
 
=====Parameters:=====
 
;<var>segmentExpression</var>
 
:A valid segment expression. If <var>samplingRate</var> and <var>sampleCount</var> are specified, <var>segmentExpression</var> cannot contain segment names. See Specifying Signal Segments for details about valid segment expressions. Note that if this is the only argument, the parameters of the current soundfile are used for calculations.
 
;<var>samplingRate</var>
 
:The sampling rate to use for calculations. If this parameter is specified, it takes precedence over the sampling rate of the current soundfile.
 
;<var>sampleCount</var>
 
:The number of samples.
 
;<var>xmlFile</var>
 
:An XML file item id. The file's selected element must be an audio set. The status and context of the file are not changed by the <code>SEGMENT</code> command.
 
;<var>srAttr</var>
 
:The name of the sampling rate attribute in the currently selected audio set. E.g. '<code>SR</code>' for an {{STX}} <code>AFile</code> element.
 
;<var>segTag</var>
 
:The XML tag containing the segment data in the currently selected audio set. E.g '<code>ASeg</code>'.


;<var>idAttr</var>
== {{anchor|usage3|Based on data from an XML segment definition}} ==


:The id of the segment to evaluate.
Evaluate the segment expression <var>segexpr</var>, using the sampling rate and the segment definitions stored in the [[Programmer_Guide/Shell_Items/File|XML file item]] <var>xmlfile</var>.


;<var>pAttr</var>
SEGMENT <var>segexpr</var> <var>xmlfile</var> <var>srattr</var> <var>segtag</var> <var>idattr</var> <var>pattr </var> <var>lattr</var> [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent | /?]] ]
:;<var>segexpr</var>:the segment expression to be evaluated
:;<var>xmlfile</var>:an [[Programmer_Guide/Shell_Items/File|XML file item]] containing the metadata; the selected element must contain sound file metadata, and the segment definitions must be stored as child elements
:;<var>srattr</var>:the XML attribute of the selected element containing the sampling rate (in Hz)
:;<var>segtag</var>:the XML element tag used for segment definitions
:;<var>idattr</var>, <var>pattr</var> and <var>lattr</var>:the XML attributes used in the segment definition elements to specifiy the segment id (<var>idattr</var>) and its starting position (<var>pattr</var>) and length (<var>lattr</var>)


:The name of the attribute containing the starting address in samples. E.g. '<code>P</code>' in an <code>ASeg</code> element.
==Result==
;success: <code>''bseg eseg lseg''</code> - the return value is the ''begin'' (''bseg''), the ''end'' (''eseg'') and the ''length'' (''lseg'') of the segment specified by the segment expression. The variable <var>RC</var> is set to 0.  
:Note: If the segment expression specifies a label at position ''lpos'', the return value is <code><var>lpos</var> <var>lpos</var> '''0'''</code>.
;error: the command returns an empty string. As usual, the error, or warning code (0 on success) is stored in the variable <var>RC</var>.


;<var>lAttr</var>
==Segment Expressions ==
{{:Programmer_Guide/General_Descriptions/Segment_Expressions}}


:The name of the attribute containing the length of the segment in samples. E.g. '<code>L</code>' in an <code>ASeg</code> element.
==Further Examples==
Address 0 samples to 4 seconds of the current soundfile:
segment 0_4s     


;<var>/S</var>
Address 2 seconds in the middle of the current soundfile:
segment 50%-1s_+2s


:If specified, errors will generate warning messages rather than error messages. See The Silent Flag for details.
Address 1 second to 1 second plus 100 samples of a signal with a 10kHz sampling rate and a 5 seconds duration:
segment 1s_+100 10000 5*10000


=====Result:=====
Note: XML attributes and element names and segment ids are case sensitive!


Returns a string in the following format:
Address the whole signal of segment '''seg1''':
segment seg1 ''xmlfile'' SR ASeg ID P L 


<code>'beginning end length'</code>
Address the signal from the beginning of '''seg1''' to the end of '''seg1''' plus 2 seconds:
segment seg1:b_seg2:e+2s ''xmlfile'' SR ASeg ID P L


All values are in samples.
==See also==
[[Programmer_Guide/Class_Library/BDataSet|class BDataSet]], [[../LOAD|LOAD SOUNDFILES]], [[../INT|INT]], [[../NUM|NUM]], [[Programmer_Guide/Shell_Items/File|file item (xml)]]

Latest revision as of 11:01, 17 April 2018

The SEGMENT command evaluates a segment expression in various ways returning a string indicating the begin (bseg), the end (eseg) and the length (lseg) of the segment addressed by the respective segment expression.

bseg eseg lseg

Based on the current sound file

Evaluate the segment expression segexpr, using the sampling rate and the length of the current sound file (see LOAD SOUNDFILE):

SEGMENT segexpr [ /Silent | /? ]
segexpr
the segment expression to be evaluated
/Silent, /?
silent error handling; generate warnings rather than errors.

Based on supplied data

Evaluate the segment expression segexpr, using the specified sampling rate and length.

SEGMENT segexpr sr l [ /Silent | /? ]
segexpr
the segment expression to be evaluated
sr
sampling rate in Hz
l
maximum signal duration in samples

Based on data from an XML segment definition

Evaluate the segment expression segexpr, using the sampling rate and the segment definitions stored in the XML file item xmlfile.

SEGMENT segexpr xmlfile srattr segtag idattr pattr  lattr [ /Silent | /? ]
segexpr
the segment expression to be evaluated
xmlfile
an XML file item containing the metadata; the selected element must contain sound file metadata, and the segment definitions must be stored as child elements
srattr
the XML attribute of the selected element containing the sampling rate (in Hz)
segtag
the XML element tag used for segment definitions
idattr, pattr and lattr
the XML attributes used in the segment definition elements to specifiy the segment id (idattr) and its starting position (pattr) and length (lattr)

Result

success
bseg eseg lseg - the return value is the begin (bseg), the end (eseg) and the length (lseg) of the segment specified by the segment expression. The variable RC is set to 0.
Note: If the segment expression specifies a label at position lpos, the return value is lpos lpos 0.
error
the command returns an empty string. As usual, the error, or warning code (0 on success) is stored in the variable RC.

Segment Expressions

STx uses a special syntax to address a segment of a sound file. The syntax allows for the mixed use of segment names and time values in a complex expression known as a segment expression. Segment expressions may be used in all commands and dialogs where a signal segment (or a position/duration) may be specified (exceptions are described in the Command Reference). In dialogs, the supported value formats/types are always described in the control/dialog caption.

Segment Expression

A segment expression addresses a part of a sound file with a non-zero duration. It can consist of (1) a segment name, or (2) of two label expressions (see below) specifying the beginning and the end of the segment, or (3) of two label expressions (see below) specifying the position of the segment and its duration.

segment expression description
labelexpression_labelexpression (beginning and end)
labelexpression_+labelexpression (beginning and duration)
labelexpression_-labelexpression (end and duration)

Label Expression

A label expression is a position in a sound file (e.g. the begin/end of a segment) or the duration of a segment. A label expression may consist of a sign (+/-) and one or more values formatted as described below and combined with the operators + (add) or – (subtract). If a label expression contains blanks, it must be quoted when used as an argument.
label expression description value in samples comment
x x samples x
xs x seconds x * sr
xms x milliseconds x / 1000 * sr
xHz periode of a signal with x Hz sr / x
xkHz periode of a signal with x kHz sr / (x * 1000)
x% x percent of the signal length l * x / 100 only with this and that version of the SEGMENT command
x%% x per mill of the signal length l * x / 1000 only with this and that version of the SEGMENT command
segid begin and length of the segment with id segid only with this version of the SEGMENT command
segid:b begin of the segment with id segid only with this version of the SEGMENT command
segid:e end of the segment with id segid only with this version of the SEGMENT command
segid:l length of the segment with id segid only with this version of the SEGMENT command
Where: x is a number
sr is the signal sampling rate in Hz
l is the signal length in samples (e.g. soundfile length)
segid is the ID of a segment defined in the XML file

Examples

Below you will find a short list of examples.

0_4s
addresses the segment from sample 0 (the beginning) to 4 seconds into the file
SegmentA:B+100_+10s
addresses 100 samples after the beginning of an existing segment called "SegmentB" for a duration of ten seconds
SegmentB
addresses an existing segment called "SegmentB"
SegmentA:B_SegmentB:E
addresses the range from the beginning of SegmentA to the end of SegmentB
SegmentB:E_-100ms
addresses the range starting 100 milliseconds before the end of SegmentB and ending at the end of SegmentB

Notes

For some expressions, the values number% (percentage of the full duration) and number%% (thousandths of the full duration) can be used, but only if the full signal is available/defined (e.g. for envelopes of sequence signals). A segmentname can only be used if a sound file or an audio-element of an XML file is involved in the expression evaluation. Segment names are case sensitive.

Time Expression

Further Examples

Address 0 samples to 4 seconds of the current soundfile:

segment 0_4s       

Address 2 seconds in the middle of the current soundfile:

segment 50%-1s_+2s

Address 1 second to 1 second plus 100 samples of a signal with a 10kHz sampling rate and a 5 seconds duration:

segment 1s_+100 10000 5*10000 

Note: XML attributes and element names and segment ids are case sensitive!

Address the whole signal of segment seg1:

segment seg1 xmlfile SR ASeg ID P L  

Address the signal from the beginning of seg1 to the end of seg1 plus 2 seconds:

segment seg1:b_seg2:e+2s xmlfile SR ASeg ID P L

See also

class BDataSet, LOAD SOUNDFILES, INT, NUM, file item (xml)

Navigation menu

Personal tools