Makefile: remove spurious tab
[xcsoar.git] / src / Audio / PCMPlayer.hpp
blob98857e9056562d6f371411bac151d6d4749b1105
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef XCSOAR_AUDIO_PCM_PLAYER_HPP
25 #define XCSOAR_AUDIO_PCM_PLAYER_HPP
27 #ifdef ANDROID
28 #include "Thread/Mutex.hpp"
29 #include "SLES/Object.hpp"
30 #include "SLES/Play.hpp"
31 #include "SLES/AndroidSimpleBufferQueue.hpp"
33 #include <stdint.h>
34 #endif
36 #include <stddef.h>
38 class PCMSynthesiser;
40 /**
41 * An audio player that plays synthesized 16 bit mono PCM data. It is
42 * being fed by a #PCMSynthesiser object that gets called when more
43 * PCM samples are needed.
45 class PCMPlayer {
46 unsigned sample_rate;
48 PCMSynthesiser *synthesiser;
50 #ifdef ANDROID
52 SLES::Object engine_object;
54 SLES::Object mix_object;
56 SLES::Object play_object;
57 SLES::Play play;
58 SLES::AndroidSimpleBufferQueue queue;
60 /**
61 * This mutex protects the attributes "next" and "filled". It is
62 * only needed while playback is launched, when the initial buffers
63 * are being enqueued in the caller thread, while another thread may
64 * invoke the registered callback.
66 Mutex mutex;
68 /**
69 * The index of the next buffer to be enqueued.
71 unsigned next;
73 /**
74 * Does the "next" buffer already contain synthesised samples? This
75 * can happen when PCMSynthesiser::Synthesise() has been called, but
76 * the OpenSL/ES buffer queue was full. The buffer will then be
77 * postponed.
79 bool filled;
81 /**
82 * An array of buffers. It's one more than being managed by
83 * OpenSL/ES, and the one not enqueued (see attribute #next) will be
84 * written to.
86 int16_t buffers[3][4096];
88 #elif defined(WIN32)
89 #else
90 #endif
92 public:
93 PCMPlayer();
94 ~PCMPlayer();
96 /**
97 * Start playback.
99 * @param synthesiser a PCMSynthesiser instance that will be used to
100 * generate sound; the caller is responsible for releasing it (not
101 * before playback is stopped)
103 bool Start(PCMSynthesiser &synthesiser, unsigned sample_rate);
106 * Stop playback and close the audio device. This method is
107 * synchronous.
109 void Stop();
111 #ifdef ANDROID
112 void Enqueue();
113 #elif defined(WIN32)
114 #else
115 void Synthesise(void *buffer, size_t n);
116 #endif
119 #endif