Skip to content

Commit

Permalink
Move code to __sceAudio
Browse files Browse the repository at this point in the history
  • Loading branch information
RisingFog committed Sep 3, 2016
1 parent c18b0fc commit 6e9732a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 42 deletions.
40 changes: 38 additions & 2 deletions Core/HLE/__sceAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ static int audioHostIntervalCycles;

static s32 *mixBuffer;

WaveFileWriter g_wave_writer;
bool m_logAudio;

// High and low watermarks, basically. For perfect emulation, the correct values are 0 and 1, respectively.
// TODO: Tweak. Hm, there aren't actually even used currently...
static int chanQueueMaxSizeFactor;
Expand Down Expand Up @@ -140,7 +143,7 @@ void __AudioInit() {
{
std::string audio_file_name = GetSysDirectory(DIRECTORY_VIDEO_DUMP) + "audiodump.wav";
File::CreateEmptyFile(audio_file_name);
resampler.StartLogAudio(audio_file_name);
__StartLogAudio(audio_file_name);
}
}

Expand Down Expand Up @@ -188,7 +191,7 @@ void __AudioShutdown() {

if (g_Config.bDumpAudio)
{
resampler.StopLogAudio();
__StopLogAudio();
}
}

Expand Down Expand Up @@ -377,6 +380,10 @@ void __AudioUpdate() {

if (g_Config.bEnableSound) {
resampler.PushSamples(mixBuffer, hwBlockSize);
if (m_logAudio)
{
g_wave_writer.AddStereoSamples((short*)mixBuffer, hwBlockSize);
}
}
}

Expand All @@ -398,3 +405,32 @@ void __PushExternalAudio(const s32 *audio, int numSamples) {
resampler.Clear();
}
}

void __StartLogAudio(const std::string& filename)
{
if (!m_logAudio)
{
m_logAudio = true;
g_wave_writer.Start(filename, 44100);
g_wave_writer.SetSkipSilence(false);
NOTICE_LOG(SCEAUDIO, "Starting Audio logging");
}
else
{
WARN_LOG(SCEAUDIO, "Audio logging has already been started");
}
}

void __StopLogAudio()
{
if (m_logAudio)
{
m_logAudio = false;
g_wave_writer.Stop();
NOTICE_LOG(SCEAUDIO, "Stopping Audio logging");
}
else
{
WARN_LOG(SCEAUDIO, "Audio logging has already been stopped");
}
}
5 changes: 5 additions & 0 deletions Core/HLE/__sceAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include "sceAudio.h"
#include "Core/WaveFile.h"

struct AudioDebugStats {
int buffered;
Expand Down Expand Up @@ -45,3 +46,7 @@ void __AudioWakeThreads(AudioChannel &chan, int result);
int __AudioMix(short *outstereo, int numSamples, int sampleRate);
const AudioDebugStats *__AudioGetDebugStats();
void __PushExternalAudio(const s32 *audio, int numSamples); // Should not be used in-game, only at the menu!

// Audio Dumping stuff
void __StartLogAudio(const std::string& filename);
void __StopLogAudio();
33 changes: 0 additions & 33 deletions Core/HW/StereoResampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,41 +223,8 @@ void StereoResampler::MixerFifo::GetAudioDebugStats(AudioDebugStats *stats) {
stats->lastPushSize = lastPushSize_;
}

void StereoResampler::StartLogAudio(const std::string& filename)
{
if (!m_logAudio)
{
m_logAudio = true;
g_wave_writer.Start(filename, 44100);
g_wave_writer.SetSkipSilence(false);
NOTICE_LOG(SCEAUDIO, "Starting Audio logging");
}
else
{
WARN_LOG(SCEAUDIO, "Audio logging has already been started");
}
}

void StereoResampler::StopLogAudio()
{
if (m_logAudio)
{
m_logAudio = false;
g_wave_writer.Stop();
NOTICE_LOG(SCEAUDIO, "Stopping Audio logging");
}
else
{
WARN_LOG(SCEAUDIO, "Audio logging has already been stopped");
}
}

void StereoResampler::PushSamples(const int *samples, unsigned int num_samples) {
m_dma_mixer.PushSamples(samples, num_samples);
if (m_logAudio)
{
g_wave_writer.AddStereoSamples((short*)samples, num_samples);
}
}

void StereoResampler::MixerFifo::SetInputSampleRate(unsigned int rate) {
Expand Down
6 changes: 0 additions & 6 deletions Core/HW/StereoResampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ class StereoResampler {

void GetAudioDebugStats(AudioDebugStats *stats);

void StartLogAudio(const std::string& filename);
void StopLogAudio();

protected:
// TODO: Unlike Dolphin we only mix one stream so this inner class can be merged into the outer one.
class MixerFifo {
Expand Down Expand Up @@ -104,7 +101,4 @@ class StereoResampler {
};

MixerFifo m_dma_mixer;

WaveFileWriter g_wave_writer;
bool m_logAudio;
};
2 changes: 1 addition & 1 deletion Core/WaveFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class WaveFileWriter
void Stop();

void SetSkipSilence(bool skip) { skip_silence = skip; }
void AddStereoSamples(const short* sample_data, u32 count); // big endian
void AddStereoSamples(const short* sample_data, u32 count);
u32 GetAudioSize() const { return audio_size; }
private:
static constexpr size_t BUFFER_SIZE = 32 * 1024;
Expand Down

0 comments on commit 6e9732a

Please sign in to comment.