~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to libsound/aos4/sound_handler_ahi.h

  • Committer: Bazaar Package Importer
  • Author(s): Sindhudweep Narayan Sarkar
  • Date: 2009-10-07 00:06:10 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20091007000610-mj9rwqe774gizn1j
Tags: 0.8.6-0ubuntu1
new upstream release 0.8.6 (LP: #435897)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// sound_handler_ahi.h: Sound handling using standard AHI
 
2
//
 
3
//   Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
4
//
 
5
// This program is free software; you can redistribute it and/or modify
 
6
// it under the terms of the GNU General Public License as published by
 
7
// the Free Software Foundation; either version 3 of the License, or
 
8
// (at your option) any later version.
 
9
 
 
10
// This program is distributed in the hope that it will be useful,
 
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
// GNU General Public License for more details.
 
14
//
 
15
// You should have received a copy of the GNU General Public License
 
16
// along with this program; if not, write to the Free Software
 
17
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 
 
19
 
 
20
#ifndef SOUND_HANDLER_AOS4_H
 
21
#define SOUND_HANDLER_AOS4_H
 
22
 
 
23
 
 
24
#include "sound_handler.h" // for inheritance
 
25
 
 
26
#include <vector> // for composition (Sounds)
 
27
#include <set> // for composition (InputStreams)
 
28
#include <fstream> // for composition (file_stream)
 
29
#include <boost/thread/mutex.hpp>
 
30
 
 
31
#include <proto/dos.h>
 
32
#include <proto/exec.h>
 
33
#include <proto/ahi.h>
 
34
 
 
35
#include <devices/ahi.h>
 
36
#include <exec/memory.h>
 
37
 
 
38
#include <sys/types.h>
 
39
// Forward declarations
 
40
namespace gnash {
 
41
    class SimpleBuffer;
 
42
    namespace sound {
 
43
        class EmbedSound;
 
44
        class InputStream;
 
45
    }
 
46
}
 
47
 
 
48
namespace gnash {
 
49
namespace sound {
 
50
 
 
51
/// AHI-based sound_handler
 
52
class AOS4_sound_handler : public sound_handler
 
53
{
 
54
private:
 
55
        struct MsgPort          *_port;
 
56
        uint32                           _timerSig;
 
57
        struct TimeRequest      *_timerio;
 
58
        struct TimerIFace       *ITimer;
 
59
 
 
60
        struct AHIIFace         *IAHI;
 
61
        struct Library          *AHIBase;
 
62
        struct MsgPort          *AHImp;                                 //AHI Message Port
 
63
        struct AHIRequest       *AHIio;
 
64
        BYTE                             AHIDevice;
 
65
        struct AHIRequest       *AHIios[2];
 
66
        APTR                             AHIiocopy;
 
67
        ULONG                            AHICurBuf;
 
68
        bool                             AHIReqSent[2];
 
69
        UBYTE                           *PlayBuffer[2];
 
70
        ULONG                            BufferFill;
 
71
        UBYTE                           *BufferPointer;
 
72
        ULONG                            Buffer;
 
73
 
 
74
        struct Process          *AudioPump;
 
75
 
 
76
        bool TimerInit(void);
 
77
        void TimerExit(void);
 
78
        void TimerReset(uint32 microDelay);
 
79
 
 
80
    /// Initialize audio card
 
81
    void initAudio();
 
82
    void openAudio();
 
83
    void closeAudio();
 
84
 
 
85
    bool _audioOpened;
 
86
        bool _closing;
 
87
 
 
88
        struct DeathMessage *_dmsg;     // the child Death Message
 
89
        struct MsgPort *_DMreplyport;   // and its port
 
90
        
 
91
    /// Mutex for making sure threads doesn't mess things up
 
92
    boost::mutex _mutex;
 
93
 
 
94
    /// Mutex protecting _muted (defined in base class)
 
95
    mutable boost::mutex _mutedMutex;
 
96
 
 
97
    /// File stream for dump file
 
98
    //
 
99
    /// TODO: move to base class ?
 
100
    ///
 
101
    std::ofstream file_stream;
 
102
 
 
103
    // write a .WAV file header
 
104
    void write_wave_header(std::ofstream& outfile);
 
105
 
 
106
    // See dox in sound_handler.h
 
107
    void mix(boost::int16_t* outSamples, boost::int16_t* inSamples,
 
108
                unsigned int nSamples, float volume);
 
109
 
 
110
        void MixAudio (boost::uint8_t *dst, const boost::uint8_t *src, boost::uint32_t len, int volume);
 
111
 
 
112
public:
 
113
 
 
114
    AOS4_sound_handler();
 
115
 
 
116
    AOS4_sound_handler(const std::string& wave_file);
 
117
 
 
118
    ~AOS4_sound_handler();
 
119
 
 
120
    // See dox in sound_handler.h
 
121
    virtual int create_sound(std::auto_ptr<SimpleBuffer> data, std::auto_ptr<media::SoundInfo> sinfo);
 
122
 
 
123
    // See dox in sound_handler.h
 
124
    // overridden to serialize access to the data buffer slot
 
125
    virtual StreamBlockId addSoundBlock(unsigned char* data,
 
126
                                       unsigned int data_bytes,
 
127
                                       unsigned int sample_count,
 
128
                                       int streamId);
 
129
 
 
130
    // See dox in sound_handler.h
 
131
    virtual void    stop_sound(int sound_handle);
 
132
 
 
133
    // See dox in sound_handler.h
 
134
    virtual void    delete_sound(int sound_handle);
 
135
 
 
136
    // See dox in sound_handler.h
 
137
    virtual void reset();
 
138
 
 
139
    // See dox in sound_handler.h
 
140
    virtual void    stop_all_sounds();
 
141
 
 
142
    // See dox in sound_handler.h
 
143
    virtual int get_volume(int sound_handle);
 
144
 
 
145
    // See dox in sound_handler.h
 
146
    virtual void    set_volume(int sound_handle, int volume);
 
147
 
 
148
    // See dox in sound_handler.h
 
149
    virtual media::SoundInfo* get_sound_info(int soundHandle);
 
150
 
 
151
    // See dox in sound_handler.h
 
152
    // overridden to serialize access to the _muted member
 
153
    virtual void mute();
 
154
 
 
155
    // See dox in sound_handler.h
 
156
    // overridden to serialize access to the _muted member
 
157
    virtual void unmute();
 
158
 
 
159
    // See dox in sound_handler.h
 
160
    // overridden to serialize access to the _muted member
 
161
    virtual bool is_muted() const;
 
162
 
 
163
    // See dox in sound_handler.h
 
164
    // overridden to close audio card
 
165
    virtual void pause();
 
166
 
 
167
    // See dox in sound_handler.h
 
168
    // overridden to open audio card
 
169
    virtual void unpause();
 
170
 
 
171
    // See dox in sound_handler.h
 
172
    virtual unsigned int get_duration(int sound_handle);
 
173
 
 
174
    // See dox in sound_handler.h
 
175
    virtual unsigned int tell(int sound_handle);
 
176
 
 
177
    // See dox in sound_handler.h
 
178
    // Overridden to unpause SDL audio
 
179
    void plugInputStream(std::auto_ptr<InputStream> in);
 
180
 
 
181
    // See dox in sound_handler.h
 
182
    void fetchSamples(boost::int16_t* to, unsigned int nSamples);
 
183
 
 
184
        int audioTask();
 
185
};
 
186
 
 
187
 
 
188
 
 
189
} // gnash.sound namespace
 
190
} // namespace gnash
 
191
 
 
192
#endif // SOUND_HANDLER_SDL_H