2009-07-28 15:32:10 -06:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2009-03-26 03:29:14 -06:00
|
|
|
|
|
|
|
// 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, version 2.0.
|
|
|
|
|
|
|
|
// 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 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2009-03-28 02:57:34 -06:00
|
|
|
#ifndef _MIXER_H_
|
|
|
|
#define _MIXER_H_
|
2009-03-26 03:29:14 -06:00
|
|
|
|
2011-02-11 11:59:42 -07:00
|
|
|
#include "WaveFile.h"
|
|
|
|
|
2009-12-23 08:34:14 -07:00
|
|
|
// 16 bit Stereo
|
2009-12-25 04:59:04 -07:00
|
|
|
#define MAX_SAMPLES (1024 * 8)
|
2009-12-23 08:34:14 -07:00
|
|
|
#define INDEX_MASK (MAX_SAMPLES * 2 - 1)
|
2009-12-25 04:59:04 -07:00
|
|
|
#define RESERVED_SAMPLES (256)
|
2009-03-26 03:29:14 -06:00
|
|
|
|
|
|
|
class CMixer {
|
|
|
|
|
|
|
|
public:
|
2010-11-11 20:39:07 -07:00
|
|
|
CMixer(unsigned int AISampleRate = 48000, unsigned int DACSampleRate = 48000, unsigned int BackendSampleRate = 32000)
|
2009-12-23 08:34:14 -07:00
|
|
|
: m_aiSampleRate(AISampleRate)
|
2009-12-25 04:59:04 -07:00
|
|
|
, m_dacSampleRate(DACSampleRate)
|
2009-12-22 00:26:30 -07:00
|
|
|
, m_bits(16)
|
|
|
|
, m_channels(2)
|
|
|
|
, m_HLEready(false)
|
2011-02-11 14:07:51 -07:00
|
|
|
, m_logAudio(0)
|
2009-12-23 08:34:14 -07:00
|
|
|
, m_numSamples(0)
|
|
|
|
, m_indexW(0)
|
|
|
|
, m_indexR(0)
|
2010-10-01 17:23:13 -06:00
|
|
|
, m_AIplaying(true)
|
2009-12-23 08:34:14 -07:00
|
|
|
{
|
2009-12-25 04:59:04 -07:00
|
|
|
// AyuanX: The internal (Core & DSP) sample rate is fixed at 32KHz
|
|
|
|
// So when AI/DAC sample rate differs than 32KHz, we have to do re-sampling
|
2010-11-11 20:39:07 -07:00
|
|
|
m_sampleRate = BackendSampleRate;
|
|
|
|
|
2009-12-25 15:10:56 -07:00
|
|
|
INFO_LOG(AUDIO_INTERFACE, "Mixer is initialized (AISampleRate:%i, DACSampleRate:%i)", AISampleRate, DACSampleRate);
|
2009-12-23 08:34:14 -07:00
|
|
|
}
|
2009-03-26 03:29:14 -06:00
|
|
|
|
2010-07-23 17:51:34 -06:00
|
|
|
virtual ~CMixer() {}
|
|
|
|
|
2009-03-26 03:29:14 -06:00
|
|
|
// Called from audio threads
|
2009-12-23 08:34:14 -07:00
|
|
|
virtual unsigned int Mix(short* samples, unsigned int numSamples);
|
2011-01-28 11:39:30 -07:00
|
|
|
virtual void Premix(short * /*samples*/, unsigned int /*numSamples*/) {}
|
2009-12-23 08:34:14 -07:00
|
|
|
unsigned int GetNumSamples();
|
2009-12-19 19:23:26 -07:00
|
|
|
|
2009-03-26 03:29:14 -06:00
|
|
|
// Called from main thread
|
2011-01-28 11:39:30 -07:00
|
|
|
virtual void PushSamples(const short* samples, unsigned int num_samples);
|
2009-12-23 08:34:14 -07:00
|
|
|
unsigned int GetSampleRate() {return m_sampleRate;}
|
2009-06-12 08:40:50 -06:00
|
|
|
|
2009-03-26 03:29:14 -06:00
|
|
|
void SetThrottle(bool use) { m_throttle = use;}
|
2009-03-30 03:55:50 -06:00
|
|
|
void SetDTKMusic(bool use) { m_EnableDTKMusic = use;}
|
2009-03-26 03:29:14 -06:00
|
|
|
|
2009-03-28 02:57:34 -06:00
|
|
|
// TODO: do we need this
|
2009-03-26 03:29:14 -06:00
|
|
|
bool IsHLEReady() { return m_HLEready;}
|
|
|
|
void SetHLEReady(bool ready) { m_HLEready = ready;}
|
2009-03-28 02:57:34 -06:00
|
|
|
// ---------------------
|
2009-03-26 03:29:14 -06:00
|
|
|
|
2011-02-11 11:59:42 -07:00
|
|
|
|
|
|
|
virtual void StartLogAudio(const char *filename) {
|
|
|
|
if (! m_logAudio) {
|
|
|
|
m_logAudio = true;
|
2011-02-12 22:05:53 -07:00
|
|
|
g_wave_writer.Start(filename, GetSampleRate());
|
2011-02-11 11:59:42 -07:00
|
|
|
g_wave_writer.SetSkipSilence(false);
|
|
|
|
NOTICE_LOG(DSPHLE, "Starting Audio logging");
|
|
|
|
} else {
|
|
|
|
WARN_LOG(DSPHLE, "Audio logging already started");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void StopLogAudio() {
|
|
|
|
if (m_logAudio) {
|
|
|
|
m_logAudio = false;
|
|
|
|
g_wave_writer.Stop();
|
|
|
|
NOTICE_LOG(DSPHLE, "Stopping Audio logging");
|
|
|
|
} else {
|
|
|
|
WARN_LOG(DSPHLE, "Audio logging already stopped");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-26 03:29:14 -06:00
|
|
|
protected:
|
2009-12-23 08:34:14 -07:00
|
|
|
unsigned int m_sampleRate;
|
|
|
|
unsigned int m_aiSampleRate;
|
2009-12-25 04:59:04 -07:00
|
|
|
unsigned int m_dacSampleRate;
|
2009-03-26 03:29:14 -06:00
|
|
|
int m_bits;
|
|
|
|
int m_channels;
|
2011-02-11 11:59:42 -07:00
|
|
|
|
|
|
|
WaveFileWriter g_wave_writer;
|
2009-03-26 03:29:14 -06:00
|
|
|
|
|
|
|
bool m_HLEready;
|
2011-02-11 11:59:42 -07:00
|
|
|
bool m_logAudio;
|
2009-03-26 03:29:14 -06:00
|
|
|
|
2009-03-30 03:55:50 -06:00
|
|
|
bool m_EnableDTKMusic;
|
2009-03-26 03:29:14 -06:00
|
|
|
bool m_throttle;
|
2009-12-23 08:34:14 -07:00
|
|
|
|
|
|
|
short m_buffer[MAX_SAMPLES * 2];
|
2010-01-18 11:21:27 -07:00
|
|
|
volatile u32 m_numSamples;
|
2009-12-23 08:34:14 -07:00
|
|
|
u32 m_indexW;
|
|
|
|
u32 m_indexR;
|
|
|
|
|
2010-10-01 17:23:13 -06:00
|
|
|
bool m_AIplaying;
|
2010-09-28 15:43:38 -06:00
|
|
|
|
2009-03-26 03:29:14 -06:00
|
|
|
private:
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2009-03-28 02:57:34 -06:00
|
|
|
#endif // _MIXER_H_
|