Add a simpler test for BPushGameSound and attempt to fix the most striking mistakes in there.
This commit is contained in:
@@ -60,10 +60,10 @@ BPushGameSound::lock_status
|
|||||||
BPushGameSound::LockNextPage(void **out_pagePtr, size_t *out_pageSize)
|
BPushGameSound::LockNextPage(void **out_pagePtr, size_t *out_pageSize)
|
||||||
{
|
{
|
||||||
// the user can not lock every page
|
// the user can not lock every page
|
||||||
if (fPageLocked->CountItems() > fPageCount - 3)
|
if (fPageLocked->CountItems() > fPageCount - 1)
|
||||||
return lock_failed;
|
return lock_failed;
|
||||||
|
|
||||||
// the user cann't lock a page being played
|
// the user can't lock a page being played
|
||||||
if (fLockPos < fPlayPos
|
if (fLockPos < fPlayPos
|
||||||
&& fLockPos + fPageSize > fPlayPos)
|
&& fLockPos + fPageSize > fPlayPos)
|
||||||
return lock_failed;
|
return lock_failed;
|
||||||
@@ -74,7 +74,7 @@ BPushGameSound::LockNextPage(void **out_pagePtr, size_t *out_pageSize)
|
|||||||
|
|
||||||
// move the locker to the next page
|
// move the locker to the next page
|
||||||
fLockPos += fPageSize;
|
fLockPos += fPageSize;
|
||||||
if (fLockPos > fBufferSize)
|
if (fLockPos >= fBufferSize)
|
||||||
fLockPos = 0;
|
fLockPos = 0;
|
||||||
|
|
||||||
*out_pagePtr = lockPage;
|
*out_pagePtr = lockPage;
|
||||||
|
|||||||
@@ -4,3 +4,8 @@ SimpleTest push_game_sound_test
|
|||||||
: push_game_sound_test.cpp
|
: push_game_sound_test.cpp
|
||||||
: game media be $(TARGET_LIBSUPC++)
|
: game media be $(TARGET_LIBSUPC++)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
SimpleTest push_game_sound_sine
|
||||||
|
: push_game_sound_sine.cpp
|
||||||
|
: game be $(TARGET_LIBSUPC++)
|
||||||
|
;
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012, Adrien Destugues <[email protected]>
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <Entry.h>
|
||||||
|
#include <InterfaceDefs.h>
|
||||||
|
#include <MediaFile.h>
|
||||||
|
#include <MediaTrack.h>
|
||||||
|
#include <PushGameSound.h>
|
||||||
|
|
||||||
|
|
||||||
|
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 [<frames per part> <parts>]\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 > 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 = 48000;
|
||||||
|
gsFormat.channel_count = 1;
|
||||||
|
gsFormat.format = gs_audio_format::B_GS_S16;
|
||||||
|
gsFormat.byte_order = B_MEDIA_LITTLE_ENDIAN;
|
||||||
|
gsFormat.buffer_size = framesPerBufferPart;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
memset(buffer, 0, bufferSize);
|
||||||
|
|
||||||
|
if (pushGameSound.StartPlaying() != B_OK) {
|
||||||
|
printf("cannot start playback\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("playing, press [esc] to exit...\n");
|
||||||
|
|
||||||
|
key_info keyInfo;
|
||||||
|
|
||||||
|
size_t sampleCount = framesPerBufferPart * bufferPartCount;
|
||||||
|
for(size_t pos = 0; pos < sampleCount; pos++)
|
||||||
|
{
|
||||||
|
*(int16_t*)(buffer + pos * sizeof(int16_t))
|
||||||
|
= (int16_t)(2000 * sin(pos * gsFormat.frame_rate
|
||||||
|
/ ((float)sampleCount * 440)));
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
usleep(1000000 * framesPerBufferPart / gsFormat.frame_rate);
|
||||||
|
|
||||||
|
// check escape key state
|
||||||
|
if (get_key_info(&keyInfo) != B_OK) {
|
||||||
|
printf("\nkeyboard state read error\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((keyInfo.key_states[0] & 0x40) != 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
pushGameSound.StopPlaying();
|
||||||
|
|
||||||
|
printf("\nfinished.\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user