2021-11-09 12:11:23 +00:00
|
|
|
|
//
|
|
|
|
|
// Audio.hpp
|
|
|
|
|
// Clock Signal
|
|
|
|
|
//
|
|
|
|
|
// Created by Thomas Harte on 09/11/2021.
|
|
|
|
|
// Copyright © 2021 Thomas Harte. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef Audio_hpp
|
|
|
|
|
#define Audio_hpp
|
|
|
|
|
|
|
|
|
|
#include "DMADevice.hpp"
|
2021-11-11 14:24:15 +00:00
|
|
|
|
#include "../../ClockReceiver/ClockReceiver.hpp"
|
|
|
|
|
#include "../../Concurrency/AsyncTaskQueue.hpp"
|
2021-11-09 12:11:23 +00:00
|
|
|
|
|
|
|
|
|
namespace Amiga {
|
|
|
|
|
|
|
|
|
|
class Audio: public DMADevice<4> {
|
|
|
|
|
public:
|
2021-11-11 14:24:15 +00:00
|
|
|
|
Audio(
|
|
|
|
|
Chipset &chipset, uint16_t *ram, size_t word_size,
|
|
|
|
|
[[maybe_unused]] double output_rate) :
|
|
|
|
|
DMADevice<4>(chipset, ram, word_size) {}
|
2021-11-09 12:11:23 +00:00
|
|
|
|
|
2021-11-11 14:24:15 +00:00
|
|
|
|
/// Idiomatic call-in for DMA scheduling; indicates that this class may
|
|
|
|
|
/// perform a DMA access for the stated channel now.
|
2021-11-09 12:11:23 +00:00
|
|
|
|
bool advance(int channel);
|
|
|
|
|
|
2021-11-11 14:24:15 +00:00
|
|
|
|
/// Standard JustInTimeActor item; allows this class to track the
|
|
|
|
|
/// amount of time between other events.
|
2021-11-12 20:30:52 +00:00
|
|
|
|
void run_for(Cycles);
|
2021-11-11 14:24:15 +00:00
|
|
|
|
|
|
|
|
|
/// Sets the total number of words to fetch for the given channel.
|
|
|
|
|
void set_length(int channel, uint16_t);
|
|
|
|
|
|
|
|
|
|
/// Sets the number of DMA windows between each 8-bit output,
|
|
|
|
|
/// in the same time base as @c ticks_per_line.
|
|
|
|
|
void set_period(int channel, uint16_t);
|
|
|
|
|
|
|
|
|
|
/// Sets the output volume for the given channel; if bit 6 is set
|
|
|
|
|
/// then output is maximal; otherwise bits 0–5 select
|
|
|
|
|
/// a volume of [0–63]/64, on a logarithmic scale.
|
|
|
|
|
void set_volume(int channel, uint16_t);
|
|
|
|
|
|
|
|
|
|
/// Sets the next two samples of audio to output.
|
|
|
|
|
void set_data(int channel, uint16_t);
|
|
|
|
|
|
|
|
|
|
/// Provides a copy of the DMA enable flags, for the purpose of
|
|
|
|
|
/// determining which channels are enabled for DMA.
|
|
|
|
|
void set_channel_enables(uint16_t);
|
|
|
|
|
|
|
|
|
|
/// Sets which channels, if any, modulate period or volume of
|
|
|
|
|
/// their neighbours.
|
|
|
|
|
void set_modulation_flags(uint16_t);
|
|
|
|
|
|
2021-11-13 16:05:39 +00:00
|
|
|
|
/// Sets which interrupt requests are currently active.
|
|
|
|
|
void set_interrupt_requests(uint16_t);
|
|
|
|
|
|
2021-11-11 14:24:15 +00:00
|
|
|
|
private:
|
|
|
|
|
struct Channel {
|
|
|
|
|
// The data latch plus a count of unused samples
|
|
|
|
|
// in the latch, which will always be 0, 1 or 2.
|
|
|
|
|
uint16_t data = 0x0000;
|
2021-11-12 20:30:52 +00:00
|
|
|
|
bool has_data = false;
|
2021-11-11 14:24:15 +00:00
|
|
|
|
|
|
|
|
|
// Number of words remaining in DMA data.
|
|
|
|
|
uint16_t length = 0;
|
|
|
|
|
|
|
|
|
|
// Number of ticks between each sample, plus the
|
|
|
|
|
// current counter, which counts downward.
|
|
|
|
|
uint16_t period = 0;
|
|
|
|
|
uint16_t period_counter = 0;
|
|
|
|
|
|
|
|
|
|
// Output volume, [0, 64].
|
|
|
|
|
uint8_t volume;
|
|
|
|
|
|
|
|
|
|
// Indicates whether DMA is enabled for this channel.
|
|
|
|
|
bool dma_enabled = false;
|
2021-11-12 20:30:52 +00:00
|
|
|
|
|
2021-11-13 16:05:39 +00:00
|
|
|
|
// Records whether this audio interrupt is pending.
|
|
|
|
|
bool interrupt_pending = false;
|
|
|
|
|
|
2021-11-12 20:30:52 +00:00
|
|
|
|
// Replicates the Hardware Reference Manual state machine;
|
|
|
|
|
// comments indicate which of the documented states each
|
|
|
|
|
// label refers to.
|
|
|
|
|
enum class State {
|
|
|
|
|
Disabled, // 000
|
|
|
|
|
WaitingForDummyDMA, // 001
|
|
|
|
|
WaitingForDMA, // 101
|
|
|
|
|
PlayingHigh, // 010
|
|
|
|
|
PlayingLow, // 011
|
2021-11-13 16:05:39 +00:00
|
|
|
|
} state = State::Disabled;
|
2021-11-11 14:24:15 +00:00
|
|
|
|
} channels_[4];
|
2021-11-09 12:11:23 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* Audio_hpp */
|