diff --git a/src/tests/kits/game/Jamfile b/src/tests/kits/game/Jamfile index a88eba4973..9723784540 100644 --- a/src/tests/kits/game/Jamfile +++ b/src/tests/kits/game/Jamfile @@ -5,6 +5,7 @@ SubInclude HAIKU_TOP src tests kits game direct_window_test ; SubInclude HAIKU_TOP src tests kits game direct_window_info_test ; SubInclude HAIKU_TOP src tests kits game file_game_sound_test ; SubInclude HAIKU_TOP src tests kits game push_game_sound_test ; +SubInclude HAIKU_TOP src tests kits game push_game_sound_test2 ; SubInclude HAIKU_TOP src tests kits game set_mouse_position_test ; SubInclude HAIKU_TOP src tests kits game simple_game_sound_test ; SubInclude HAIKU_TOP src tests kits game page_flipper ; diff --git a/src/tests/kits/game/push_game_sound_test2/Jamfile b/src/tests/kits/game/push_game_sound_test2/Jamfile new file mode 100644 index 0000000000..e2a7356f3d --- /dev/null +++ b/src/tests/kits/game/push_game_sound_test2/Jamfile @@ -0,0 +1,6 @@ +SubDir HAIKU_TOP src tests kits game push_game_sound_test2 ; + +SimpleTest push_game_sound_test2 + : push_game_sound_test.cpp + : game media be $(TARGET_LIBSUPC++) +; diff --git a/src/tests/kits/game/push_game_sound_test2/push_game_sound_test.cpp b/src/tests/kits/game/push_game_sound_test2/push_game_sound_test.cpp new file mode 100644 index 0000000000..e1343f603a --- /dev/null +++ b/src/tests/kits/game/push_game_sound_test2/push_game_sound_test.cpp @@ -0,0 +1,86 @@ +/* + * Copyright 2009, Krzysztof Ćwiertnia (krzysiek.bmkx_gmail_com). + * Copyright 2011, Adrien Destugues (pulkomandy@pulkomandy.ath.cx) + * All Rights Reserved. Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + +#include +#include +#include +#include + + +int +main(int argc, char *argv[]) +{ + // 256 frames * 4 buffer parts * 2 channels * 2 bytes per sample + // will give us internal buffer of 4096 bytes + size_t framesPerBufferPart = 256; + size_t bufferPartCount = 4; + + if (argc != 1 && argc != 3) { + printf("Usage: %s [ ]\n", + argv[0]); + return 0; + } + + if (argc == 3) { + size_t size = strtoul(argv[1], NULL, 10); + if (size > 0) + framesPerBufferPart = size; + + size = strtoul(argv[2], NULL, 10); + if (size == 1) { + printf("at least 2 buffer parts are needed\n"); + return 1; + } + if (size > 0) + bufferPartCount = size; + } + + printf("frames per buffer part: %ld\n", framesPerBufferPart); + printf("buffer part count: %ld\n", bufferPartCount); + + gs_audio_format gsFormat; + memset(&gsFormat, 0, sizeof(gsFormat)); + gsFormat.frame_rate = 44100; + gsFormat.channel_count = 1; + gsFormat.format = gs_audio_format::B_GS_U8; + + BPushGameSound pushGameSound(framesPerBufferPart, &gsFormat, + bufferPartCount); + if (pushGameSound.InitCheck() != B_OK) { + printf("trouble initializing push game sound: %s\n", + strerror(pushGameSound.InitCheck())); + return 1; + } + + uint8 *buffer; + size_t bufferSize; + if (pushGameSound.LockForCyclic((void **)&buffer, &bufferSize) + != BPushGameSound::lock_ok) { + printf("cannot lock buffer\n"); + return 1; + } + + for (int i = 0; i < bufferSize; i++) + buffer[i] = i; + + if (pushGameSound.StartPlaying() != B_OK) { + printf("cannot start playback\n"); + return 1; + } + + getchar(); + + pushGameSound.StopPlaying(); + + printf("\nfinished.\n"); + + return 0; +}