game kit: Style and whitespace cleanup. No functional change.

This commit is contained in:
Alexander von Gluck IV
2012-02-08 17:38:59 -06:00
parent 1b6bc2675f
commit 2066acfbc5
10 changed files with 547 additions and 477 deletions
+44 -27
View File
@@ -1,12 +1,13 @@
/* /*
* Copyright 2001-2007, Haiku Inc. * Copyright 2001-2012 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors: * Authors:
* Christopher ML Zumwalt May ([email protected]) * Christopher ML Zumwalt May ([email protected])
* Jérôme Duval * Jérôme Duval
*
* Distributed under the terms of the MIT License.
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -20,6 +21,7 @@
#include "GameSoundDevice.h" #include "GameSoundDevice.h"
#include "GSUtility.h" #include "GSUtility.h"
const int32 kPages = 20; const int32 kPages = 20;
struct _gs_media_tracker struct _gs_media_tracker
{ {
@@ -29,8 +31,10 @@ struct _gs_media_tracker
size_t position; size_t position;
}; };
// Local utility functions ----------------------------------------------- // Local utility functions -----------------------------------------------
bool FillBuffer(_gs_ramp * ramp, uint8 * data, uint8 * buffer, size_t * bytes) bool
FillBuffer(_gs_ramp * ramp, uint8 * data, uint8 * buffer, size_t * bytes)
{ {
int32 samples = *bytes / sizeof(uint8); int32 samples = *bytes / sizeof(uint8);
@@ -47,7 +51,9 @@ bool FillBuffer(_gs_ramp * ramp, uint8 * data, uint8 * buffer, size_t * bytes)
return false; return false;
} }
bool FillBuffer(_gs_ramp * ramp, int16 * data, int16 * buffer, size_t * bytes)
bool
FillBuffer(_gs_ramp * ramp, int16 * data, int16 * buffer, size_t * bytes)
{ {
int32 samples = *bytes / sizeof(int16); int32 samples = *bytes / sizeof(int16);
@@ -64,7 +70,9 @@ bool FillBuffer(_gs_ramp * ramp, int16 * data, int16 * buffer, size_t * bytes)
return false; return false;
} }
bool FillBuffer(_gs_ramp * ramp, int32 * data, int32 * buffer, size_t * bytes)
bool
FillBuffer(_gs_ramp * ramp, int32 * data, int32 * buffer, size_t * bytes)
{ {
size_t byte = 0; size_t byte = 0;
bool bytesAreReady = (*bytes > 0); bool bytesAreReady = (*bytes > 0);
@@ -85,7 +93,9 @@ bool FillBuffer(_gs_ramp * ramp, int32 * data, int32 * buffer, size_t * bytes)
return false; return false;
} }
bool FillBuffer(_gs_ramp * ramp, float * data, float * buffer, size_t * bytes)
bool
FillBuffer(_gs_ramp * ramp, float * data, float * buffer, size_t * bytes)
{ {
size_t byte = 0; size_t byte = 0;
bool bytesAreReady = (*bytes > 0); bool bytesAreReady = (*bytes > 0);
@@ -106,11 +116,12 @@ bool FillBuffer(_gs_ramp * ramp, float * data, float * buffer, size_t * bytes)
return false; return false;
} }
// BFileGameSound ------------------------------------------------------- // BFileGameSound -------------------------------------------------------
BFileGameSound::BFileGameSound(const entry_ref *file, BFileGameSound::BFileGameSound(const entry_ref *file, bool looping,
bool looping,
BGameSoundDevice *device) BGameSoundDevice *device)
: BStreamingGameSound(device), :
BStreamingGameSound(device),
fAudioStream(NULL), fAudioStream(NULL),
fStopping(false), fStopping(false),
fLooping(looping), fLooping(looping),
@@ -125,10 +136,10 @@ BFileGameSound::BFileGameSound(const entry_ref *file,
} }
BFileGameSound::BFileGameSound(const char *file, BFileGameSound::BFileGameSound(const char *file, bool looping,
bool looping,
BGameSoundDevice *device) BGameSoundDevice *device)
: BStreamingGameSound(device), :
BStreamingGameSound(device),
fAudioStream(NULL), fAudioStream(NULL),
fStopping(false), fStopping(false),
fLooping(looping), fLooping(looping),
@@ -221,8 +232,7 @@ BFileGameSound::Preload()
void void
BFileGameSound::FillBuffer(void *inBuffer, BFileGameSound::FillBuffer(void *inBuffer, size_t inByteCount)
size_t inByteCount)
{ {
// Split or combine decoder buffers into mixer buffers // Split or combine decoder buffers into mixer buffers
// fPlayPosition is where we got up to in the input buffer after last call // fPlayPosition is where we got up to in the input buffer after last call
@@ -231,7 +241,8 @@ BFileGameSound::FillBuffer(void *inBuffer,
while (inByteCount > 0 && !fPaused) { while (inByteCount > 0 && !fPaused) {
if (!fPaused || fPausing) { if (!fPaused || fPausing) {
printf("mixout %ld, inByteCount %ld, decin %ld, BufferSize %ld\n",out_offset, inByteCount, fPlayPosition, fBufferSize); printf("mixout %ld, inByteCount %ld, decin %ld, BufferSize %ld\n",
out_offset, inByteCount, fPlayPosition, fBufferSize);
if (fPlayPosition == 0 || fPlayPosition >= fBufferSize) { if (fPlayPosition == 0 || fPlayPosition >= fBufferSize) {
Load(); Load();
} }
@@ -251,19 +262,27 @@ BFileGameSound::FillBuffer(void *inBuffer,
switch(Format().format) { switch(Format().format) {
case gs_audio_format::B_GS_U8: case gs_audio_format::B_GS_U8:
rampDone = ::FillBuffer(fPausing, (uint8*)&buffer[out_offset], (uint8*)&fBuffer[fPlayPosition], &bytes); rampDone = ::FillBuffer(fPausing,
(uint8*)&buffer[out_offset],
(uint8*)&fBuffer[fPlayPosition], &bytes);
break; break;
case gs_audio_format::B_GS_S16: case gs_audio_format::B_GS_S16:
rampDone = ::FillBuffer(fPausing, (int16*)&buffer[out_offset], (int16*)&fBuffer[fPlayPosition], &bytes); rampDone = ::FillBuffer(fPausing,
(int16*)&buffer[out_offset],
(int16*)&fBuffer[fPlayPosition], &bytes);
break; break;
case gs_audio_format::B_GS_S32: case gs_audio_format::B_GS_S32:
rampDone = ::FillBuffer(fPausing, (int32*)&buffer[out_offset], (int32*)&fBuffer[fPlayPosition], &bytes); rampDone = ::FillBuffer(fPausing,
(int32*)&buffer[out_offset],
(int32*)&fBuffer[fPlayPosition], &bytes);
break; break;
case gs_audio_format::B_GS_F: case gs_audio_format::B_GS_F:
rampDone = ::FillBuffer(fPausing, (float*)&buffer[out_offset], (float*)&fBuffer[fPlayPosition], &bytes); rampDone = ::FillBuffer(fPausing,
(float*)&buffer[out_offset],
(float*)&fBuffer[fPlayPosition], &bytes);
break; break;
} }
@@ -274,7 +293,7 @@ BFileGameSound::FillBuffer(void *inBuffer,
// We finished ramping // We finished ramping
if (rampDone) { if (rampDone) {
// We need to be able to stop asap when the pause flag is flipped. // Need to be able to stop asap when pause flag is flipped.
while (fPlayPosition < fBufferSize && (inByteCount > 0)) { while (fPlayPosition < fBufferSize && (inByteCount > 0)) {
buffer[out_offset++] = fBuffer[fPlayPosition++]; buffer[out_offset++] = fBuffer[fPlayPosition++];
inByteCount--; inByteCount--;
@@ -289,8 +308,9 @@ BFileGameSound::FillBuffer(void *inBuffer,
char * buffer = (char*)inBuffer; char * buffer = (char*)inBuffer;
// We need to be able to stop asap when the pause flag is flipped. // Need to be able to stop asap when the pause flag is flipped.
while(fPlayPosition < fBufferSize && (!fPaused || fPausing) && (inByteCount > 0)) { while (fPlayPosition < fBufferSize && (!fPaused || fPausing)
&& (inByteCount > 0)) {
buffer[out_offset++] = fBuffer[fPlayPosition++]; buffer[out_offset++] = fBuffer[fPlayPosition++];
inByteCount--; inByteCount--;
} }
@@ -309,8 +329,7 @@ BFileGameSound::Perform(int32 selector,
status_t status_t
BFileGameSound::SetPaused(bool isPaused, BFileGameSound::SetPaused(bool isPaused, bigtime_t rampTime)
bigtime_t rampTime)
{ {
if (fPaused != isPaused) { if (fPaused != isPaused) {
Lock(); Lock();
@@ -632,5 +651,3 @@ BFileGameSound::_Reserved_BFileGameSound_23(int32 arg, ...)
{ {
return B_ERROR; return B_ERROR;
} }
+6 -5
View File
@@ -1,18 +1,19 @@
/* /*
* Copyright 2001-2002, Haiku Inc. * Copyright 2001-2012 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors: * Authors:
* Christopher ML Zumwalt May ([email protected]) * Christopher ML Zumwalt May ([email protected])
*
* Distributed under the terms of the MIT License.
*/ */
#include "GSUtility.h"
#include <GameSoundDefs.h> #include <GameSoundDefs.h>
#include <MediaDefs.h> #include <MediaDefs.h>
#include <new> #include <new>
#include "GSUtility.h"
_gs_ramp* _gs_ramp*
InitRamp(float* value, float set, float frames, bigtime_t duration) InitRamp(float* value, float set, float frames, bigtime_t duration)
+5 -2
View File
@@ -23,10 +23,10 @@
// Author: Christopher ML Zumwalt May ([email protected]) // Author: Christopher ML Zumwalt May ([email protected])
// Description: Utility functions used by sound system // Description: Utility functions used by sound system
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#ifndef _GAMESOUND_UTILITY_H #ifndef _GAMESOUND_UTILITY_H
#define _GAMESOUND_UTILITY_H #define _GAMESOUND_UTILITY_H
#include <GameSoundDefs.h> #include <GameSoundDefs.h>
#include <MediaDefs.h> #include <MediaDefs.h>
@@ -46,9 +46,12 @@ struct _gs_ramp
bigtime_t duration; bigtime_t duration;
}; };
_gs_ramp* InitRamp(float* value, float set, float frames, bigtime_t duration); _gs_ramp* InitRamp(float* value, float set, float frames, bigtime_t duration);
bool ChangeRamp(_gs_ramp* ramp); bool ChangeRamp(_gs_ramp* ramp);
size_t get_sample_size(int32 format); size_t get_sample_size(int32 format);
void media_to_gs_format(gs_audio_format * dest, media_raw_audio_format * source); void media_to_gs_format(gs_audio_format* dest,
media_raw_audio_format* source);
#endif #endif
+114 -80
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2010 Haiku Inc. All rights reserved. * Copyright 2002-2012 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -12,6 +12,8 @@
*/ */
#include "GameProducer.h"
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@@ -26,8 +28,6 @@
#include "GameSoundDevice.h" #include "GameSoundDevice.h"
#include "GSUtility.h" #include "GSUtility.h"
#include "GameProducer.h"
struct _gs_play { struct _gs_play {
gs_id sound; gs_id sound;
@@ -53,14 +53,16 @@ GameProducer::GameProducer(GameSoundBuffer* object,
fPreferredFormat.type = B_MEDIA_RAW_AUDIO; fPreferredFormat.type = B_MEDIA_RAW_AUDIO;
fPreferredFormat.u.raw_audio.format = format->format; fPreferredFormat.u.raw_audio.format = format->format;
fPreferredFormat.u.raw_audio.channel_count = format->channel_count; fPreferredFormat.u.raw_audio.channel_count = format->channel_count;
fPreferredFormat.u.raw_audio.frame_rate = format->frame_rate; // measured in Hertz fPreferredFormat.u.raw_audio.frame_rate = format->frame_rate; // Hertz
fPreferredFormat.u.raw_audio.byte_order = format->byte_order; fPreferredFormat.u.raw_audio.byte_order = format->byte_order;
// fPreferredFormat.u.raw_audio.channel_mask = B_CHANNEL_LEFT | B_CHANNEL_RIGHT; // fPreferredFormat.u.raw_audio.channel_mask
// = B_CHANNEL_LEFT | B_CHANNEL_RIGHT;
// fPreferredFormat.u.raw_audio.valid_bits = 32; // fPreferredFormat.u.raw_audio.valid_bits = 32;
// fPreferredFormat.u.raw_audio.matrix_mask = B_MATRIX_AMBISONIC_WXYZ; // fPreferredFormat.u.raw_audio.matrix_mask = B_MATRIX_AMBISONIC_WXYZ;
// we'll use the consumer's preferred buffer size, if any // we'll use the consumer's preferred buffer size, if any
fPreferredFormat.u.raw_audio.buffer_size = media_raw_audio_format::wildcard.buffer_size; fPreferredFormat.u.raw_audio.buffer_size
= media_raw_audio_format::wildcard.buffer_size;
// we're not connected yet // we're not connected yet
fOutput.destination = media_destination::null; fOutput.destination = media_destination::null;
@@ -91,7 +93,8 @@ status_t
GameProducer::GetNextOutput(int32* cookie, media_output* out_output) GameProducer::GetNextOutput(int32* cookie, media_output* out_output)
{ {
// we currently support only one output // we currently support only one output
if (0 != *cookie) return B_BAD_INDEX; if (0 != *cookie)
return B_BAD_INDEX;
*out_output = fOutput; *out_output = fOutput;
*cookie += 1; *cookie += 1;
@@ -108,12 +111,13 @@ GameProducer::DisposeOutputCookie(int32 cookie)
void void
GameProducer::EnableOutput(const media_source& what, bool enabled, int32* _deprecated_) GameProducer::EnableOutput(const media_source& what, bool enabled,
int32* _deprecated_)
{ {
// If I had more than one output, I'd have to walk my list of output records to see // If I had more than one output, I'd have to walk my list of output records
// which one matched the given source, and then enable/disable that one. But this // to see which one matched the given source, and then enable/disable that
// node only has one output, so I just make sure the given source matches, then set // one. But this node only has one output, so I just make sure the given
// the enable state accordingly. // source matches, then set the enable state accordingly.
if (what == fOutput.source) if (what == fOutput.source)
{ {
fOutputEnabled = enabled; fOutputEnabled = enabled;
@@ -122,7 +126,8 @@ GameProducer::EnableOutput(const media_source& what, bool enabled, int32* _depre
status_t status_t
GameProducer::FormatSuggestionRequested(media_type type, int32 /*quality*/, media_format* format) GameProducer::FormatSuggestionRequested(media_type type, int32 /*quality*/,
media_format* format)
{ {
// insure that we received a format // insure that we received a format
if (!format) if (!format)
@@ -132,7 +137,8 @@ GameProducer::FormatSuggestionRequested(media_type type, int32 /*quality*/, medi
*format = fPreferredFormat; *format = fPreferredFormat;
// our format is supported // our format is supported
if (type == B_MEDIA_UNKNOWN_TYPE) return B_OK; if (type == B_MEDIA_UNKNOWN_TYPE)
return B_OK;
// we only support raw audo // we only support raw audo
return (type != B_MEDIA_RAW_AUDIO) ? B_MEDIA_BAD_FORMAT : B_OK; return (type != B_MEDIA_RAW_AUDIO) ? B_MEDIA_BAD_FORMAT : B_OK;
@@ -143,31 +149,38 @@ status_t
GameProducer::FormatProposal(const media_source& output, media_format* format) GameProducer::FormatProposal(const media_source& output, media_format* format)
{ {
// doest the proposed output match our output? // doest the proposed output match our output?
if (output != fOutput.source) return B_MEDIA_BAD_SOURCE; if (output != fOutput.source)
return B_MEDIA_BAD_SOURCE;
// return our preferred format // return our preferred format
*format = fPreferredFormat; *format = fPreferredFormat;
// we will reject the proposal if the format is not audio // we will reject the proposal if the format is not audio
media_type requestedType = format->type; media_type requestedType = format->type;
if ((requestedType != B_MEDIA_UNKNOWN_TYPE) && (requestedType != B_MEDIA_RAW_AUDIO)) if ((requestedType != B_MEDIA_UNKNOWN_TYPE)
&& (requestedType != B_MEDIA_RAW_AUDIO)) {
return B_MEDIA_BAD_FORMAT; return B_MEDIA_BAD_FORMAT;
}
return B_OK; // raw audio or wildcard type, either is okay by us return B_OK; // raw audio or wildcard type, either is okay by us
} }
status_t status_t
GameProducer::PrepareToConnect(const media_source& what, const media_destination& where, media_format* format, media_source* out_source, char* out_name) GameProducer::PrepareToConnect(const media_source& what,
const media_destination& where, media_format* format,
media_source* out_source, char* out_name)
{ {
// The format has been processed by the consumer at this point. We need // The format has been processed by the consumer at this point. We need
// to insure the format is still acceptable and any wild care are filled in. // to insure the format is still acceptable and any wild care are filled in.
// trying to connect something that isn't our source? // trying to connect something that isn't our source?
if (what != fOutput.source) return B_MEDIA_BAD_SOURCE; if (what != fOutput.source)
return B_MEDIA_BAD_SOURCE;
// are we already connected? // are we already connected?
if (fOutput.destination != media_destination::null) return B_MEDIA_ALREADY_CONNECTED; if (fOutput.destination != media_destination::null)
return B_MEDIA_ALREADY_CONNECTED;
// the format may not yet be fully specialized (the consumer might have // the format may not yet be fully specialized (the consumer might have
// passed back some wildcards). Finish specializing it now, and return an // passed back some wildcards). Finish specializing it now, and return an
@@ -179,8 +192,11 @@ GameProducer::PrepareToConnect(const media_source& what, const media_destination
return B_MEDIA_BAD_FORMAT; return B_MEDIA_BAD_FORMAT;
// check the buffer size, which may still be wildcarded // check the buffer size, which may still be wildcarded
if (format->u.raw_audio.buffer_size == media_raw_audio_format::wildcard.buffer_size) if (format->u.raw_audio.buffer_size
format->u.raw_audio.buffer_size = 4096; // pick something comfortable to suggest == media_raw_audio_format::wildcard.buffer_size) {
format->u.raw_audio.buffer_size = 4096;
// pick something comfortable to suggest
}
// Now reserve the connection, and return information about it // Now reserve the connection, and return information about it
fOutput.destination = where; fOutput.destination = where;
@@ -192,19 +208,21 @@ GameProducer::PrepareToConnect(const media_source& what, const media_destination
void void
GameProducer::Connect(status_t error, const media_source& source, const media_destination& destination, const media_format& format, char* io_name) GameProducer::Connect(status_t error, const media_source& source,
const media_destination& destination, const media_format& format,
char* io_name)
{ {
// If something earlier failed, Connect() might still be called, but with a non-zero // If something earlier failed, Connect() might still be called, but with a
// error code. When that happens we simply unreserve the connection and do // non-zero error code. When that happens we simply unreserve the
// nothing else. // connection and do nothing else.
if (error) { if (error) {
fOutput.destination = media_destination::null; fOutput.destination = media_destination::null;
fOutput.format = fPreferredFormat; fOutput.format = fPreferredFormat;
return; return;
} }
// Okay, the connection has been confirmed. Record the destination and format // Okay, the connection has been confirmed. Record the destination and
// that we agreed on, and report our connection name again. // format that we agreed on, and report our connection name again.
fOutput.destination = destination; fOutput.destination = destination;
fOutput.format = format; fOutput.format = format;
strlcpy(io_name, fOutput.name, B_MEDIA_NAME_LENGTH); strlcpy(io_name, fOutput.name, B_MEDIA_NAME_LENGTH);
@@ -241,7 +259,8 @@ GameProducer::Connect(status_t error, const media_source& source, const media_de
delete [] data; delete [] data;
// reset our buffer duration, etc. to avoid later calculations // reset our buffer duration, etc. to avoid later calculations
bigtime_t duration = bigtime_t(1000000) * frames / bigtime_t(fOutput.format.u.raw_audio.frame_rate); bigtime_t duration = bigtime_t(1000000) * frames
/ bigtime_t(fOutput.format.u.raw_audio.frame_rate);
SetBufferDuration(duration); SetBufferDuration(duration);
// Set up the buffer group for our connection, as long as nobody handed us a // Set up the buffer group for our connection, as long as nobody handed us a
@@ -254,7 +273,8 @@ GameProducer::Connect(status_t error, const media_source& source, const media_de
void void
GameProducer::Disconnect(const media_source& what, const media_destination& where) GameProducer::Disconnect(const media_source& what,
const media_destination& where)
{ {
// Make sure that our connection is the one being disconnected // Make sure that our connection is the one being disconnected
if ((where == fOutput.destination) && (what == fOutput.source)) { if ((where == fOutput.destination) && (what == fOutput.source)) {
@@ -267,7 +287,9 @@ GameProducer::Disconnect(const media_source& what, const media_destination& wher
status_t status_t
GameProducer::FormatChangeRequested(const media_source& source, const media_destination& destination, media_format* io_format, int32* _deprecated_) GameProducer::FormatChangeRequested(const media_source& source,
const media_destination& destination, media_format* io_format,
int32* _deprecated_)
{ {
// we don't support any other formats, so we just reject any format changes. // we don't support any other formats, so we just reject any format changes.
return B_ERROR; return B_ERROR;
@@ -275,7 +297,8 @@ GameProducer::FormatChangeRequested(const media_source& source, const media_dest
status_t status_t
GameProducer::SetBufferGroup(const media_source& for_source, BBufferGroup* newGroup) GameProducer::SetBufferGroup(const media_source& for_source,
BBufferGroup* newGroup)
{ {
// verify that we didn't get bogus arguments before we proceed // verify that we didn't get bogus arguments before we proceed
if (for_source != fOutput.source) if (for_source != fOutput.source)
@@ -285,12 +308,12 @@ GameProducer::SetBufferGroup(const media_source& for_source, BBufferGroup* newGr
if (newGroup == fBufferGroup) if (newGroup == fBufferGroup)
return B_OK; return B_OK;
// Ahh, someone wants us to use a different buffer group. At this point we delete // Ahh, someone wants us to use a different buffer group. At this point we
// the one we are using and use the specified one instead. If the specified group is // delete the one we are using and use the specified one instead. If the
// NULL, we need to recreate one ourselves, and use *that*. Note that if we're // specified group is NULL, we need to recreate one ourselves, and use
// caching a BBuffer that we requested earlier, we have to Recycle() that buffer // *that*. Note that if we're caching a BBuffer that we requested earlier,
// *before* deleting the buffer group, otherwise we'll deadlock waiting for that // we have to Recycle() that buffer *before* deleting the buffer group,
// buffer to be recycled! // otherwise we'll deadlock waiting for that buffer to be recycled!
delete fBufferGroup; // waits for all buffers to recycle delete fBufferGroup; // waits for all buffers to recycle
if (newGroup != NULL) { if (newGroup != NULL) {
// we were given a valid group; just use that one from now on // we were given a valid group; just use that one from now on
@@ -323,28 +346,30 @@ GameProducer::GetLatency(bigtime_t* out_latency)
void void
GameProducer::LateNoticeReceived(const media_source& what, bigtime_t how_much, bigtime_t performance_time) GameProducer::LateNoticeReceived(const media_source& what, bigtime_t how_much,
bigtime_t performance_time)
{ {
// If we're late, we need to catch up. Respond in a manner appropriate to our // If we're late, we need to catch up. Respond in a manner appropriate to
// current run mode. // our current run mode.
if (what == fOutput.source) { if (what == fOutput.source) {
if (RunMode() == B_RECORDING) { if (RunMode() == B_RECORDING) {
// A hardware capture node can't adjust; it simply emits buffers at // A hardware capture node can't adjust; it simply emits buffers at
// appropriate points. We (partially) simulate this by not adjusting // appropriate points. We (partially) simulate this by not
// our behavior upon receiving late notices -- after all, the hardware // adjusting our behavior upon receiving late notices -- after all,
// can't choose to capture "sooner".... // the hardware can't choose to capture "sooner"...
} else if (RunMode() == B_INCREASE_LATENCY) { } else if (RunMode() == B_INCREASE_LATENCY) {
// We're late, and our run mode dictates that we try to produce buffers // We're late, and our run mode dictates that we try to produce
// earlier in order to catch up. This argues that the downstream nodes are // buffers earlier in order to catch up. This argues that the
// not properly reporting their latency, but there's not much we can do about // downstream nodes are not properly reporting their latency, but
// that at the moment, so we try to start producing buffers earlier to // there's not much we can do about that at the moment, so we try
// compensate. // to start producing buffers earlier to compensate.
fInternalLatency += how_much; fInternalLatency += how_much;
SetEventLatency(fLatency + fInternalLatency); SetEventLatency(fLatency + fInternalLatency);
} else { } else {
// The other run modes dictate various strategies for sacrificing data quality // The other run modes dictate various strategies for sacrificing
// in the interests of timely data delivery. The way *we* do this is to skip // data quality in the interests of timely data delivery. The way we
// a buffer, which catches us up in time by one buffer duration. // do this is to skip a buffer, which catches us up in time by one
// buffer duration.
size_t nSamples = fBufferSize / fFrameSize; size_t nSamples = fBufferSize / fFrameSize;
fFramesSent += nSamples; fFramesSent += nSamples;
} }
@@ -353,7 +378,8 @@ GameProducer::LateNoticeReceived(const media_source& what, bigtime_t how_much, b
void void
GameProducer::LatencyChanged(const media_source& source, const media_destination& destination, bigtime_t new_latency, uint32 flags) GameProducer::LatencyChanged(const media_source& source,
const media_destination& destination, bigtime_t new_latency, uint32 flags)
{ {
// something downstream changed latency, so we need to start producing // something downstream changed latency, so we need to start producing
// buffers earlier (or later) than we were previously. Make sure that the // buffers earlier (or later) than we were previously. Make sure that the
@@ -383,7 +409,9 @@ GameProducer::HandleMessage(int32 message, const void* data, size_t size)
void void
GameProducer::AdditionalBufferRequested(const media_source& source, media_buffer_id prev_buffer, bigtime_t prev_time, const media_seek_tag* prev_tag) GameProducer::AdditionalBufferRequested(const media_source& source,
media_buffer_id prev_buffer, bigtime_t prev_time,
const media_seek_tag* prev_tag)
{ {
// we don't support offline mode (yet...) // we don't support offline mode (yet...)
return; return;
@@ -418,7 +446,8 @@ GameProducer::SetRunMode(run_mode mode)
void void
GameProducer::HandleEvent(const media_timed_event* event, bigtime_t lateness, bool realTimeEvent) GameProducer::HandleEvent(const media_timed_event* event, bigtime_t lateness,
bool realTimeEvent)
{ {
// FPRINTF(stderr, "ToneProducer::HandleEvent\n"); // FPRINTF(stderr, "ToneProducer::HandleEvent\n");
switch (event->type) switch (event->type)
@@ -426,44 +455,44 @@ GameProducer::HandleEvent(const media_timed_event* event, bigtime_t lateness, bo
case BTimedEventQueue::B_START: case BTimedEventQueue::B_START:
// don't do anything if we're already running // don't do anything if we're already running
if (RunState() != B_STARTED) { if (RunState() != B_STARTED) {
// We are going to start sending buffers so setup the needed bookkeeping // Going to start sending buffers so setup the needed bookkeeping
fFramesSent = 0; fFramesSent = 0;
fStartTime = event->event_time; fStartTime = event->event_time;
media_timed_event firstBufferEvent(fStartTime, BTimedEventQueue::B_HANDLE_BUFFER); media_timed_event firstBufferEvent(fStartTime,
BTimedEventQueue::B_HANDLE_BUFFER);
// Alternatively, we could call HandleEvent() directly with this event, to avoid a trip through // Alternatively, we could call HandleEvent() directly with this
// the event queue, like this: // event, to avoid a trip through the event queue like this:
//
// this->HandleEvent(&firstBufferEvent, 0, false); // this->HandleEvent(&firstBufferEvent, 0, false);
//
EventQueue()->AddEvent(firstBufferEvent); EventQueue()->AddEvent(firstBufferEvent);
} }
break; break;
case BTimedEventQueue::B_STOP: case BTimedEventQueue::B_STOP:
// When we handle a stop, we must ensure that downstream consumers don't // When we handle a stop, we must ensure that downstream consumers don't
// get any more buffers from us. This means we have to flush any pending // get any more buffers from us. This means we have to flush any
// buffer-producing events from the queue. // pending buffer-producing events from the queue.
EventQueue()->FlushEvents(0, BTimedEventQueue::B_ALWAYS, true, BTimedEventQueue::B_HANDLE_BUFFER); EventQueue()->FlushEvents(0, BTimedEventQueue::B_ALWAYS, true,
BTimedEventQueue::B_HANDLE_BUFFER);
break; break;
case BTimedEventQueue::B_HANDLE_BUFFER: case BTimedEventQueue::B_HANDLE_BUFFER:
{ {
// make sure we're both started *and* connected before delivering a buffer // Ensure we're both started and connected before delivering buffer
if ((RunState() == BMediaEventLooper::B_STARTED) if ((RunState() == BMediaEventLooper::B_STARTED)
&& (fOutput.destination != media_destination::null)) { && (fOutput.destination != media_destination::null)) {
// Get the next buffer of data // Get the next buffer of data
BBuffer* buffer = FillNextBuffer(event->event_time); BBuffer* buffer = FillNextBuffer(event->event_time);
if (buffer) { if (buffer) {
// send the buffer downstream if and only if output is enabled // Send the buffer downstream if output is enabled
status_t err = B_ERROR; status_t err = B_ERROR;
if (fOutputEnabled) { if (fOutputEnabled) {
err = SendBuffer(buffer, fOutput.source, err = SendBuffer(buffer, fOutput.source,
fOutput.destination); fOutput.destination);
} }
if (err) { if (err) {
// we need to recycle the buffer ourselves if output is disabled or // we need to recycle the buffer ourselves if output is
// if the call to SendBuffer() fails // disabled or if the call to SendBuffer() fails
buffer->Recycle(); buffer->Recycle();
} }
} }
@@ -473,8 +502,11 @@ GameProducer::HandleEvent(const media_timed_event* event, bigtime_t lateness, bo
fFramesSent += nFrames; fFramesSent += nFrames;
// The buffer is on its way; now schedule the next one to go // The buffer is on its way; now schedule the next one to go
bigtime_t nextEvent = fStartTime + bigtime_t(double(fFramesSent) / double(fOutput.format.u.raw_audio.frame_rate) * 1000000.0); bigtime_t nextEvent = fStartTime + bigtime_t(double(fFramesSent)
media_timed_event nextBufferEvent(nextEvent, BTimedEventQueue::B_HANDLE_BUFFER); / double(fOutput.format.u.raw_audio.frame_rate)
* 1000000.0);
media_timed_event nextBufferEvent(nextEvent,
BTimedEventQueue::B_HANDLE_BUFFER);
EventQueue()->AddEvent(nextBufferEvent); EventQueue()->AddEvent(nextBufferEvent);
} }
} }
@@ -492,8 +524,9 @@ GameProducer::FillNextBuffer(bigtime_t event_time)
// get a buffer from our buffer group // get a buffer from our buffer group
BBuffer* buf = fBufferGroup->RequestBuffer(fBufferSize, BufferDuration()); BBuffer* buf = fBufferGroup->RequestBuffer(fBufferSize, BufferDuration());
// if we fail to get a buffer (for example, if the request times out), we skip this // if we fail to get a buffer (for example, if the request times out), we
// buffer and go on to the next, to avoid locking up the control thread // skip this buffer and go on to the next, to avoid locking up the control
// thread.
if (!buf) if (!buf)
return NULL; return NULL;
@@ -513,20 +546,21 @@ GameProducer::FillNextBuffer(bigtime_t event_time)
bigtime_t stamp; bigtime_t stamp;
if (RunMode() == B_RECORDING) { if (RunMode() == B_RECORDING) {
// In B_RECORDING mode, we stamp with the capture time. We're not // In B_RECORDING mode, we stamp with the capture time. We're not
// really a hardware capture node, but we simulate it by using the (precalculated) // really a hardware capture node, but we simulate it by using the
// time at which this buffer "should" have been created. // (precalculated) time at which this buffer "should" have been created.
stamp = event_time; stamp = event_time;
} else { } else {
// okay, we're in one of the "live" performance run modes. in these modes, we // okay, we're in one of the "live" performance run modes. in these
// stamp the buffer with the time at which the buffer should be rendered to the // modes, we stamp the buffer with the time at which the buffer should
// output, not with the capture time. fStartTime is the cached value of the // be rendered to the output, not with the capture time. fStartTime is
// first buffer's performance time; we calculate this buffer's performance time as // the cached value of the first buffer's performance time; we calculate
// an offset from that time, based on the amount of media we've created so far. // this buffer's performance time as an offset from that time, based on
// the amount of media we've created so far.
// Recalculating every buffer like this avoids accumulation of error. // Recalculating every buffer like this avoids accumulation of error.
stamp = fStartTime + bigtime_t(double(fFramesSent) / double(fOutput.format.u.raw_audio.frame_rate) * 1000000.0); stamp = fStartTime + bigtime_t(double(fFramesSent)
/ double(fOutput.format.u.raw_audio.frame_rate) * 1000000.0);
} }
hdr->start_time = stamp; hdr->start_time = stamp;
return buf; return buf;
} }
+19 -18
View File
@@ -1,27 +1,31 @@
/* /*
* Copyright 2001-2002, Haiku Inc. * Copyright 2002-2012 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors: * Authors:
* Christopher ML Zumwalt May (zummy@users.sf.net) * Christopher ML Zumwalt May (zummy@users.sf.net)
* *
* Distributed under the terms of the MIT License.
*/ */
#include <GameSound.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <GameSound.h>
#include "GameSoundBuffer.h" #include "GameSoundBuffer.h"
#include "GameSoundDevice.h" #include "GameSoundDevice.h"
using std::nothrow; using std::nothrow;
// Local Defines --------------------------------------------------------------- // Local Defines ---------------------------------------------------------------
// BGameSound class ------------------------------------------------------------ // BGameSound class ------------------------------------------------------------
BGameSound::BGameSound(BGameSoundDevice *device) BGameSound::BGameSound(BGameSoundDevice *device)
: fSound(-1) :
fSound(-1)
{ {
// TODO: device is ignored! // TODO: device is ignored!
// NOTE: BeBook documents that BGameSoundDevice must currently always // NOTE: BeBook documents that BGameSoundDevice must currently always
@@ -32,7 +36,8 @@ BGameSound::BGameSound(BGameSoundDevice *device)
BGameSound::BGameSound(const BGameSound &other) BGameSound::BGameSound(const BGameSound &other)
: fSound(-1) :
fSound(-1)
{ {
memcpy(&fFormat, &other.fFormat, sizeof(gs_audio_format)); memcpy(&fFormat, &other.fFormat, sizeof(gs_audio_format));
// TODO: device from other is ignored! // TODO: device from other is ignored!
@@ -106,8 +111,7 @@ BGameSound::StopPlaying()
status_t status_t
BGameSound::SetGain(float gain, BGameSound::SetGain(float gain, bigtime_t duration)
bigtime_t duration)
{ {
gs_attribute attribute; gs_attribute attribute;
@@ -121,8 +125,7 @@ BGameSound::SetGain(float gain,
status_t status_t
BGameSound::SetPan(float pan, BGameSound::SetPan(float pan, bigtime_t duration)
bigtime_t duration)
{ {
gs_attribute attribute; gs_attribute attribute;
@@ -166,16 +169,14 @@ BGameSound::Pan()
status_t status_t
BGameSound::SetAttributes(gs_attribute *inAttributes, BGameSound::SetAttributes(gs_attribute *inAttributes, size_t inAttributeCount)
size_t inAttributeCount)
{ {
return fDevice->SetAttributes(fSound, inAttributes, inAttributeCount); return fDevice->SetAttributes(fSound, inAttributes, inAttributeCount);
} }
status_t status_t
BGameSound::GetAttributes(gs_attribute *outAttributes, BGameSound::GetAttributes(gs_attribute *outAttributes, size_t inAttributeCount)
size_t inAttributeCount)
{ {
return fDevice->GetAttributes(fSound, outAttributes, inAttributeCount); return fDevice->GetAttributes(fSound, outAttributes, inAttributeCount);
} }
@@ -258,7 +259,8 @@ BGameSound::Init(gs_id handle)
return B_OK; return B_OK;
} }
/*
#if 0
BGameSound & BGameSound &
BGameSound::operator=(const BGameSound &other) BGameSound::operator=(const BGameSound &other)
{ {
@@ -272,7 +274,8 @@ BGameSound::operator=(const BGameSound &other)
return this; return this;
} }
*/ #endif
/* unimplemented for protection of the user: /* unimplemented for protection of the user:
* *
@@ -614,5 +617,3 @@ BGameSound::_Reserved_BGameSound_47(int32 arg, ...)
{ {
return B_ERROR; return B_ERROR;
} }
+22 -15
View File
@@ -24,6 +24,9 @@
// Description: Interface to a single sound, managed by the GameSoundDevice. // Description: Interface to a single sound, managed by the GameSoundDevice.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#include "GameSoundBuffer.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -35,7 +38,6 @@
#include <BufferGroup.h> #include <BufferGroup.h>
#include "GameProducer.h" #include "GameProducer.h"
#include "GameSoundBuffer.h"
#include "GameSoundDevice.h" #include "GameSoundDevice.h"
#include "StreamingGameSound.h" #include "StreamingGameSound.h"
#include "GSUtility.h" #include "GSUtility.h"
@@ -76,7 +78,8 @@ ApplyMod(float * data, float * buffer, int32 index, float gain, float * pan)
// GameSoundBuffer ------------------------------------------------------- // GameSoundBuffer -------------------------------------------------------
GameSoundBuffer::GameSoundBuffer(const gs_audio_format * format) GameSoundBuffer::GameSoundBuffer(const gs_audio_format * format)
: fLooping(false), :
fLooping(false),
fIsConnected(false), fIsConnected(false),
fIsPlaying(false), fIsPlaying(false),
fGain(1.0), fGain(1.0),
@@ -400,11 +403,14 @@ GameSoundBuffer::Connect(media_node * consumer)
media_input mixerInput; media_input mixerInput;
media_output soundOutput; media_output soundOutput;
int32 count = 1; int32 count = 1;
err = roster->GetFreeOutputsFor(fConnection->producer, &soundOutput, 1, &count); err = roster->GetFreeOutputsFor(fConnection->producer, &soundOutput, 1,
&count);
if (err != B_OK) if (err != B_OK)
return err; return err;
count = 1; count = 1;
err = roster->GetFreeInputsFor(fConnection->consumer, &mixerInput, 1, &count); err = roster->GetFreeInputsFor(fConnection->consumer, &mixerInput, 1,
&count);
if (err != B_OK) if (err != B_OK)
return err; return err;
@@ -412,7 +418,8 @@ GameSoundBuffer::Connect(media_node * consumer)
media_format format; media_format format;
format.type = B_MEDIA_RAW_AUDIO; format.type = B_MEDIA_RAW_AUDIO;
format.u.raw_audio = media_raw_audio_format::wildcard; format.u.raw_audio = media_raw_audio_format::wildcard;
err = roster->Connect(soundOutput.source, mixerInput.destination, &format, &soundOutput, &mixerInput); err = roster->Connect(soundOutput.source, mixerInput.destination, &format,
&soundOutput, &mixerInput);
if (err != B_OK) if (err != B_OK)
return err; return err;
@@ -441,8 +448,10 @@ GameSoundBuffer::StartPlaying()
// the node chain, otherwise it'll start up already late // the node chain, otherwise it'll start up already late
bigtime_t latency = 0; bigtime_t latency = 0;
status_t status = roster->GetLatencyFor(fConnection->producer, &latency); status_t status = roster->GetLatencyFor(fConnection->producer, &latency);
if (status == B_OK) if (status == B_OK) {
status = roster->StartNode(fConnection->producer, source->Now() + latency); status = roster->StartNode(fConnection->producer,
source->Now() + latency);
}
source->Release(); source->Release();
fIsPlaying = true; fIsPlaying = true;
@@ -477,11 +486,10 @@ GameSoundBuffer::IsPlaying()
// SimpleSoundBuffer ------------------------------------------------------ // SimpleSoundBuffer ------------------------------------------------------
SimpleSoundBuffer::SimpleSoundBuffer(const gs_audio_format * format, SimpleSoundBuffer::SimpleSoundBuffer(const gs_audio_format * format,
const void * data, const void * data, int64 frames)
int64 frames) :
: GameSoundBuffer(format), GameSoundBuffer(format),
fPosition(0) fPosition(0)
{ {
fBufferSize = frames * fFrameSize; fBufferSize = frames * fFrameSize;
fBuffer = new char[fBufferSize]; fBuffer = new char[fBufferSize];
@@ -534,15 +542,14 @@ SimpleSoundBuffer::FillBuffer(void * data, int64 frames)
// StreamingSoundBuffer ------------------------------------------------------ // StreamingSoundBuffer ------------------------------------------------------
StreamingSoundBuffer::StreamingSoundBuffer(const gs_audio_format * format, StreamingSoundBuffer::StreamingSoundBuffer(const gs_audio_format * format,
const void * streamHook, size_t inBufferFrameCount, const void * streamHook, size_t inBufferFrameCount, size_t inBufferCount)
size_t inBufferCount)
: :
GameSoundBuffer(format), GameSoundBuffer(format),
fStreamHook(const_cast<void *>(streamHook)) fStreamHook(const_cast<void *>(streamHook))
{ {
if (inBufferFrameCount != 0 && inBufferCount != 0) { if (inBufferFrameCount != 0 && inBufferCount != 0) {
BBufferGroup *bufferGroup = new BBufferGroup(inBufferFrameCount BBufferGroup *bufferGroup
* fFrameSize, inBufferCount); = new BBufferGroup(inBufferFrameCount * fFrameSize, inBufferCount);
fNode->SetBufferGroup(fConnection->source, bufferGroup); fNode->SetBufferGroup(fConnection->source, bufferGroup);
} }
} }
+7 -4
View File
@@ -26,6 +26,9 @@
// this time. Use at your own risk. // this time. Use at your own risk.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#include "GameSoundDevice.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@@ -33,15 +36,15 @@
#include <Autolock.h> #include <Autolock.h>
#include <List.h> #include <List.h>
#include <Locker.h> #include <Locker.h>
#include <MediaRoster.h>
#include <MediaAddOn.h> #include <MediaAddOn.h>
#include <TimeSource.h> #include <MediaRoster.h>
#include <MediaTheme.h> #include <MediaTheme.h>
#include <TimeSource.h>
#include "GSUtility.h"
#include "GameSoundDevice.h"
#include "GameSoundBuffer.h" #include "GameSoundBuffer.h"
#include "GameProducer.h" #include "GameProducer.h"
#include "GSUtility.h"
// BGameSoundDevice definitions ------------------------------------ // BGameSoundDevice definitions ------------------------------------
const int32 kInitSoundCount = 32; const int32 kInitSoundCount = 32;
+8 -9
View File
@@ -1,16 +1,17 @@
/* /*
* Copyright 2001-2007, Haiku Inc. * Copyright 2001-2012 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors: * Authors:
* Christopher ML Zumwalt May (zummy@users.sf.net) * Christopher ML Zumwalt May (zummy@users.sf.net)
* Jérôme Duval * Jérôme Duval
*
* Distributed under the terms of the MIT License.
*/ */
#include <string.h>
#include <PushGameSound.h>
#include <List.h> #include <List.h>
#include <PushGameSound.h> #include <string.h>
#include "GSUtility.h" #include "GSUtility.h"
@@ -133,8 +134,7 @@ BPushGameSound::Perform(int32 selector, void *data)
status_t status_t
BPushGameSound::SetParameters(size_t inBufferFrameCount, BPushGameSound::SetParameters(size_t inBufferFrameCount,
const gs_audio_format *format, const gs_audio_format *format, size_t inBufferCount)
size_t inBufferCount)
{ {
return B_UNSUPPORTED; return B_UNSUPPORTED;
} }
@@ -210,6 +210,7 @@ BPushGameSound::BytesReady(size_t * bytes)
return true; return true;
} }
/* unimplemented for protection of the user: /* unimplemented for protection of the user:
* *
* BPushGameSound::BPushGameSound() * BPushGameSound::BPushGameSound()
@@ -384,5 +385,3 @@ BPushGameSound::_Reserved_BPushGameSound_23(int32 arg, ...)
{ {
return B_ERROR; return B_ERROR;
} }
+26 -21
View File
@@ -1,27 +1,30 @@
/* /*
* Copyright 2001-2005, Haiku Inc. * Copyright 2001-2012 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors: * Authors:
* Christopher ML Zumwalt May (zummy@users.sf.net) * Christopher ML Zumwalt May (zummy@users.sf.net)
*
* Distributed under the terms of the MIT License.
*/ */
#include <stdlib.h>
#include <string.h> #include <SimpleGameSound.h>
#include <Entry.h> #include <Entry.h>
#include <MediaFile.h> #include <MediaFile.h>
#include <MediaTrack.h> #include <MediaTrack.h>
#include <stdlib.h>
#include <string.h>
#include "GameSoundDefs.h"
#include "GameSoundBuffer.h" #include "GameSoundBuffer.h"
#include "GameSoundDefs.h"
#include "GameSoundDevice.h" #include "GameSoundDevice.h"
#include "GSUtility.h" #include "GSUtility.h"
#include <SimpleGameSound.h>
BSimpleGameSound::BSimpleGameSound(const entry_ref *inFile, BGameSoundDevice *device) BSimpleGameSound::BSimpleGameSound(const entry_ref *inFile,
: BGameSound(device) BGameSoundDevice *device)
:
BGameSound(device)
{ {
if (InitCheck() == B_OK) if (InitCheck() == B_OK)
SetInitError(Init(inFile)); SetInitError(Init(inFile));
@@ -29,7 +32,8 @@ BSimpleGameSound::BSimpleGameSound(const entry_ref *inFile, BGameSoundDevice *de
BSimpleGameSound::BSimpleGameSound(const char *inFile, BGameSoundDevice *device) BSimpleGameSound::BSimpleGameSound(const char *inFile, BGameSoundDevice *device)
: BGameSound(device) :
BGameSound(device)
{ {
if (InitCheck() == B_OK) { if (InitCheck() == B_OK) {
entry_ref file; entry_ref file;
@@ -42,11 +46,10 @@ BSimpleGameSound::BSimpleGameSound(const char *inFile, BGameSoundDevice *device)
} }
BSimpleGameSound::BSimpleGameSound(const void *inData, BSimpleGameSound::BSimpleGameSound(const void *inData, size_t inFrameCount,
size_t inFrameCount, const gs_audio_format *format, BGameSoundDevice *device)
const gs_audio_format *format, :
BGameSoundDevice *device) BGameSound(device)
: BGameSound(device)
{ {
if (InitCheck() == B_OK) if (InitCheck() == B_OK)
SetInitError(Init(inData, inFrameCount, format)); SetInitError(Init(inData, inFrameCount, format));
@@ -54,7 +57,8 @@ BSimpleGameSound::BSimpleGameSound(const void *inData,
BSimpleGameSound::BSimpleGameSound(const BSimpleGameSound &other) BSimpleGameSound::BSimpleGameSound(const BSimpleGameSound &other)
: BGameSound(other) :
BGameSound(other)
{ {
gs_audio_format format; gs_audio_format format;
void *data = NULL; void *data = NULL;
@@ -146,7 +150,8 @@ BSimpleGameSound::Init(const entry_ref* inFile)
memset(&mformat, 0, sizeof(media_format)); memset(&mformat, 0, sizeof(media_format));
mformat.type = B_MEDIA_RAW_AUDIO; mformat.type = B_MEDIA_RAW_AUDIO;
// mformat.u.raw_audio.byte_order = (B_HOST_IS_BENDIAN) ? B_MEDIA_BIG_ENDIAN : B_MEDIA_LITTLE_ENDIAN; // mformat.u.raw_audio.byte_order
// = (B_HOST_IS_BENDIAN) ? B_MEDIA_BIG_ENDIAN : B_MEDIA_LITTLE_ENDIAN;
status_t error = audioStream->DecodedFormat(&mformat); status_t error = audioStream->DecodedFormat(&mformat);
if (error != B_OK) if (error != B_OK)
return error; return error;
@@ -183,7 +188,8 @@ BSimpleGameSound::Init(const entry_ref* inFile)
} else { } else {
// We need to determine the size, in bytes, of a single sample. // We need to determine the size, in bytes, of a single sample.
// At the same time, we will store the format of the audio buffer // At the same time, we will store the format of the audio buffer
size_t frameSize = get_sample_size(gsformat.format) * gsformat.channel_count; size_t frameSize
= get_sample_size(gsformat.format) * gsformat.channel_count;
char * data = new char[frames * frameSize]; char * data = new char[frames * frameSize];
gsformat.buffer_size = frames * frameSize; gsformat.buffer_size = frames * frameSize;
@@ -210,7 +216,8 @@ BSimpleGameSound::Init(const void* inData, int64 inFrameCount,
{ {
gs_id sound; gs_id sound;
status_t error = Device()->CreateBuffer(&sound, format, inData, inFrameCount); status_t error
= Device()->CreateBuffer(&sound, format, inData, inFrameCount);
if (error != B_OK) if (error != B_OK)
return error; return error;
@@ -393,5 +400,3 @@ BSimpleGameSound::_Reserved_BSimpleGameSound_23(int32 arg, ...)
{ {
return B_ERROR; return B_ERROR;
} }
+14 -14
View File
@@ -25,27 +25,31 @@
// (data not known beforehand) game sounds. // (data not known beforehand) game sounds.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#include "GameSoundDevice.h"
#include "StreamingGameSound.h" #include "StreamingGameSound.h"
#include "GameSoundDevice.h"
BStreamingGameSound::BStreamingGameSound(size_t inBufferFrameCount, BStreamingGameSound::BStreamingGameSound(size_t inBufferFrameCount,
const gs_audio_format *format, const gs_audio_format *format, size_t inBufferCount,
size_t inBufferCount,
BGameSoundDevice *device) BGameSoundDevice *device)
: BGameSound(device), :
BGameSound(device),
fStreamHook(NULL), fStreamHook(NULL),
fStreamCookie(NULL) fStreamCookie(NULL)
{ {
if (InitCheck() == B_OK) { if (InitCheck() == B_OK) {
status_t error = SetParameters(inBufferFrameCount, format, inBufferCount); status_t error = SetParameters(inBufferFrameCount, format,
inBufferCount);
SetInitError(error); SetInitError(error);
} }
} }
BStreamingGameSound::BStreamingGameSound(BGameSoundDevice *device) BStreamingGameSound::BStreamingGameSound(BGameSoundDevice *device)
: BGameSound(device), :
BGameSound(device),
fStreamHook(NULL), fStreamHook(NULL),
fStreamCookie(NULL) fStreamCookie(NULL)
{ {
@@ -65,8 +69,8 @@ BStreamingGameSound::Clone() const
status_t status_t
BStreamingGameSound::SetStreamHook(void (*hook)(void * inCookie, void * inBuffer, size_t inByteCount, BStreamingGameSound * me), BStreamingGameSound::SetStreamHook(void (*hook)(void* inCookie, void* inBuffer,
void * cookie) size_t inByteCount, BStreamingGameSound * me), void * cookie)
{ {
fStreamHook = hook; fStreamHook = hook;
fStreamCookie = cookie; fStreamCookie = cookie;
@@ -85,8 +89,7 @@ BStreamingGameSound::FillBuffer(void *inBuffer,
status_t status_t
BStreamingGameSound::Perform(int32 selector, BStreamingGameSound::Perform(int32 selector, void *data)
void *data)
{ {
return B_ERROR; return B_ERROR;
} }
@@ -102,8 +105,7 @@ BStreamingGameSound::SetAttributes(gs_attribute * inAttributes,
status_t status_t
BStreamingGameSound::SetParameters(size_t inBufferFrameCount, BStreamingGameSound::SetParameters(size_t inBufferFrameCount,
const gs_audio_format *format, const gs_audio_format *format, size_t inBufferCount)
size_t inBufferCount)
{ {
gs_id sound; gs_id sound;
status_t error = Device()->CreateBuffer(&sound, this, format, status_t error = Device()->CreateBuffer(&sound, this, format,
@@ -302,5 +304,3 @@ BStreamingGameSound::_Reserved_BStreamingGameSound_23(int32 arg, ...)
{ {
return B_ERROR; return B_ERROR;
} }