diff --git a/repos/dde_bsd/run/audio_out.run b/repos/dde_bsd/run/audio_out.run index d191a186a..d10d0d846 100644 --- a/repos/dde_bsd/run/audio_out.run +++ b/repos/dde_bsd/run/audio_out.run @@ -62,6 +62,9 @@ append_if $use_mixer config { + + + @@ -130,4 +133,4 @@ append qemu_args " -nographic -soundhw es1370 " # For obvious reasons the timeout depends on the total # length of the used sample file. # -run_genode_until {.*played.*1 time\(s\)} 60 +run_genode_until {.*played.*1 time\(s\)} 300 diff --git a/repos/os/include/audio/source.h b/repos/os/include/audio/source.h new file mode 100644 index 000000000..29c19e115 --- /dev/null +++ b/repos/os/include/audio/source.h @@ -0,0 +1,81 @@ +/* + * \brief Audio session producer class + * \author Emery Hemingway + * \date 2019-06-13 + */ + +/* + * Copyright (C) 2019 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + + +/* Genode includes */ +#include + +namespace Audio +{ + struct Source; + class Stereo_out; +}; + + +struct Audio::Source +{ + virtual ~Source() { } + virtual bool fill(float *left, float *right, Genode::size_t samples) = 0; +}; + + +class Audio::Stereo_out +{ + private: + + Audio::Source &_source; + + Audio_out::Connection _left, _right; + + Genode::Io_signal_handler _progress_handler; + + public: + + Stereo_out(Genode::Env &env, Audio::Source &source) + : _source(source) + , _left (env, "left", false, false) + , _right(env, "right", false, false) + , _progress_handler(env.ep(), *this, &Stereo_out::progress) + { + _left.progress_sigh(_progress_handler); + } + + void start() + { + _left.start(); + _right.start(); + } + + void stop() + { + _left.stop(); + _right.stop(); + } + + void progress() + { + using namespace Audio_out; + + while (!_left.stream()->full()) { + Packet *left = _left.stream()->alloc(); + unsigned pos = _left.stream()->packet_position(left); + Packet *right = _right.stream()->get(pos); + + if (!_source.fill(left->content(), right->content(), PERIOD)) + break; + + _left.submit(left); + _right.submit(right); + } + } +}; diff --git a/repos/os/src/test/audio_out/main.cc b/repos/os/src/test/audio_out/main.cc index 25c7e56b8..3d93a883d 100644 --- a/repos/os/src/test/audio_out/main.cc +++ b/repos/os/src/test/audio_out/main.cc @@ -15,7 +15,7 @@ * under the terms of the GNU Affero General Public License version 3. */ -#include +#include