libsidplayfp  1.1.0
mixer.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net>
5  * Copyright 2007-2010 Antti Lankila
6  * Copyright (C) 2000 Simon White
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
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.
17  *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 
24 #ifndef MIXER_H
25 #define MIXER_H
26 
27 #include <stdlib.h>
28 
29 #include <vector>
30 
31 #include "event.h"
32 #include "sidbuilder.h"
33 
37 class Mixer : private Event
38 {
39 public:
41  static const int_least32_t VOLUME_MAX = 1024;
42 
43 private:
47  EventContext &event_context;
48 
49  std::vector<sidemu *> m_chips;
50 
51  int oldRandomValue;
52  int m_fastForwardFactor;
53 
54  int_least32_t m_leftVolume;
55  int_least32_t m_rightVolume;
56  bool m_stereo;
57 
58  // Mixer settings
59  uint_least32_t m_sampleCount;
60  uint_least32_t m_sampleIndex;
61  short *m_sampleBuffer;
62 
63 private:
64  int triangularDithering()
65  {
66  const int prevValue = oldRandomValue;
67  oldRandomValue = rand() & (VOLUME_MAX-1);
68  return oldRandomValue - prevValue;
69  }
70 
71 public:
77  Mixer(EventContext *context) :
78  Event("Mixer"),
79  event_context(*context),
80  oldRandomValue(0),
81  m_fastForwardFactor(1),
82  m_sampleCount(0) {}
83 
87  void event();
88 
89  void reset();
90 
91  void begin(short *buffer, uint_least32_t count);
92 
93  void setSids(sidemu *chip1, sidemu *chip2);
94  bool setFastForward(int ff);
95  void setVolume(int_least32_t left, int_least32_t right);
96  void setStereo(bool stereo) { m_stereo = stereo; }
97 
98  bool notFinished() const { return m_sampleIndex != m_sampleCount; }
99  uint_least32_t samplesGenerated() const { return m_sampleIndex; }
100  uint_least32_t sampleCount() const { return m_sampleCount; }
101 };
102 
103 #endif // MIXER_H
static const int_least32_t VOLUME_MAX
Definition: mixer.h:41
Definition: mixer.h:37
Definition: sidemu.h:45
Definition: event.h:101
Mixer(EventContext *context)
Definition: mixer.h:77
Definition: event.h:50
void event()
Definition: mixer.cpp:46