all repos — mgba @ 498aa541fc660c8755cda99cf8889171b3bd5381

mGBA Game Boy Advance Emulator

include/mgba/internal/ds/audio.h (view raw)

  1/* Copyright (c) 2013-2017 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6#ifndef DS_AUDIO_H
  7#define DS_AUDIO_H
  8
  9#include <mgba-util/common.h>
 10
 11CXX_GUARD_START
 12
 13#include <mgba/core/log.h>
 14#include <mgba/core/timing.h>
 15
 16mLOG_DECLARE_CATEGORY(DS_AUDIO);
 17
 18DECL_BITFIELD(DSRegisterSOUNDxCNT, uint32_t);
 19DECL_BITS(DSRegisterSOUNDxCNT, VolumeMul, 0, 7);
 20DECL_BITS(DSRegisterSOUNDxCNT, VolumeDiv, 8, 2);
 21DECL_BIT(DSRegisterSOUNDxCNT, Hold, 15);
 22DECL_BITS(DSRegisterSOUNDxCNT, Panning, 16, 7);
 23DECL_BITS(DSRegisterSOUNDxCNT, Duty, 24, 3);
 24DECL_BITS(DSRegisterSOUNDxCNT, Repeat, 27, 2);
 25DECL_BITS(DSRegisterSOUNDxCNT, Format, 29, 2);
 26DECL_BIT(DSRegisterSOUNDxCNT, Busy, 31);
 27
 28struct DSAudio;
 29struct DSAudioChannel {
 30	struct DSAudio* p;
 31	int index;
 32
 33	struct mTimingEvent updateEvent;
 34
 35	uint32_t source;
 36	uint32_t loopPoint;
 37	uint32_t length;
 38	uint32_t offset;
 39
 40	unsigned volume;
 41	unsigned divider;
 42	int panning;
 43	int format;
 44	int repeat;
 45
 46	uint32_t period;
 47	int16_t sample;
 48
 49	int adpcmOffset;
 50
 51	int16_t adpcmStartSample;
 52	unsigned adpcmStartIndex;
 53
 54	int16_t adpcmSample;
 55	unsigned adpcmIndex;
 56
 57	bool enable;
 58};
 59
 60struct DS;
 61struct DSAudio {
 62	struct DS* p;
 63	struct blip_t* left;
 64	struct blip_t* right;
 65
 66	struct DSAudioChannel ch[16];
 67
 68	int16_t lastLeft;
 69	int16_t lastRight;
 70	int clock;
 71
 72	int16_t sampleLeft;
 73	int16_t sampleRight;
 74
 75	size_t samples;
 76	unsigned sampleRate;
 77
 78	int32_t sampleInterval;
 79
 80	bool forceDisableCh[16];
 81	int bias;
 82	int masterVolume;
 83
 84	struct mTimingEvent sampleEvent;
 85};
 86
 87void DSAudioInit(struct DSAudio*, size_t samples);
 88void DSAudioDeinit(struct DSAudio*);
 89void DSAudioReset(struct DSAudio*);
 90
 91void DSAudioResizeBuffer(struct DSAudio* audio, size_t samples);
 92
 93void DSAudioWriteSOUNDCNT_LO(struct DSAudio*, int chan, uint16_t value);
 94void DSAudioWriteSOUNDCNT_HI(struct DSAudio*, int chan, uint16_t value);
 95void DSAudioWriteSOUNDTMR(struct DSAudio*, int chan, uint16_t value);
 96void DSAudioWriteSOUNDPNT(struct DSAudio*, int chan, uint16_t value);
 97void DSAudioWriteSOUNDSAD(struct DSAudio*, int chan, uint32_t value);
 98void DSAudioWriteSOUNDLEN(struct DSAudio*, int chan, uint32_t value);
 99
100CXX_GUARD_END
101
102#endif