Skip to content

Commit 871ecca

Browse files
committed
Refactor/subclass Basic_Gb_Apu
1 parent 5191912 commit 871ecca

File tree

6 files changed

+148
-164
lines changed

6 files changed

+148
-164
lines changed

plugins/papu/Basic_Gb_Apu.cpp

Lines changed: 0 additions & 79 deletions
This file was deleted.

plugins/papu/Basic_Gb_Apu.h

Lines changed: 0 additions & 55 deletions
This file was deleted.

plugins/papu/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ INCLUDE_DIRECTORIES(game-music-emu/gme)
66
BUILD_PLUGIN(papu
77
papu_instrument.cpp
88
papu_instrument.h
9-
Basic_Gb_Apu.cpp # TODO: Replace with subclass
10-
Basic_Gb_Apu.h # TODO: Replace with subclass
11-
# Gb_Apu_Buffer.cpp
12-
# Gb_Apu_Buffer.h
9+
Gb_Apu_Buffer.cpp
10+
Gb_Apu_Buffer.h
1311
game-music-emu/gme/Gb_Apu.cpp
1412
game-music-emu/gme/Gb_Apu.h
1513
game-music-emu/gme/Gb_Oscs.cpp

plugins/papu/Gb_Apu_Buffer.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Gb_Apu_Buffer.cpp - Gb_Apu subclass which allows direct buffer access
3+
* Copyright (c) 2017 Tres Finocchiaro <tres.finocchiaro/at/gmail.com>
4+
*
5+
* This file is part of LMMS - https://lmms.io
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public
9+
* License as published by the Free Software Foundation; either
10+
* version 2 of the License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public
18+
* License along with this program (see COPYING); if not, write to the
19+
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20+
* Boston, MA 02110-1301 USA.
21+
*
22+
*/
23+
#include "Gb_Apu.h"
24+
#include "Gb_Apu_Buffer.h"
25+
26+
blip_time_t const FRAME_LENGTH = 70224;
27+
long const CLOCK_RATE = 4194304;
28+
29+
Gb_Apu_Buffer::Gb_Apu_Buffer() : m_time(0) {}
30+
Gb_Apu_Buffer::~Gb_Apu_Buffer() {}
31+
32+
void Gb_Apu_Buffer::write_register(blip_time_t ignore, unsigned addr, int data) {
33+
Gb_Apu::write_register(clock(), addr, data);
34+
}
35+
36+
int Gb_Apu_Buffer::read_register(blip_time_t ignore, unsigned addr) {
37+
return Gb_Apu::read_register(clock(), addr);
38+
}
39+
40+
void Gb_Apu_Buffer::end_frame(blip_time_t ignore) {
41+
m_time = 0;
42+
Gb_Apu::end_frame(FRAME_LENGTH);
43+
m_buf.end_frame(FRAME_LENGTH);
44+
}
45+
46+
// Sets specified sample rate and hard-coded clock rate in Multi_Buffer
47+
blargg_err_t Gb_Apu_Buffer::set_sample_rate(long rate) {
48+
Gb_Apu_Buffer::output(m_buf.center(), m_buf.left(), m_buf.right());
49+
m_buf.clock_rate(CLOCK_RATE);
50+
return m_buf.set_sample_rate(rate);
51+
}
52+
53+
// Wrap Multi_Buffer::samples_avail()
54+
long Gb_Apu_Buffer::samples_avail() const {
55+
return m_buf.samples_avail();
56+
}
57+
58+
// Wrap Multi_Buffer::read_samples(...)
59+
long Gb_Apu_Buffer::read_samples(sample_t* out, long count) {
60+
return m_buf.read_samples(out, count);
61+
}
62+
63+
void Gb_Apu_Buffer::bass_freq(int freq) {
64+
m_buf.bass_freq(freq);
65+
}
66+

plugins/papu/Gb_Apu_Buffer.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Gb_Apu_Buffer.cpp - Gb_Apu subclass which allows direct buffer access
3+
* Copyright (c) 2017 Tres Finocchiaro <tres.finocchiaro/at/gmail.com>
4+
*
5+
* This file is part of LMMS - https://lmms.io
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public
9+
* License as published by the Free Software Foundation; either
10+
* version 2 of the License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public
18+
* License along with this program (see COPYING); if not, write to the
19+
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20+
* Boston, MA 02110-1301 USA.
21+
*
22+
*/
23+
#ifndef GB_APU_BUFFER_H
24+
#define GB_APU_BUFFER_H
25+
26+
#include "Gb_Apu.h"
27+
#include "Multi_Buffer.h"
28+
#include "MemoryManager.h"
29+
30+
class Gb_Apu_Buffer : public Gb_Apu {
31+
MM_OPERATORS
32+
public:
33+
Gb_Apu_Buffer();
34+
~Gb_Apu_Buffer();
35+
36+
void write_register(blip_time_t, unsigned addr, int data);
37+
int read_register(blip_time_t, unsigned addr);
38+
void end_frame(blip_time_t);
39+
blargg_err_t set_sample_rate(long rate);
40+
long samples_avail() const;
41+
typedef blip_sample_t sample_t;
42+
long read_samples(sample_t* out, long count);
43+
44+
void bass_freq(int freq);
45+
private:
46+
Stereo_Buffer m_buf;
47+
blip_time_t m_time;
48+
49+
// faked CPU timing
50+
blip_time_t clock() { return m_time += 4; }
51+
};
52+
53+
#endif
54+

0 commit comments

Comments
 (0)