diff options
Diffstat (limited to 'src/audio_core/hle/dsp.cpp')
| -rw-r--r-- | src/audio_core/hle/dsp.cpp | 59 |
1 files changed, 50 insertions, 9 deletions
diff --git a/src/audio_core/hle/dsp.cpp b/src/audio_core/hle/dsp.cpp index 5113ad8ca..0640e1eff 100644 --- a/src/audio_core/hle/dsp.cpp +++ b/src/audio_core/hle/dsp.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <memory> | 6 | #include <memory> |
| 7 | 7 | ||
| 8 | #include "audio_core/hle/dsp.h" | 8 | #include "audio_core/hle/dsp.h" |
| 9 | #include "audio_core/hle/mixers.h" | ||
| 9 | #include "audio_core/hle/pipe.h" | 10 | #include "audio_core/hle/pipe.h" |
| 10 | #include "audio_core/hle/source.h" | 11 | #include "audio_core/hle/source.h" |
| 11 | #include "audio_core/sink.h" | 12 | #include "audio_core/sink.h" |
| @@ -14,6 +15,8 @@ | |||
| 14 | namespace DSP { | 15 | namespace DSP { |
| 15 | namespace HLE { | 16 | namespace HLE { |
| 16 | 17 | ||
| 18 | // Region management | ||
| 19 | |||
| 17 | std::array<SharedMemory, 2> g_regions; | 20 | std::array<SharedMemory, 2> g_regions; |
| 18 | 21 | ||
| 19 | static size_t CurrentRegionIndex() { | 22 | static size_t CurrentRegionIndex() { |
| @@ -41,16 +44,57 @@ static SharedMemory& WriteRegion() { | |||
| 41 | return g_regions[1 - CurrentRegionIndex()]; | 44 | return g_regions[1 - CurrentRegionIndex()]; |
| 42 | } | 45 | } |
| 43 | 46 | ||
| 47 | // Audio processing and mixing | ||
| 48 | |||
| 44 | static std::array<Source, num_sources> sources = { | 49 | static std::array<Source, num_sources> sources = { |
| 45 | Source(0), Source(1), Source(2), Source(3), Source(4), Source(5), | 50 | Source(0), Source(1), Source(2), Source(3), Source(4), Source(5), |
| 46 | Source(6), Source(7), Source(8), Source(9), Source(10), Source(11), | 51 | Source(6), Source(7), Source(8), Source(9), Source(10), Source(11), |
| 47 | Source(12), Source(13), Source(14), Source(15), Source(16), Source(17), | 52 | Source(12), Source(13), Source(14), Source(15), Source(16), Source(17), |
| 48 | Source(18), Source(19), Source(20), Source(21), Source(22), Source(23) | 53 | Source(18), Source(19), Source(20), Source(21), Source(22), Source(23) |
| 49 | }; | 54 | }; |
| 55 | static Mixers mixers; | ||
| 56 | |||
| 57 | static StereoFrame16 GenerateCurrentFrame() { | ||
| 58 | SharedMemory& read = ReadRegion(); | ||
| 59 | SharedMemory& write = WriteRegion(); | ||
| 60 | |||
| 61 | std::array<QuadFrame32, 3> intermediate_mixes = {}; | ||
| 62 | |||
| 63 | // Generate intermediate mixes | ||
| 64 | for (size_t i = 0; i < num_sources; i++) { | ||
| 65 | write.source_statuses.status[i] = sources[i].Tick(read.source_configurations.config[i], read.adpcm_coefficients.coeff[i]); | ||
| 66 | for (size_t mix = 0; mix < 3; mix++) { | ||
| 67 | sources[i].MixInto(intermediate_mixes[mix], mix); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | // Generate final mix | ||
| 72 | write.dsp_status = mixers.Tick(read.dsp_configuration, read.intermediate_mix_samples, write.intermediate_mix_samples, intermediate_mixes); | ||
| 73 | |||
| 74 | StereoFrame16 output_frame = mixers.GetOutput(); | ||
| 75 | |||
| 76 | // Write current output frame to the shared memory region | ||
| 77 | for (size_t samplei = 0; samplei < output_frame.size(); samplei++) { | ||
| 78 | for (size_t channeli = 0; channeli < output_frame[0].size(); channeli++) { | ||
| 79 | write.final_samples.pcm16[samplei][channeli] = s16_le(output_frame[samplei][channeli]); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | return output_frame; | ||
| 84 | } | ||
| 85 | |||
| 86 | // Audio output | ||
| 50 | 87 | ||
| 51 | static std::unique_ptr<AudioCore::Sink> sink; | 88 | static std::unique_ptr<AudioCore::Sink> sink; |
| 52 | static AudioCore::TimeStretcher time_stretcher; | 89 | static AudioCore::TimeStretcher time_stretcher; |
| 53 | 90 | ||
| 91 | static void OutputCurrentFrame(const StereoFrame16& frame) { | ||
| 92 | time_stretcher.AddSamples(&frame[0][0], frame.size()); | ||
| 93 | sink->EnqueueSamples(time_stretcher.Process(sink->SamplesInQueue())); | ||
| 94 | } | ||
| 95 | |||
| 96 | // Public Interface | ||
| 97 | |||
| 54 | void Init() { | 98 | void Init() { |
| 55 | DSP::HLE::ResetPipes(); | 99 | DSP::HLE::ResetPipes(); |
| 56 | 100 | ||
| @@ -58,6 +102,8 @@ void Init() { | |||
| 58 | source.Reset(); | 102 | source.Reset(); |
| 59 | } | 103 | } |
| 60 | 104 | ||
| 105 | mixers.Reset(); | ||
| 106 | |||
| 61 | time_stretcher.Reset(); | 107 | time_stretcher.Reset(); |
| 62 | if (sink) { | 108 | if (sink) { |
| 63 | time_stretcher.SetOutputSampleRate(sink->GetNativeSampleRate()); | 109 | time_stretcher.SetOutputSampleRate(sink->GetNativeSampleRate()); |
| @@ -75,17 +121,12 @@ void Shutdown() { | |||
| 75 | } | 121 | } |
| 76 | 122 | ||
| 77 | bool Tick() { | 123 | bool Tick() { |
| 78 | SharedMemory& read = ReadRegion(); | 124 | StereoFrame16 current_frame = {}; |
| 79 | SharedMemory& write = WriteRegion(); | ||
| 80 | 125 | ||
| 81 | std::array<QuadFrame32, 3> intermediate_mixes = {}; | 126 | // TODO: Check dsp::DSP semaphore (which indicates emulated application has finished writing to shared memory region) |
| 127 | current_frame = GenerateCurrentFrame(); | ||
| 82 | 128 | ||
| 83 | for (size_t i = 0; i < num_sources; i++) { | 129 | OutputCurrentFrame(current_frame); |
| 84 | write.source_statuses.status[i] = sources[i].Tick(read.source_configurations.config[i], read.adpcm_coefficients.coeff[i]); | ||
| 85 | for (size_t mix = 0; mix < 3; mix++) { | ||
| 86 | sources[i].MixInto(intermediate_mixes[mix], mix); | ||
| 87 | } | ||
| 88 | } | ||
| 89 | 130 | ||
| 90 | return true; | 131 | return true; |
| 91 | } | 132 | } |