mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-30 07:23:05 +00:00
SCI: Use Audio::Timestamp instead of sfx_timestamp_t
svn-id: r39113
This commit is contained in:
parent
673a21b249
commit
0a206fb031
@ -70,7 +70,6 @@ MODULE_OBJS = \
|
||||
sfx/mixer.o \
|
||||
sfx/pcm-iterator.o \
|
||||
sfx/songlib.o \
|
||||
sfx/time.o \
|
||||
sfx/device/devices.o \
|
||||
sfx/player/players.o \
|
||||
sfx/player/polled.o \
|
||||
|
@ -52,14 +52,16 @@ protected:
|
||||
sfx_pcm_feed_t *_feed;
|
||||
|
||||
/* Timestamp of next frame requested by stream driver. */
|
||||
sfx_timestamp_t _time;
|
||||
Audio::Timestamp _time;
|
||||
|
||||
public:
|
||||
PCMFeedAudioStream(sfx_pcm_feed_t *feed) : _feed(feed) {
|
||||
PCMFeedAudioStream(sfx_pcm_feed_t *feed)
|
||||
: _feed(feed),
|
||||
_time(g_system->getMillis(), feed->conf.rate) {
|
||||
|
||||
_feed->frame_size = (_feed->conf.stereo ? 2 : 1) * ((_feed->conf.format & SFX_PCM_FORMAT_16) ? 2 : 1);
|
||||
_mode = FEED_MODE_ALIVE;
|
||||
_gap = 0;
|
||||
_time = sfx_new_timestamp(g_system->getMillis(), _feed->conf.rate);
|
||||
}
|
||||
|
||||
~PCMFeedAudioStream() {
|
||||
@ -79,12 +81,12 @@ protected:
|
||||
|
||||
void PCMFeedAudioStream::queryTimestamp() {
|
||||
if (_feed->get_timestamp) {
|
||||
sfx_timestamp_t stamp;
|
||||
int val = _feed->get_timestamp(_feed, &stamp);
|
||||
Audio::Timestamp stamp;
|
||||
int val = _feed->get_timestamp(_feed, stamp);
|
||||
|
||||
switch (val) {
|
||||
case PCM_FEED_TIMESTAMP:
|
||||
_gap = sfx_timestamp_frame_diff(stamp, _time);
|
||||
_gap = stamp.frameDiff(_time);
|
||||
|
||||
if (_gap >= 0)
|
||||
_mode = FEED_MODE_ALIVE;
|
||||
@ -101,8 +103,8 @@ void PCMFeedAudioStream::queryTimestamp() {
|
||||
// on DC."
|
||||
// That makes some sense.
|
||||
_mode = FEED_MODE_RESTART;
|
||||
_time = sfx_new_timestamp(g_system->getMillis(), _feed->conf.rate);
|
||||
_gap = sfx_timestamp_frame_diff(stamp, _time);
|
||||
_time = Audio::Timestamp(g_system->getMillis(), _feed->conf.rate);
|
||||
_gap = stamp.frameDiff(_time);
|
||||
|
||||
if (_gap < 0)
|
||||
_gap = 0;
|
||||
@ -134,7 +136,7 @@ int PCMFeedAudioStream::readBuffer(int16 *buffer, const int numSamples) {
|
||||
// create a fake timestamp based on the current time. For comparison, a real
|
||||
// timestamp could be adjusted for pauses in sound processing. And it would
|
||||
// be synced for all audio streams.
|
||||
sfx_timestamp_t timestamp = sfx_new_timestamp(g_system->getMillis(), _feed->conf.rate);
|
||||
Audio::Timestamp timestamp(g_system->getMillis(), _feed->conf.rate);
|
||||
|
||||
int channels, frames_req;
|
||||
int frames_recv = 0;
|
||||
@ -153,7 +155,7 @@ int PCMFeedAudioStream::readBuffer(int16 *buffer, const int numSamples) {
|
||||
if (_mode == FEED_MODE_IDLE || _mode == FEED_MODE_DEAD) {
|
||||
memset(buf_pos, 0, frames_left * channels * 2);
|
||||
|
||||
_time = sfx_timestamp_add(_time, frames_left);
|
||||
_time = _time.addFrames(frames_left);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -167,7 +169,7 @@ int PCMFeedAudioStream::readBuffer(int16 *buffer, const int numSamples) {
|
||||
|
||||
_gap -= frames;
|
||||
frames_recv += frames;
|
||||
_time = sfx_timestamp_add(_time, frames);
|
||||
_time = _time.addFrames(frames);
|
||||
} else {
|
||||
int frames = _feed->poll(_feed, buf_pos, frames_left);
|
||||
|
||||
@ -175,7 +177,7 @@ int PCMFeedAudioStream::readBuffer(int16 *buffer, const int numSamples) {
|
||||
U8_to_S16(buf_pos, frames * channels);
|
||||
|
||||
frames_recv += frames;
|
||||
_time = sfx_timestamp_add(_time, frames);
|
||||
_time = _time.addFrames(frames);
|
||||
|
||||
if (frames < frames_left)
|
||||
queryTimestamp();
|
||||
|
@ -37,7 +37,7 @@ static song_iterator_t *play_it;
|
||||
static int play_paused = 0;
|
||||
static sfx_softseq_t *seq;
|
||||
static int volume = 100;
|
||||
static sfx_timestamp_t new_timestamp;
|
||||
static Audio::Timestamp new_timestamp;
|
||||
static int new_song = 0;
|
||||
|
||||
/* The time counter is used to determine how close to the end of a tick we are.
|
||||
@ -117,13 +117,13 @@ void ppf_destroy(sfx_pcm_feed_t *self) {
|
||||
/* no-op */
|
||||
}
|
||||
|
||||
int ppf_get_timestamp(sfx_pcm_feed_t *self, sfx_timestamp_t *timestamp) {
|
||||
int ppf_get_timestamp(sfx_pcm_feed_t *self, Audio::Timestamp ×tamp) {
|
||||
if (!new_song)
|
||||
return PCM_FEED_IDLE;
|
||||
|
||||
/* Otherwise, we have a timestamp: */
|
||||
|
||||
*timestamp = new_timestamp;
|
||||
timestamp = new_timestamp;
|
||||
new_song = 0;
|
||||
return PCM_FEED_TIMESTAMP;
|
||||
}
|
||||
@ -215,7 +215,7 @@ static int pp_add_iterator(song_iterator_t *it, uint32 start_time) {
|
||||
/* The check must happen HERE, and not at the beginning of the
|
||||
function, to avoid a race condition with the mixer. */
|
||||
if (old == NULL) {
|
||||
new_timestamp = sfx_new_timestamp(start_time, seq->pcm_conf.rate);
|
||||
new_timestamp = Audio::Timestamp(start_time, seq->pcm_conf.rate);
|
||||
/* ASAP otherwise */
|
||||
time_counter = 0;
|
||||
new_song = 1;
|
||||
|
@ -27,7 +27,7 @@
|
||||
#define SCI_SFX_SFX_PCM_H
|
||||
|
||||
#include "sci/sfx/sfx.h"
|
||||
#include "sci/sfx/sfx_time.h"
|
||||
#include "sound/timestamp.h"
|
||||
|
||||
namespace Sci {
|
||||
|
||||
@ -80,10 +80,9 @@ struct sfx_pcm_feed_t {
|
||||
** free(self) should be part of this function, if applicable.
|
||||
*/
|
||||
|
||||
int
|
||||
(*get_timestamp)(sfx_pcm_feed_t *self, sfx_timestamp_t *timestamp);
|
||||
int (*get_timestamp)(sfx_pcm_feed_t *self, Audio::Timestamp ×tamp);
|
||||
/* Determines the timestamp of the next frame-to-read
|
||||
** Returns : (sfx_timestamp_t) timestamp: The timestamp of the next frame
|
||||
** Returns : (Timestamp &) timestamp: The timestamp of the next frame
|
||||
** (int) PCM_FEED_*
|
||||
** This function is OPTIONAL and may be NULL
|
||||
*/
|
||||
|
@ -1,85 +0,0 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* $URL$
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SCI_SFX_SFX_TIME_H
|
||||
#define SCI_SFX_SFX_TIME_H
|
||||
|
||||
#include "common/scummsys.h"
|
||||
|
||||
namespace Sci {
|
||||
|
||||
struct sfx_timestamp_t {
|
||||
uint32 msecs;
|
||||
int frame_rate;
|
||||
int frame_offset;
|
||||
/* Total time: msecs + frame_offset/frame_rate */
|
||||
};
|
||||
|
||||
|
||||
sfx_timestamp_t sfx_new_timestamp(const uint32 msecs, const int frame_rate);
|
||||
/* Creates a new mutable timestamp
|
||||
** Parameters: (uint32) msecs: Initial timestamp
|
||||
** (int) frame_rate: Frame rate, for increasing the time stamp
|
||||
*/
|
||||
|
||||
sfx_timestamp_t sfx_timestamp_add(sfx_timestamp_t timestamp, int frames);
|
||||
/* Adds a number of frames to a timestamp
|
||||
** Parameters: (sfx_timestampt_t *) timestamp: The timestamp to update
|
||||
** (int) frames: Number of frames to add
|
||||
** Returns : (sfx_timestamp_t) The increased timestamp
|
||||
*/
|
||||
|
||||
sfx_timestamp_t sfx_timestamp_renormalise(sfx_timestamp_t timestamp, int new_freq);
|
||||
/* Translates a timestamp to a new base frame frequency
|
||||
** Parameters: (sfx_timestamp_t *) timestamp: The timestamp to normalise
|
||||
** (int) new_freq: The new frequency to normalise to
|
||||
** Returns : (sfx_timestamp_t) The re-normalised timestamp
|
||||
** The translation looses accuracy in the order of magnitude of milliseconds
|
||||
** for "usual" sampling frequencies.
|
||||
*/
|
||||
|
||||
int sfx_timestamp_frame_diff(sfx_timestamp_t a, sfx_timestamp_t b);
|
||||
/* Computes the difference (# of frames) between two timestamps
|
||||
** Parameters: (sfx_timestamp) a: See below
|
||||
** (sfx_timestamp) b: See below
|
||||
** Returns : (int) a-b
|
||||
*/
|
||||
|
||||
int sfx_timestamp_msecs_diff(sfx_timestamp_t a, sfx_timestamp_t b);
|
||||
/* Computes the difference (# of milliseconds) between two timestamps
|
||||
** Parameters: (sfx_timestamp) a: See below
|
||||
** (sfx_timestamp) b: See below
|
||||
** Returns : (int) a-b
|
||||
*/
|
||||
|
||||
void sfx_timestamp_gettime(sfx_timestamp_t *timestamp, uint32 *msecs);
|
||||
/* Determines the time described by a given timestamp
|
||||
** Parameters: (sfx_timestamp_t *) timestamp: Timestamp to read from
|
||||
** Returns : (uint32 *) msecs: Milliseconds since startup
|
||||
*/
|
||||
|
||||
} // End of namespace Sci
|
||||
|
||||
#endif // SCI_SFX_SFX_TIME_H
|
@ -1,93 +0,0 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* $URL$
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sci/sfx/sfx_time.h"
|
||||
#include "sci/tools.h"
|
||||
|
||||
namespace Sci {
|
||||
|
||||
sfx_timestamp_t sfx_new_timestamp(const uint32 msecs, const int frame_rate) {
|
||||
sfx_timestamp_t r;
|
||||
r.msecs = msecs;
|
||||
r.frame_rate = frame_rate;
|
||||
r.frame_offset = 0;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
sfx_timestamp_t sfx_timestamp_add(sfx_timestamp_t timestamp, int frames) {
|
||||
timestamp.frame_offset += frames;
|
||||
|
||||
if (timestamp.frame_offset < 0) {
|
||||
int secsub = 1 + (-timestamp.frame_offset / timestamp.frame_rate);
|
||||
|
||||
timestamp.frame_offset += timestamp.frame_rate * secsub;
|
||||
timestamp.msecs -= secsub * 1000;
|
||||
}
|
||||
|
||||
timestamp.msecs += (timestamp.frame_offset / timestamp.frame_rate) * 1000;
|
||||
timestamp.frame_offset %= timestamp.frame_rate;
|
||||
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
int sfx_timestamp_frame_diff(sfx_timestamp_t a, sfx_timestamp_t b) {
|
||||
int msecdelta = 0;
|
||||
|
||||
if (a.frame_rate != b.frame_rate) {
|
||||
fprintf(stderr, "Fatal: The semantics of subtracting two timestamps with a different base from each other is not defined!\n");
|
||||
BREAKPOINT();
|
||||
}
|
||||
|
||||
if (a.msecs != b.msecs)
|
||||
msecdelta = (long(a.msecs) - long(b.msecs)) * a.frame_rate / 1000;
|
||||
|
||||
return msecdelta + a.frame_offset - b.frame_offset;
|
||||
}
|
||||
|
||||
int sfx_timestamp_msecs_diff(sfx_timestamp_t t1, sfx_timestamp_t t2) {
|
||||
uint32 msecs1, msecs2;
|
||||
|
||||
sfx_timestamp_gettime(&t1, &msecs1);
|
||||
sfx_timestamp_gettime(&t2, &msecs2);
|
||||
|
||||
return long(msecs1) - long(msecs2);
|
||||
}
|
||||
|
||||
sfx_timestamp_t sfx_timestamp_renormalise(sfx_timestamp_t timestamp, int new_freq) {
|
||||
sfx_timestamp_t r;
|
||||
sfx_timestamp_gettime(×tamp, &r.msecs);
|
||||
r.frame_rate = new_freq;
|
||||
r.frame_offset = 0;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void sfx_timestamp_gettime(sfx_timestamp_t *timestamp, uint32 *msecs) {
|
||||
*msecs = timestamp->msecs +
|
||||
timestamp->frame_offset * 1000l / timestamp->frame_rate;
|
||||
}
|
||||
|
||||
} // End of namespace Sci
|
@ -1,55 +0,0 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* $URL$
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sfx_time.h>
|
||||
#include <assert.h>
|
||||
|
||||
using namespace Sci;
|
||||
|
||||
sfx_timestamp_t a, b, c;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int i;
|
||||
a = sfx_new_timestamp(10, 0, 1000);
|
||||
b = sfx_new_timestamp(10, 1000, 1000);
|
||||
c = sfx_new_timestamp(10, 2000, 1000);
|
||||
|
||||
assert(sfx_timestamp_sample_diff(a, b) == -1);
|
||||
assert(sfx_timestamp_sample_diff(b, a) == 1);
|
||||
assert(sfx_timestamp_sample_diff(c, a) == 2);
|
||||
assert(sfx_timestamp_sample_diff(sfx_timestamp_add(b, 2000), a) == 2001);
|
||||
assert(sfx_timestamp_sample_diff(sfx_timestamp_add(b, 2000), sfx_timestamp_add(a, -1000)) == 3001);
|
||||
|
||||
for (i = -10000; i < 10000; i++) {
|
||||
int v = sfx_timestamp_sample_diff(sfx_timestamp_add(c, i), c);
|
||||
if (v != i) {
|
||||
fprintf(stderr, "After adding %d samples: Got diff of %d\n", i, v);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user