From 7228af3083a2d459075b52fb05391654306c06c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 3 Dec 2009 17:57:13 +0000 Subject: [PATCH] * Added BeBook example quoted in bug #4920 as a test application into the repository. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34469 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/kits/media/Jamfile | 1 + src/tests/kits/media/soundplayer/Jamfile | 6 ++ .../media/soundplayer/SimplePlayerTest.cpp | 63 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 src/tests/kits/media/soundplayer/Jamfile create mode 100644 src/tests/kits/media/soundplayer/SimplePlayerTest.cpp diff --git a/src/tests/kits/media/Jamfile b/src/tests/kits/media/Jamfile index 3f29b048f6..3fe7c21801 100644 --- a/src/tests/kits/media/Jamfile +++ b/src/tests/kits/media/Jamfile @@ -22,5 +22,6 @@ SubInclude HAIKU_TOP src tests kits media notificationtest ; 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 ; diff --git a/src/tests/kits/media/soundplayer/Jamfile b/src/tests/kits/media/soundplayer/Jamfile new file mode 100644 index 0000000000..dae87de95a --- /dev/null +++ b/src/tests/kits/media/soundplayer/Jamfile @@ -0,0 +1,6 @@ +SubDir HAIKU_TOP src tests kits media soundplayer ; + +SimpleTest SimplePlayerTest + : SimplePlayerTest.cpp + : media be $(TARGET_LIBSUPC++) +; diff --git a/src/tests/kits/media/soundplayer/SimplePlayerTest.cpp b/src/tests/kits/media/soundplayer/SimplePlayerTest.cpp new file mode 100644 index 0000000000..06881c9061 --- /dev/null +++ b/src/tests/kits/media/soundplayer/SimplePlayerTest.cpp @@ -0,0 +1,63 @@ +//! From BeBook examples. + + +#include +#include +#include + + +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(); +}