Record and Play
constant Size { value: 192000 }
signal Buffer [Size] { default: 0.0 rate: none domain: AudioDomain reset: ButtonPressed }
signal Sample { default: 0.0 rate: streamRate domain: AudioDomain }
trigger ButtonPressed {}
trigger ButtonReleased {}
reaction Record {
output: Index
onExecution: Reset
terminateWhen: ButtonReleased or BufferFull
internalBlock: [
signal Index { default: 1 rate: AudioRate domain: AudioDomain reset: Reset },
trigger BufferFull {},
trigger Reset {}
]
streams: [
AudioIn[1] >> SetPort( index: Index ) >> Buffer; # SHORTHAND: AudioIn[1] >> Buffer[Index];
Index + 1 >> Index >> Compare ( value: Size operator: 'Greater' ) >> BufferFull;
]
}
reaction Play {
output: Output
onExecution: Reset
terminateWhen: ButtonPressed
internalBlock: [
signal Output { default: 0.0 rate: streamRate domain: streamDomain },
signal Index { default: 1 rate: streamRate domain: streamDomain reset: Reset },
trigger Reset {}
]
streams: [
Buffer >> GetPort ( index: Index ) >> Output; # SHORTHAND: Buffer[Index] >> Output;
Index + 1 >> Index >> Compare ( value: Size operator: 'Greater' ) >> Reset;
]
}
DigitalIn[1]
>> OnEdge ( edge: [ 'Rising' , 'Falling' ] )
>> [ ButtonPressed , ButtonReleased ];
>> [ Record (), Play () >> Sample ]; # Bundle OK since same input but no output
DigitalIn[1]
>> Select ( whenOn: AudioIn[1] whenOff: Sample ) # Can Sample be AudioRate through property?
>> AudioOut;
Two Sines
reaction Generator {
output: Output
onExecution: Reset
terminateWhen: Done
propertyName: 'frequency'
propertyDirection: in
propertyBlock: constant Frequency { value: 110 }
internalBlock: [
signal Output { default: 0.0 rate: streamRate domain: streamDomain},
signal Count { default: 0 rate: streamRate domain: streamDomain reset: Reset },
switch Done { default: off reset: Reset },
trigger Reset {}
]
streams: [
Oscillator ( frequency: Frequency amplitude: 0.5 reset: Reset ) >> Output;
Count + 1 >> Count >> Compare ( value: streamRate / Frequency operator: 'Greater' ) >> Done;
]
}
DigitalIn[1:2] >> Generator ( frequency: [220,440] ) >> Mix () >> AudioOut;