~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/sound/allegro_s.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: allegro_s.cpp 15305 2009-02-01 11:52:41Z rubidium $ */
 
2
 
 
3
/** @file allegro_s.cpp Playing sound via Allegro. */
 
4
 
 
5
#ifdef WITH_ALLEGRO
 
6
 
 
7
#include "../stdafx.h"
 
8
 
 
9
#include "../driver.h"
 
10
#include "../mixer.h"
 
11
#include "../sdl.h"
 
12
#include "../debug.h"
 
13
#include "allegro_s.h"
 
14
#include <allegro.h>
 
15
 
 
16
static FSoundDriver_Allegro iFSoundDriver_Allegro;
 
17
/** The stream we are writing too */
 
18
static AUDIOSTREAM *_stream = NULL;
 
19
/** The number of samples in the buffer */
 
20
static const int BUFFER_SIZE = 512;
 
21
 
 
22
void SoundDriver_Allegro::MainLoop()
 
23
{
 
24
        /* We haven't opened a stream yet */
 
25
        if (_stream == NULL) return;
 
26
 
 
27
        void *data = get_audio_stream_buffer(_stream);
 
28
        /* We don't have to fill the stream yet */
 
29
        if (data == NULL) return;
 
30
 
 
31
        /* Mix the samples */
 
32
        MxMixSamples(data, BUFFER_SIZE);
 
33
 
 
34
        /* Allegro sound is always unsigned, so we need to correct that */
 
35
        uint16 *snd = (uint16*)data;
 
36
        for (int i = 0; i < BUFFER_SIZE * 2; i++) snd[i] ^= 0x8000;
 
37
 
 
38
        /* Tell we've filled the stream */
 
39
        free_audio_stream_buffer(_stream);
 
40
}
 
41
 
 
42
/** There are multiple modules that might be using Allegro and
 
43
 * Allegro can only be initiated once. */
 
44
extern int _allegro_instance_count;
 
45
 
 
46
const char *SoundDriver_Allegro::Start(const char * const *parm)
 
47
{
 
48
        if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) return NULL;
 
49
        _allegro_instance_count++;
 
50
 
 
51
        /* Initialise the sound */
 
52
        if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) return NULL;
 
53
 
 
54
        /* Okay, there's no soundcard */
 
55
        if (digi_card == DIGI_NONE) {
 
56
                DEBUG(driver, 0, "allegro: no sound card found");
 
57
                return NULL;
 
58
        }
 
59
 
 
60
        _stream = play_audio_stream(BUFFER_SIZE, 16, true, 11025, 255, 128);
 
61
        return NULL;
 
62
}
 
63
 
 
64
void SoundDriver_Allegro::Stop()
 
65
{
 
66
        if (_stream != NULL) {
 
67
                stop_audio_stream(_stream);
 
68
                _stream = NULL;
 
69
        }
 
70
        remove_sound();
 
71
 
 
72
        if (--_allegro_instance_count == 0) allegro_exit();
 
73
}
 
74
 
 
75
#endif /* WITH_ALLEGRO */