ROLAND  0.70
Amstrad Emulator based on Caprice Source rewritten in C++.
audio.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) by Fred Klaus *
3  * development@fkweb.de *
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 2 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 *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 #ifndef SDLTK_AUDIO_H
21 #define SDLTK_AUDIO_H
22 
23 #include "def.h"
24 #include "cpc.h"
25 #include "SDL.h"
26 
27 
28 namespace sdltk
29 {
30 
32  class Audio final
33  {
34 
35  public:
36  Audio(cpcx::Cpc * cpc);
37  ~Audio();
38 
39  int init();
40  void quit();
41 
42  uint dist() const;
43  uint mindist() const {return mMinSafeDist;}
44  uint maxdist() const {return mMaxSafeDist;}
45 
46  bool copied() const {return mBufferCopied;}
47  void setCopied(bool val) {mBufferCopied = val;}
48  void waitCopied() {while (!mBufferCopied) {SDL_Delay(1);} mBufferCopied = false;}
49 
50  void pause(bool value);
51 
52  static void update(void *userdata, Uint8 *stream, int len);
53 
54  private:
55  static cpcx::Cpc * mCpc;
56  static volatile bool mBufferCopied;
57  SDL_AudioSpec* mSpec;
58 
59  bool isInit;
60 
63 
64  uint alignSamples(uint given);
65  };
66 
67  inline uint Audio::dist() const // determine distance between play and write cursors
68  {
69  if (mCpc->sound().stream() < mCpc->sound().bufferPtr())
70  {
71  return mCpc->sound().bufferPtr()-mCpc->sound().stream();
72  }
73  else
74  {
75  return (mCpc->sound().bufferEnd() - mCpc->sound().stream())
76  +
77  (mCpc->sound().bufferPtr() - mCpc->sound().buffer());
78  }
79  }
80 
81 } // sdltk
82 
83 #endif // SDLTK_AUDIO_H
uint dist() const
Definition: audio.h:67
static void update(void *userdata, Uint8 *stream, int len)
Definition: audio.cpp:125
Manages all Audio related stuff.
Definition: audio.h:32
uint alignSamples(uint given)
Definition: audio.cpp:53
static volatile bool mBufferCopied
Definition: audio.h:56
void quit()
Definition: audio.cpp:43
void setCopied(bool val)
Definition: audio.h:47
void waitCopied()
Definition: audio.h:48
Sound & sound()
Definition: cpc.h:103
bool copied() const
Definition: audio.h:46
bool isInit
Definition: audio.h:59
SDL_AudioSpec * mSpec
Definition: audio.h:57
~Audio()
Definition: audio.cpp:38
tUBYTE * bufferPtr() const
Definition: sound.h:104
uint mindist() const
Definition: audio.h:43
uint maxdist() const
Definition: audio.h:44
tUBYTE * stream() const
Definition: sound.h:74
int init()
Definition: audio.cpp:63
uint mMinSafeDist
Definition: audio.h:61
tUBYTE * bufferEnd() const
Definition: sound.h:73
unsigned int uint
Definition: types.h:121
Audio(cpcx::Cpc *cpc)
Definition: audio.cpp:28
uint mMaxSafeDist
Definition: audio.h:62
Definition: cpc.h:61
sdltk::Audio audio & cpc
Definition: roland.cpp:76
static cpcx::Cpc * mCpc
Definition: audio.h:55
tUBYTE * buffer() const
Definition: sound.h:72
void pause(bool value)
Definition: audio.cpp:116
the SDL based Stuff
Definition: audio.cpp:22