Skip to content

Commit

Permalink
BACKENDS: Only expose one set of functions for AudioCDManager
Browse files Browse the repository at this point in the history
Engines should only have to call one set of functions and not decide between the two. In fact, the 'emulation' API was documented to just call the 'real CD' API.
  • Loading branch information
Matthew Hoops authored and Johannes Schickel committed Mar 13, 2016
1 parent dc0d4fc commit aa6ff44
Show file tree
Hide file tree
Showing 24 changed files with 281 additions and 267 deletions.
81 changes: 19 additions & 62 deletions backends/audiocd/audiocd.h
Expand Up @@ -48,26 +48,31 @@ class AudioCDManager : Common::NonCopyable {
};

/**
* @name Emulated playback functions
* Engines should call these functions. Not all platforms
* support cd playback, and these functions should try to
* emulate it.
* Initialize the specified CD drive for audio playback.
* @return true if the CD drive was inited successfully
*/
//@{
virtual bool open() = 0;

/**
* Close the currently open CD drive
*/
virtual void close() = 0;

/**
* Start audio CD playback
* @param track the track to play.
* @param numLoops how often playback should be repeated (-1 = infinitely often).
* @param startFrame the frame at which playback should start (75 frames = 1 second).
* @param duration the number of frames to play.
* @param only_emulate determines if the track should be emulated only
* @param track the track to play.
* @param numLoops how often playback should be repeated (<=0 means infinitely often).
* @param startFrame the frame at which playback should start (75 frames = 1 second).
* @param duration the number of frames to play.
* @param onlyEmulate determines if the track should be emulated only
* @note The @c onlyEmulate parameter is deprecated.
* @return @c true if the track started playing, @c false otherwise
*/
virtual void play(int track, int numLoops, int startFrame, int duration, bool only_emulate = false) = 0;
virtual bool play(int track, int numLoops, int startFrame, int duration, bool onlyEmulate = false) = 0;

/**
* Get if audio is being played.
* @return true if CD or emulated audio is playing
* @return true if CD audio is playing
*/
virtual bool isPlaying() const = 0;

Expand All @@ -82,12 +87,12 @@ class AudioCDManager : Common::NonCopyable {
virtual void setBalance(int8 balance) = 0;

/**
* Stop CD or emulated audio playback.
* Stop audio playback.
*/
virtual void stop() = 0;

/**
* Update CD or emulated audio status.
* Update audio status.
*/
virtual void update() = 0;

Expand All @@ -96,54 +101,6 @@ class AudioCDManager : Common::NonCopyable {
* @return a Status struct with playback data.
*/
virtual Status getStatus() const = 0;

//@}


/**
* @name Real CD audio methods
* These functions should be called from the emulated
* ones if they can't emulate the audio playback.
*/
//@{

/**
* Initialize the specified CD drive for audio playback.
* @return true if the CD drive was inited successfully
*/
virtual bool openCD() = 0;

/**
* Close the currently open CD drive
*/
virtual void closeCD() = 0;

/**
* Poll CD status.
* @return true if CD audio is playing
*/
virtual bool pollCD() const = 0;

/**
* Start CD audio playback.
* @param track the track to play.
* @param num_loops how often playback should be repeated (-1 = infinitely often).
* @param start_frame the frame at which playback should start (75 frames = 1 second).
* @param duration the number of frames to play.
*/
virtual void playCD(int track, int num_loops, int start_frame, int duration) = 0;

/**
* Stop CD audio playback.
*/
virtual void stopCD() = 0;

/**
* Update CD audio status.
*/
virtual void updateCD() = 0;

//@}
};

#endif
76 changes: 34 additions & 42 deletions backends/audiocd/default/default-audiocd.cpp
Expand Up @@ -38,7 +38,25 @@ DefaultAudioCDManager::DefaultAudioCDManager() {
assert(_mixer);
}

void DefaultAudioCDManager::play(int track, int numLoops, int startFrame, int duration, bool only_emulate) {
DefaultAudioCDManager::~DefaultAudioCDManager() {
// Subclasses should call close as well
close();
}

bool DefaultAudioCDManager::open() {
// For emulation, opening is always valid
close();
return true;
}

void DefaultAudioCDManager::close() {
// Only need to stop for emulation
stop();
}

bool DefaultAudioCDManager::play(int track, int numLoops, int startFrame, int duration, bool onlyEmulate) {
stop();

if (numLoops != 0 || startFrame != 0) {
_cd.track = track;
_cd.numLoops = numLoops;
Expand All @@ -56,9 +74,6 @@ void DefaultAudioCDManager::play(int track, int numLoops, int startFrame, int du
for (int i = 0; !stream && i < 2; ++i)
stream = Audio::SeekableAudioStream::openStreamFile(trackName[i]);

// Stop any currently playing emulated track
_mixer->stopHandle(_handle);

if (stream != 0) {
Audio::Timestamp start = Audio::Timestamp(0, startFrame, 75);
Audio::Timestamp end = duration ? Audio::Timestamp(0, startFrame + duration, 75) : stream->getLength();
Expand All @@ -71,65 +86,44 @@ void DefaultAudioCDManager::play(int track, int numLoops, int startFrame, int du
_emulating = true;
_mixer->playStream(Audio::Mixer::kMusicSoundType, &_handle,
Audio::makeLoopingAudioStream(stream, start, end, (numLoops < 1) ? numLoops + 1 : numLoops), -1, _cd.volume, _cd.balance);
} else {
_emulating = false;
if (!only_emulate)
playCD(track, numLoops, startFrame, duration);
return true;
}
}

return false;
}

void DefaultAudioCDManager::stop() {
if (_emulating) {
// Audio CD emulation
_mixer->stopHandle(_handle);
_emulating = false;
} else {
// Real Audio CD
stopCD();
}
}

bool DefaultAudioCDManager::isPlaying() const {
if (_emulating) {
// Audio CD emulation
// Audio CD emulation
if (_emulating)
return _mixer->isSoundHandleActive(_handle);
} else {
// Real Audio CD
return pollCD();
}

// The default class only handles emulation
return false;
}

void DefaultAudioCDManager::setVolume(byte volume) {
_cd.volume = volume;
if (_emulating) {
// Audio CD emulation
if (_mixer->isSoundHandleActive(_handle))
_mixer->setChannelVolume(_handle, _cd.volume);
} else {
// Real Audio CD

// Unfortunately I can't implement this atm
// since SDL doesn't seem to offer an interface method for this.

// g_system->setVolumeCD(_cd.volume);
}
// Audio CD emulation
if (_emulating && isPlaying())
_mixer->setChannelVolume(_handle, _cd.volume);
}

void DefaultAudioCDManager::setBalance(int8 balance) {
_cd.balance = balance;
if (_emulating) {
// Audio CD emulation
if (isPlaying())
_mixer->setChannelBalance(_handle, _cd.balance);
} else {
// Real Audio CD

// Unfortunately I can't implement this atm
// since SDL doesn't seem to offer an interface method for this.

// g_system->setBalanceCD(_cd.balance);
}
// Audio CD emulation
if (_emulating && isPlaying())
_mixer->setChannelBalance(_handle, _cd.balance);
}

void DefaultAudioCDManager::update() {
Expand All @@ -143,8 +137,6 @@ void DefaultAudioCDManager::update() {
// or not.
_emulating = false;
}
} else {
updateCD();
}
}

Expand All @@ -154,7 +146,7 @@ DefaultAudioCDManager::Status DefaultAudioCDManager::getStatus() const {
return info;
}

bool DefaultAudioCDManager::openCD() {
bool DefaultAudioCDManager::openRealCD() {
Common::String cdrom = ConfMan.get("cdrom");

// Try to parse it as an int
Expand Down
29 changes: 14 additions & 15 deletions backends/audiocd/default/default-audiocd.h
Expand Up @@ -36,18 +36,23 @@ class String;
class DefaultAudioCDManager : public AudioCDManager {
public:
DefaultAudioCDManager();
virtual ~DefaultAudioCDManager() {}
virtual ~DefaultAudioCDManager();

void play(int track, int numLoops, int startFrame, int duration, bool only_emulate = false);
void stop();
bool isPlaying() const;
void setVolume(byte volume);
void setBalance(int8 balance);
void update();
virtual bool open();
virtual void close();
virtual bool play(int track, int numLoops, int startFrame, int duration, bool onlyEmulate = false);
virtual void stop();
virtual bool isPlaying() const;
virtual void setVolume(byte volume);
virtual void setBalance(int8 balance);
virtual void update();
virtual Status getStatus() const; // Subclasses should override for better status results

bool openCD();
virtual void closeCD() {}
protected:
/**
* Open a CD using the cdrom config variable
*/
bool openRealCD();

/**
* Open a CD using the specified drive index
Expand All @@ -56,12 +61,6 @@ class DefaultAudioCDManager : public AudioCDManager {
*/
virtual bool openCD(int drive) { return false; }

virtual void updateCD() {}
virtual bool pollCD() const { return false; }
virtual void playCD(int track, int num_loops, int start_frame, int duration) {}
virtual void stopCD() {}

protected:
/**
* Open a CD from a specific drive
* @param drive The name of the drive/path
Expand Down

0 comments on commit aa6ff44

Please sign in to comment.