Sha256: 06956e1898ccec71e6cd691643a19a65ae613d3d06b21269db05b81dbcf47b87

Contents?: true

Size: 1.98 KB

Versions: 20

Compression:

Stored size: 1.98 KB

Contents

#include <Gosu/Audio.hpp>
#include "AudioImpl.hpp"
using namespace std;

// Returns the current state of a source
static ALint state(int& channel)
{
    ALint state;
    alGetSourcei(Gosu::al_source_for_channel(channel), AL_SOURCE_STATE, &state);
    if (state != AL_PLAYING && state != AL_PAUSED) {
        channel = Gosu::NO_CHANNEL;
    }
    return state;
}

Gosu::Channel::Channel()
: channel(NO_CHANNEL), token(0)
{
}

Gosu::Channel::Channel(int channel, int token)
: channel(channel), token(token)
{
}

int Gosu::Channel::current_channel() const
{
    if (channel != NO_CHANNEL && channel_expired(channel, token)) {
        channel = NO_CHANNEL;
    }
    return channel;
}

bool Gosu::Channel::playing() const
{
    if (current_channel() == NO_CHANNEL) return false;
    
    return state(channel) == AL_PLAYING;
}

bool Gosu::Channel::paused() const
{
    if (current_channel() == NO_CHANNEL) return false;

    return state(channel) == AL_PAUSED;
}

void Gosu::Channel::pause()
{
    if (playing()) {
        ALuint source = al_source_for_channel(channel);
        alSourcePause(source);
    }
}

void Gosu::Channel::resume()
{
    if (paused()) {
        ALuint source = al_source_for_channel(channel);
        alSourcePlay(source);
    }
}

void Gosu::Channel::stop()
{
    if (current_channel() == NO_CHANNEL) return;

    ALuint source = al_source_for_channel(channel);
    alSourceStop(source);
    channel = NO_CHANNEL;
}

void Gosu::Channel::set_volume(double volume)
{
    if (current_channel() == NO_CHANNEL) return;

    ALuint source = al_source_for_channel(channel);
    alSourcef(source, AL_GAIN, max(volume, 0.0));
}

void Gosu::Channel::set_pan(double pan)
{
    if (current_channel() == NO_CHANNEL) return;

    ALuint source = al_source_for_channel(channel);
    alSource3f(source, AL_POSITION, pan * 10, 0, 0);
}

void Gosu::Channel::set_speed(double speed)
{
    if (current_channel() == NO_CHANNEL) return;

    ALuint source = al_source_for_channel(channel);
    alSourcef(source, AL_PITCH, speed);
}

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
gosu-1.3.0 src/Channel.cpp
gosu-1.2.0 src/Channel.cpp
gosu-1.1.1.1 src/Channel.cpp
gosu-1.1.0 src/Channel.cpp
gosu-1.1.0.pre2 src/Channel.cpp
gosu-1.1.0.pre1 src/Channel.cpp
gosu-1.0.0 src/Channel.cpp
gosu-1.0.0.pre2 src/Channel.cpp
gosu-1.0.0.pre1 src/Channel.cpp
gosu-0.15.2 src/Channel.cpp
gosu-0.15.1 src/Channel.cpp
gosu-0.15.0 src/Channel.cpp
gosu-0.14.6.pre1 src/Channel.cpp
gosu-0.14.5 src/Channel.cpp
gosu-0.14.4 src/Channel.cpp
gosu-0.14.4.pre2 src/Channel.cpp
gosu-0.14.3.pre1 src/Channel.cpp
gosu-0.14.3 src/Channel.cpp
gosu-0.14.0 src/Channel.cpp
gosu-0.14.0.pre2 src/Channel.cpp