Skip to content

Commit

Permalink
Refactor/subclass Basic_Gb_Apu
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed Nov 7, 2017
1 parent 5191912 commit 871ecca
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 164 deletions.
79 changes: 0 additions & 79 deletions plugins/papu/Basic_Gb_Apu.cpp

This file was deleted.

55 changes: 0 additions & 55 deletions plugins/papu/Basic_Gb_Apu.h

This file was deleted.

6 changes: 2 additions & 4 deletions plugins/papu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ INCLUDE_DIRECTORIES(game-music-emu/gme)
BUILD_PLUGIN(papu
papu_instrument.cpp
papu_instrument.h
Basic_Gb_Apu.cpp # TODO: Replace with subclass
Basic_Gb_Apu.h # TODO: Replace with subclass
# Gb_Apu_Buffer.cpp
# Gb_Apu_Buffer.h
Gb_Apu_Buffer.cpp
Gb_Apu_Buffer.h
game-music-emu/gme/Gb_Apu.cpp
game-music-emu/gme/Gb_Apu.h
game-music-emu/gme/Gb_Oscs.cpp
Expand Down
66 changes: 66 additions & 0 deletions plugins/papu/Gb_Apu_Buffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Gb_Apu_Buffer.cpp - Gb_Apu subclass which allows direct buffer access
* Copyright (c) 2017 Tres Finocchiaro <tres.finocchiaro/at/gmail.com>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include "Gb_Apu.h"
#include "Gb_Apu_Buffer.h"

blip_time_t const FRAME_LENGTH = 70224;
long const CLOCK_RATE = 4194304;

Gb_Apu_Buffer::Gb_Apu_Buffer() : m_time(0) {}
Gb_Apu_Buffer::~Gb_Apu_Buffer() {}

void Gb_Apu_Buffer::write_register(blip_time_t ignore, unsigned addr, int data) {
Gb_Apu::write_register(clock(), addr, data);
}

int Gb_Apu_Buffer::read_register(blip_time_t ignore, unsigned addr) {
return Gb_Apu::read_register(clock(), addr);
}

void Gb_Apu_Buffer::end_frame(blip_time_t ignore) {
m_time = 0;
Gb_Apu::end_frame(FRAME_LENGTH);
m_buf.end_frame(FRAME_LENGTH);
}

// Sets specified sample rate and hard-coded clock rate in Multi_Buffer
blargg_err_t Gb_Apu_Buffer::set_sample_rate(long rate) {
Gb_Apu_Buffer::output(m_buf.center(), m_buf.left(), m_buf.right());
m_buf.clock_rate(CLOCK_RATE);
return m_buf.set_sample_rate(rate);
}

// Wrap Multi_Buffer::samples_avail()
long Gb_Apu_Buffer::samples_avail() const {
return m_buf.samples_avail();
}

// Wrap Multi_Buffer::read_samples(...)
long Gb_Apu_Buffer::read_samples(sample_t* out, long count) {
return m_buf.read_samples(out, count);
}

void Gb_Apu_Buffer::bass_freq(int freq) {
m_buf.bass_freq(freq);
}

54 changes: 54 additions & 0 deletions plugins/papu/Gb_Apu_Buffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Gb_Apu_Buffer.cpp - Gb_Apu subclass which allows direct buffer access
* Copyright (c) 2017 Tres Finocchiaro <tres.finocchiaro/at/gmail.com>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef GB_APU_BUFFER_H
#define GB_APU_BUFFER_H

#include "Gb_Apu.h"
#include "Multi_Buffer.h"
#include "MemoryManager.h"

class Gb_Apu_Buffer : public Gb_Apu {
MM_OPERATORS
public:
Gb_Apu_Buffer();
~Gb_Apu_Buffer();

void write_register(blip_time_t, unsigned addr, int data);
int read_register(blip_time_t, unsigned addr);
void end_frame(blip_time_t);
blargg_err_t set_sample_rate(long rate);
long samples_avail() const;
typedef blip_sample_t sample_t;
long read_samples(sample_t* out, long count);

void bass_freq(int freq);
private:
Stereo_Buffer m_buf;
blip_time_t m_time;

// faked CPU timing
blip_time_t clock() { return m_time += 4; }
};

#endif

Loading

0 comments on commit 871ecca

Please sign in to comment.