app/chuck: pass Env to session connections, input support
- Initialize RtAudio with component env. - Mouse and keyboard input support. - Audio synthesis run scenarios. Fix #73
This commit is contained in:
committed by
Norman Feske
parent
a44aa90660
commit
73948ac1b2
131
run/chuck.run
Normal file
131
run/chuck.run
Normal file
@@ -0,0 +1,131 @@
|
||||
assert_spec x86
|
||||
|
||||
# Xmllint throws errors on inline chuck code
|
||||
proc check_xml_syntax {xml_file} { }
|
||||
|
||||
#
|
||||
# Build
|
||||
#
|
||||
|
||||
set build_components {
|
||||
core init
|
||||
app/chuck
|
||||
drivers/audio
|
||||
drivers/timer
|
||||
}
|
||||
|
||||
source ${genode_dir}/repos/base/run/platform_drv.inc
|
||||
append_platform_drv_build_components
|
||||
|
||||
build $build_components
|
||||
|
||||
create_boot_directory
|
||||
|
||||
#
|
||||
# Config
|
||||
#
|
||||
|
||||
append config {
|
||||
<config>
|
||||
<parent-provides>
|
||||
<service name="CPU"/>
|
||||
<service name="IO_MEM"/>
|
||||
<service name="IO_PORT"/>
|
||||
<service name="IRQ"/>
|
||||
<service name="LOG"/>
|
||||
<service name="PD"/>
|
||||
<service name="RAM"/>
|
||||
<service name="RM"/>
|
||||
<service name="ROM"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</default-route>
|
||||
<start name="timer">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides><service name="Timer"/></provides>
|
||||
</start>}
|
||||
|
||||
append_platform_drv_config
|
||||
|
||||
append config {
|
||||
<start name="audio_drv">
|
||||
<binary name="} [audio_drv_binary] {"/>
|
||||
<resource name="RAM" quantum="8M"/>
|
||||
<provides> <service name="Audio_out"/> </provides>
|
||||
<config/>
|
||||
</start>
|
||||
<start name="chuck">
|
||||
<resource name="RAM" quantum="32M"/>
|
||||
<config dac_channels="2" adc_channels="0">
|
||||
<libc stdout="/log" stderr="/log"/>
|
||||
<vfs> <log/>
|
||||
<inline name="test">
|
||||
// another candidate for lamest demo
|
||||
|
||||
// patch
|
||||
SinOsc s => JCRev r => dac;
|
||||
.5 => r.gain;
|
||||
.075 => r.mix;
|
||||
|
||||
// note number
|
||||
20 => float note;
|
||||
|
||||
// go up to 127
|
||||
while( note < 128 )
|
||||
{
|
||||
// convert MIDI note to hz
|
||||
Std.mtof( note ) => s.freq;
|
||||
// turn down the volume gradually
|
||||
.5 - (note/256.0) => s.gain;
|
||||
|
||||
// move up by whole step
|
||||
note + 2 => note;
|
||||
|
||||
// advance time
|
||||
.125::second => now;
|
||||
}
|
||||
|
||||
// turn off s
|
||||
0 => s.gain;
|
||||
// wait a bit
|
||||
2::second => now;
|
||||
|
||||
</inline>
|
||||
</vfs>
|
||||
<file path="/test"/>
|
||||
</config>
|
||||
<route>
|
||||
<any-service><parent/><any-child/></any-service>
|
||||
</route>
|
||||
</start>
|
||||
</config>}
|
||||
|
||||
install_config $config
|
||||
|
||||
#
|
||||
# Boot modules
|
||||
#
|
||||
|
||||
append boot_modules {
|
||||
core init ld.lib.so
|
||||
timer
|
||||
chuck
|
||||
libogg.lib.so
|
||||
libFLAC.lib.so
|
||||
libsndfile.lib.so
|
||||
libvorbis.lib.so
|
||||
pthread.lib.so
|
||||
stdcxx.lib.so
|
||||
libc.lib.so
|
||||
libm.lib.so
|
||||
} [audio_drv_binary] {
|
||||
}
|
||||
|
||||
append_platform_drv_boot_modules
|
||||
|
||||
build_boot_image $boot_modules
|
||||
|
||||
append qemu_args " -m 128 -nographic -soundhw es1370 "
|
||||
|
||||
run_genode_until {child "chuck" exited with exit value 0} 60
|
||||
193
run/chuck_keyboard.run
Normal file
193
run/chuck_keyboard.run
Normal file
@@ -0,0 +1,193 @@
|
||||
assert_spec x86
|
||||
|
||||
# Xmllint throws errors on inline chuck code
|
||||
proc check_xml_syntax {xml_file} { }
|
||||
|
||||
#
|
||||
# Build
|
||||
#
|
||||
|
||||
set build_components {
|
||||
core init
|
||||
app/chuck
|
||||
drivers/audio
|
||||
drivers/timer
|
||||
}
|
||||
|
||||
source ${genode_dir}/repos/base/run/platform_drv.inc
|
||||
append_platform_drv_build_components
|
||||
|
||||
lappend_if [have_spec ps2] build_components drivers/input/spec/ps2
|
||||
lappend_if [have_spec sdl] build_components drivers/framebuffer/spec/sdl
|
||||
|
||||
build $build_components
|
||||
|
||||
create_boot_directory
|
||||
|
||||
#
|
||||
# Config
|
||||
#
|
||||
|
||||
append config {
|
||||
<config>
|
||||
<parent-provides>
|
||||
<service name="CPU"/>
|
||||
<service name="IO_MEM"/>
|
||||
<service name="IO_PORT"/>
|
||||
<service name="IRQ"/>
|
||||
<service name="LOG"/>
|
||||
<service name="PD"/>
|
||||
<service name="RAM"/>
|
||||
<service name="RM"/>
|
||||
<service name="ROM"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</default-route>
|
||||
<start name="timer">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides><service name="Timer"/></provides>
|
||||
</start>}
|
||||
|
||||
append_platform_drv_config
|
||||
|
||||
append_if [have_spec ps2] config {
|
||||
<start name="ps2_drv">
|
||||
<resource name="RAM" quantum="2M"/>
|
||||
<provides><service name="Input"/></provides>
|
||||
<config verbose_keyboard="no" verbose_mouse="no" verbose_scancodes="no"/>
|
||||
<route>
|
||||
<service name="ROM"> <parent/> </service>
|
||||
<service name="CPU"> <parent/> </service>
|
||||
<service name="RAM"> <parent/> </service>
|
||||
<service name="PD"> <parent/> </service>
|
||||
<service name="IO_PORT"> <parent/> </service>
|
||||
<service name="LOG"> <parent/> </service>
|
||||
<service name="Platform"> <any-child/> </service>
|
||||
</route>
|
||||
</start>
|
||||
<alias name="input_drv" child="ps2_drv"/>}
|
||||
|
||||
append_if [have_spec sdl] config {
|
||||
<start name="fb_sdl">
|
||||
<resource name="RAM" quantum="4M"/>
|
||||
<provides> <service name="Input"/> <service name="Framebuffer"/> </provides>
|
||||
<route>
|
||||
<service name="ROM"> <parent/> </service>
|
||||
<service name="CPU"> <parent/> </service>
|
||||
<service name="RAM"> <parent/> </service>
|
||||
<service name="PD"> <parent/> </service>
|
||||
<service name="LOG"> <parent/> </service>
|
||||
<service name="Timer"> <child name="timer"/> </service>
|
||||
</route>
|
||||
</start>
|
||||
<alias name="input_drv" child="fb_sdl"/>}
|
||||
|
||||
append config {
|
||||
<start name="audio_drv">
|
||||
<binary name="} [audio_drv_binary] {"/>
|
||||
<resource name="RAM" quantum="8M"/>
|
||||
<provides> <service name="Audio_out"/> </provides>
|
||||
<config/>
|
||||
</start>
|
||||
<start name="chuck">
|
||||
<resource name="RAM" quantum="32M"/>
|
||||
<config dac_channels="2" adc_channels="0">
|
||||
<libc stdout="/log" stderr="/log"/>
|
||||
<vfs> <log/>
|
||||
<inline name="test">
|
||||
// HID
|
||||
Hid hi;
|
||||
HidMsg msg;
|
||||
|
||||
// which keyboard
|
||||
0 => int device;
|
||||
// get from command line
|
||||
if( me.args() ) me.arg(0) => Std.atoi => device;
|
||||
|
||||
// open keyboard (get device number from command line)
|
||||
if( !hi.openKeyboard( device ) ) me.exit();
|
||||
<<< "keyboard '" + hi.name() + "' ready", "" >>>;
|
||||
|
||||
// patch
|
||||
BeeThree organ => JCRev r => Echo e => Echo e2 => dac;
|
||||
r => dac;
|
||||
|
||||
// set delays
|
||||
240::ms => e.max => e.delay;
|
||||
480::ms => e2.max => e2.delay;
|
||||
// set gains
|
||||
.6 => e.gain;
|
||||
.3 => e2.gain;
|
||||
.05 => r.mix;
|
||||
0 => organ.gain;
|
||||
|
||||
// infinite event loop
|
||||
while( true )
|
||||
{
|
||||
// wait for event
|
||||
hi => now;
|
||||
|
||||
// get message
|
||||
while( hi.recv( msg ) )
|
||||
{
|
||||
// check
|
||||
if( msg.isButtonDown() )
|
||||
{
|
||||
Std.mtof( msg.which + 45 ) => float freq;
|
||||
if( freq > 20000 ) continue;
|
||||
|
||||
freq => organ.freq;
|
||||
.5 => organ.gain;
|
||||
1 => organ.noteOn;
|
||||
|
||||
80::ms => now;
|
||||
}
|
||||
else
|
||||
{
|
||||
0 => organ.noteOff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</inline>
|
||||
</vfs>
|
||||
<file path="/test"/>
|
||||
</config>
|
||||
<route>
|
||||
<any-service><parent/><any-child/></any-service>
|
||||
</route>
|
||||
</start>
|
||||
</config>}
|
||||
|
||||
install_config $config
|
||||
|
||||
#
|
||||
# Boot modules
|
||||
#
|
||||
|
||||
append boot_modules {
|
||||
core init ld.lib.so
|
||||
timer
|
||||
chuck
|
||||
libogg.lib.so
|
||||
libFLAC.lib.so
|
||||
libsndfile.lib.so
|
||||
libvorbis.lib.so
|
||||
pthread.lib.so
|
||||
stdcxx.lib.so
|
||||
libc.lib.so
|
||||
libm.lib.so
|
||||
} [audio_drv_binary] {
|
||||
}
|
||||
|
||||
lappend_if [have_spec ps2] boot_modules ps2_drv
|
||||
lappend_if [have_spec sdl] boot_modules fb_sdl
|
||||
|
||||
append_platform_drv_boot_modules
|
||||
|
||||
build_boot_image $boot_modules
|
||||
|
||||
append qemu_args " -m 128 -nographic -soundhw es1370 "
|
||||
|
||||
run_genode_until forever
|
||||
227
run/chuck_mouse.run
Normal file
227
run/chuck_mouse.run
Normal file
@@ -0,0 +1,227 @@
|
||||
assert_spec x86
|
||||
|
||||
# Xmllint throws errors on inline chuck code
|
||||
proc check_xml_syntax {xml_file} { }
|
||||
|
||||
#
|
||||
# Build
|
||||
#
|
||||
|
||||
set build_components {
|
||||
core init
|
||||
app/chuck
|
||||
drivers/audio
|
||||
drivers/timer
|
||||
}
|
||||
|
||||
source ${genode_dir}/repos/base/run/platform_drv.inc
|
||||
append_platform_drv_build_components
|
||||
|
||||
lappend_if [have_spec ps2] build_components drivers/input/spec/ps2
|
||||
lappend_if [have_spec sdl] build_components drivers/framebuffer/spec/sdl
|
||||
|
||||
build $build_components
|
||||
|
||||
create_boot_directory
|
||||
|
||||
#
|
||||
# Config
|
||||
#
|
||||
|
||||
append config {
|
||||
<config>
|
||||
<parent-provides>
|
||||
<service name="CPU"/>
|
||||
<service name="IO_MEM"/>
|
||||
<service name="IO_PORT"/>
|
||||
<service name="IRQ"/>
|
||||
<service name="LOG"/>
|
||||
<service name="PD"/>
|
||||
<service name="RAM"/>
|
||||
<service name="RM"/>
|
||||
<service name="ROM"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</default-route>
|
||||
<start name="timer">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides><service name="Timer"/></provides>
|
||||
</start>}
|
||||
|
||||
append_platform_drv_config
|
||||
|
||||
append_if [have_spec ps2] config {
|
||||
<start name="ps2_drv">
|
||||
<resource name="RAM" quantum="2M"/>
|
||||
<provides><service name="Input"/></provides>
|
||||
<config verbose_keyboard="no" verbose_mouse="no" verbose_scancodes="no"/>
|
||||
<route>
|
||||
<service name="ROM"> <parent/> </service>
|
||||
<service name="CPU"> <parent/> </service>
|
||||
<service name="RAM"> <parent/> </service>
|
||||
<service name="PD"> <parent/> </service>
|
||||
<service name="IO_PORT"> <parent/> </service>
|
||||
<service name="LOG"> <parent/> </service>
|
||||
<service name="Platform"> <any-child/> </service>
|
||||
</route>
|
||||
</start>
|
||||
<alias name="input_drv" child="ps2_drv"/>}
|
||||
|
||||
append_if [have_spec sdl] config {
|
||||
<start name="fb_sdl">
|
||||
<resource name="RAM" quantum="4M"/>
|
||||
<provides> <service name="Input"/> <service name="Framebuffer"/> </provides>
|
||||
<route>
|
||||
<service name="ROM"> <parent/> </service>
|
||||
<service name="CPU"> <parent/> </service>
|
||||
<service name="RAM"> <parent/> </service>
|
||||
<service name="PD"> <parent/> </service>
|
||||
<service name="LOG"> <parent/> </service>
|
||||
<service name="Timer"> <child name="timer"/> </service>
|
||||
</route>
|
||||
</start>
|
||||
<alias name="input_drv" child="fb_sdl"/>}
|
||||
|
||||
append config {
|
||||
<start name="audio_drv">
|
||||
<binary name="} [audio_drv_binary] {"/>
|
||||
<resource name="RAM" quantum="8M"/>
|
||||
<provides> <service name="Audio_out"/> </provides>
|
||||
<config/>
|
||||
</start>
|
||||
<start name="chuck">
|
||||
<resource name="RAM" quantum="32M"/>
|
||||
<config dac_channels="2" adc_channels="0">
|
||||
<libc stdout="/log" stderr="/log"/>
|
||||
<vfs> <log/>
|
||||
<inline name="test">
|
||||
// name: mouse-fm.ck
|
||||
// desc: uses first X/Y axes of a mouse to control mf and index for FM
|
||||
// author: Spencer Salazar
|
||||
|
||||
// which mouse
|
||||
0 => int device;
|
||||
// get from command line
|
||||
if( me.args() ) me.arg(0) => Std.atoi => device;
|
||||
|
||||
// modulator to carrier
|
||||
SinOsc m => SinOsc c => Envelope e => dac;
|
||||
|
||||
// carrier frequency
|
||||
220 => c.freq;
|
||||
// modulator frequency
|
||||
550 => m.freq;
|
||||
// index of modulation
|
||||
1000 => m.gain;
|
||||
|
||||
// phase modulation is FM synthesis (sync is 2)
|
||||
2 => c.sync;
|
||||
|
||||
// attack
|
||||
10::ms => e.duration;
|
||||
.5 => e.gain;
|
||||
// variables
|
||||
int base;
|
||||
float a0;
|
||||
float a1;
|
||||
float a2;
|
||||
int count;
|
||||
|
||||
// start things
|
||||
set( base, a0, a1, a2 );
|
||||
|
||||
// hid objects
|
||||
Hid hi;
|
||||
HidMsg msg;
|
||||
|
||||
// try
|
||||
if( !hi.openMouse( device ) ) me.exit();
|
||||
<<< "mouse '" + hi.name() + "' ready...", "" >>>;
|
||||
|
||||
// infinite time loop
|
||||
while( true )
|
||||
{
|
||||
// wait on event
|
||||
hi => now;
|
||||
// loop over messages
|
||||
while( hi.recv( msg ) )
|
||||
{
|
||||
if( msg.isMouseMotion() )
|
||||
{
|
||||
msg.deltaX * .001 + a0 => a0;
|
||||
//else if( msg.which == 1 ) msg.fdata => a1;
|
||||
msg.deltaY * .001 + a1 => a1;
|
||||
set( base, a0, a1, a2 );
|
||||
}
|
||||
|
||||
else if( msg.isButtonDown() )
|
||||
{
|
||||
msg.which => base;
|
||||
count++;
|
||||
if( count == 1 ) e.keyOn();
|
||||
set( base, a0, a1, a2 );
|
||||
}
|
||||
|
||||
else if( msg.isButtonUp() )
|
||||
{
|
||||
msg.which => base;
|
||||
count--;
|
||||
if( !count ) e.keyOff();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// mapping function
|
||||
fun void set( int base, float v0, float v1, float v2 )
|
||||
{
|
||||
// modulator frequency
|
||||
( 500 + 5*base + ( 500 * v0) ) => m.freq;
|
||||
// carrier frequency
|
||||
( 220 + (220 * v2) ) => c.freq;
|
||||
// index of modulation
|
||||
( 1000 * (v1+1) ) => m.gain;
|
||||
<<< "carrier:", c.freq(), "modulator:", m.freq(), "index:", m.gain() >>>;
|
||||
}
|
||||
|
||||
</inline>
|
||||
</vfs>
|
||||
<file path="/test"/>
|
||||
</config>
|
||||
<route>
|
||||
<any-service><parent/><any-child/></any-service>
|
||||
</route>
|
||||
</start>
|
||||
</config>}
|
||||
|
||||
install_config $config
|
||||
|
||||
#
|
||||
# Boot modules
|
||||
#
|
||||
|
||||
append boot_modules {
|
||||
core init ld.lib.so
|
||||
timer
|
||||
chuck
|
||||
libogg.lib.so
|
||||
libFLAC.lib.so
|
||||
libsndfile.lib.so
|
||||
libvorbis.lib.so
|
||||
pthread.lib.so
|
||||
stdcxx.lib.so
|
||||
libc.lib.so
|
||||
libm.lib.so
|
||||
} [audio_drv_binary] {
|
||||
}
|
||||
|
||||
lappend_if [have_spec ps2] boot_modules ps2_drv
|
||||
lappend_if [have_spec sdl] boot_modules fb_sdl
|
||||
|
||||
append_platform_drv_boot_modules
|
||||
|
||||
build_boot_image $boot_modules
|
||||
|
||||
append qemu_args " -m 128 -nographic -soundhw es1370 "
|
||||
|
||||
run_genode_until forever
|
||||
Reference in New Issue
Block a user