~ubuntu-branches/ubuntu/trusty/rlvm/trusty

« back to all changes in this revision

Viewing changes to .pc/002_675426ad62bccf1de10b0ae31dd46331ec47aacb.patch/src/Systems/SDL/SDLSoundChunk.cpp

  • Committer: Package Import Robot
  • Author(s): Ying-Chun Liu (PaulLiu)
  • Date: 2013-11-02 02:57:13 UTC
  • mfrom: (10.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20131102025713-yzg31grxr8i7xerh
Tags: 0.13-1
* New upstream release
  - rlvm will now warn on startup when it detects Japanese save data, but
    English patched game files, and offer to reset the save data.
  - Much better support for Little Busters. Most graphical glitches during
    the Little Busters Refrain have been fixed.
  - TCC tone curve effects have been reverse-engineered and implemented
    (thanks to lurkmoar)
  - Sepia scenes (and other graphical filters) should look much better.
  - Simple shake commands implemented (fancy per-layer shaking still
    unimplemented).
  - Make animations smooth: data should be uploaded to the graphics card
    before an animation loop starts, not while the animation loop is
    running.
  - Fixes finding system fonts on Linux
  - Thanks to Elliot Glaysher <glaysher@umich.edu>
* Remove upstreamed patches:
  - debian/patches/002_675426ad62bccf1de10b0ae31dd46331ec47aacb.patch
  - debian/patches/003_5dafabf5448635c4d4526d6e35ea7ec664a27261.patch
  - debian/patches/004_boost-drop-mt.patch
  - debian/patches/005_missing-include.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
 
// vi:tw=80:et:ts=2:sts=2
3
 
//
4
 
// -----------------------------------------------------------------------
5
 
//
6
 
// This file is part of RLVM, a RealLive virtual machine clone.
7
 
//
8
 
// -----------------------------------------------------------------------
9
 
//
10
 
// Copyright (C) 2007 Elliot Glaysher
11
 
//
12
 
// This program is free software; you can redistribute it and/or modify
13
 
// it under the terms of the GNU General Public License as published by
14
 
// the Free Software Foundation; either version 3 of the License, or
15
 
// (at your option) any later version.
16
 
//
17
 
// This program is distributed in the hope that it will be useful,
18
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 
// GNU General Public License for more details.
21
 
//
22
 
// You should have received a copy of the GNU General Public License
23
 
// along with this program; if not, write to the Free Software
24
 
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
25
 
//
26
 
// -----------------------------------------------------------------------
27
 
 
28
 
#include "Systems/SDL/SDLSoundChunk.hpp"
29
 
 
30
 
#include <SDL/SDL_mixer.h>
31
 
#include <boost/algorithm/string.hpp>
32
 
 
33
 
#include "Systems/Base/SoundSystem.hpp"
34
 
#include "Systems/SDL/SDLAudioLocker.hpp"
35
 
#include "xclannad/wavfile.h"
36
 
 
37
 
SDLSoundChunk::PlayingTable SDLSoundChunk::s_playing_table;
38
 
 
39
 
SDLSoundChunk::SDLSoundChunk(const boost::filesystem::path& path)
40
 
    : sample_(loadSample(path)) {
41
 
}
42
 
 
43
 
SDLSoundChunk::SDLSoundChunk(char* data, int length)
44
 
    : sample_(Mix_LoadWAV_RW(SDL_RWFromMem(data, length+0x2c), 1)),
45
 
      data_(data) {
46
 
}
47
 
 
48
 
SDLSoundChunk::~SDLSoundChunk() {
49
 
  Mix_FreeChunk(sample_);
50
 
  data_.reset();
51
 
}
52
 
 
53
 
Mix_Chunk* SDLSoundChunk::loadSample(const boost::filesystem::path& path) {
54
 
  if (boost::iequals(path.extension(), ".nwa")) {
55
 
    // Hack to load NWA sounds into a MixChunk. I was resisted doing this
56
 
    // because I assumed there was a better way, but this is essentially what
57
 
    // jagarl does in xclannad too :(
58
 
    FILE* f = fopen(path.external_file_string().c_str(), "r");
59
 
    if (!f)
60
 
      return NULL;
61
 
    int size = 0;
62
 
    char* data = NWAFILE::ReadAll(f, size);
63
 
    fclose(f);
64
 
 
65
 
    Mix_Chunk* chunk = Mix_LoadWAV_RW(SDL_RWFromMem(data, size), 1);
66
 
    delete [] data;
67
 
 
68
 
    return chunk;
69
 
  } else {
70
 
    return Mix_LoadWAV(path.external_file_string().c_str());
71
 
  }
72
 
}
73
 
 
74
 
void SDLSoundChunk::playChunkOn(int channel, int loops) {
75
 
  {
76
 
    SDLAudioLocker locker;
77
 
    s_playing_table[channel] = shared_from_this();
78
 
  }
79
 
 
80
 
  if (Mix_PlayChannel(channel, sample_, loops) == -1) {
81
 
    // TODO: Throw something here.
82
 
  }
83
 
}
84
 
 
85
 
void SDLSoundChunk::fadeInChunkOn(int channel, int loops, int ms) {
86
 
  {
87
 
    SDLAudioLocker locker;
88
 
    s_playing_table[channel] = shared_from_this();
89
 
  }
90
 
 
91
 
  if (Mix_FadeInChannel(channel, sample_, loops, ms) == -1) {
92
 
    // TODO: Throw something here.
93
 
  }
94
 
}
95
 
 
96
 
// static
97
 
void SDLSoundChunk::SoundChunkFinishedPlayback(int channel) {
98
 
  // Don't need an SDLAudioLocker because we're in the audio callback right
99
 
  // now.
100
 
  //
101
 
  // Decrease the refcount of the SDLSoundChunk that just finished
102
 
  // playing.
103
 
  s_playing_table[channel].reset();
104
 
}
105
 
 
106
 
// static
107
 
int SDLSoundChunk::FindNextFreeExtraChannel() {
108
 
  SDLAudioLocker locker;
109
 
 
110
 
  for (int i = NUM_BASE_CHANNELS;
111
 
      i < NUM_BASE_CHANNELS + NUM_EXTRA_WAVPLAY_CHANNELS; ++i) {
112
 
    if (s_playing_table[i].get() == 0)
113
 
      return i;
114
 
  }
115
 
 
116
 
  return -1;
117
 
}
118
 
 
119
 
// static
120
 
void SDLSoundChunk::StopChannel(int channel) {
121
 
  Mix_HaltChannel(channel);
122
 
}
123
 
 
124
 
void SDLSoundChunk::StopAllChannels() {
125
 
  Mix_HaltChannel(-1);
126
 
}
127
 
 
128
 
void SDLSoundChunk::FadeOut(const int channel, const int fadetime) {
129
 
  Mix_FadeOutChannel(channel, fadetime);
130
 
}