Author: axeld Date: 2009-12-03 18:57:13 +0100 (Thu, 03 Dec 2009) New Revision: 34469 Changeset: http://dev.haiku-os.org/changeset/34469/haiku Ticket: http://dev.haiku-os.org/ticket/4920 Added: haiku/trunk/src/tests/kits/media/soundplayer/Jamfile haiku/trunk/src/tests/kits/media/soundplayer/SimplePlayerTest.cpp Modified: haiku/trunk/src/tests/kits/media/Jamfile Log: * Added BeBook example quoted in bug #4920 as a test application into the repository. Modified: haiku/trunk/src/tests/kits/media/Jamfile =================================================================== --- haiku/trunk/src/tests/kits/media/Jamfile 2009-12-03 17:47:20 UTC (rev 34468) +++ haiku/trunk/src/tests/kits/media/Jamfile 2009-12-03 17:57:13 UTC (rev 34469) @@ -22,5 +22,6 @@ SubInclude HAIKU_TOP src tests kits media nodetest ; SubInclude HAIKU_TOP src tests kits media playwav ; SubInclude HAIKU_TOP src tests kits media mp3_reader_test ; +SubInclude HAIKU_TOP src tests kits media soundplayer ; SubInclude HAIKU_TOP src tests kits media wav_reader_test ; Added: haiku/trunk/src/tests/kits/media/soundplayer/Jamfile =================================================================== --- haiku/trunk/src/tests/kits/media/soundplayer/Jamfile (rev 0) +++ haiku/trunk/src/tests/kits/media/soundplayer/Jamfile 2009-12-03 17:57:13 UTC (rev 34469) @@ -0,0 +1,6 @@ +SubDir HAIKU_TOP src tests kits media soundplayer ; + +SimpleTest <test>SimplePlayerTest + : SimplePlayerTest.cpp + : media be $(TARGET_LIBSUPC++) +; Added: haiku/trunk/src/tests/kits/media/soundplayer/SimplePlayerTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/media/soundplayer/SimplePlayerTest.cpp (rev 0) +++ haiku/trunk/src/tests/kits/media/soundplayer/SimplePlayerTest.cpp 2009-12-03 17:57:13 UTC (rev 34469) @@ -0,0 +1,63 @@ +//! From BeBook examples. + + +#include <Application.h> +#include <Sound.h> +#include <SoundPlayer.h> + + +typedef struct cookie_record { + float value; + float direction; +} cookie_record; + + +void +BufferProc(void* _cookie, void* buffer, size_t size, + const media_raw_audio_format& format) +{ + // We're going to be cheap and only work for floating-point audio + + if (format.format != media_raw_audio_format::B_AUDIO_FLOAT) + return; + + // Now fill the buffer with sound! + + cookie_record* cookie = (cookie_record*)_cookie; + uint32 channelCount = format.channel_count; + size_t floatSize = size / 4; + float* buf = (float*)buffer; + + for (size_t i = 0; i < floatSize; i += channelCount) { + for (size_t j = 0; j < channelCount; j++) { + buf[i + j] = cookie->value; + } + + if (cookie->direction == 1.0 && cookie->value >= 1.0) + cookie->direction = -1.0; + else if (cookie->direction == -1.0 && cookie->value <= -1.0) + cookie->direction = 1.0; + + cookie->value += cookie->direction * (1.0 / 64.0); + } +} + + +int +main() +{ + BApplication app("application/dzwiek"); + + cookie_record cookie; + + cookie.value = 0.0; + cookie.direction = 1.0; + + BSoundPlayer player("wave_player", BufferProc, NULL, &cookie); + player.Start(); + player.SetHasData(true); + + sleep(5); + + player.Stop(); +}