mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00:00 
			
		
		
		
	Rest of the owl
This commit is contained in:
		
							parent
							
								
									5c9e327ff3
								
							
						
					
					
						commit
						c669aa8d55
					
				
					 7 changed files with 237 additions and 75 deletions
				
			
		|  | @ -2,10 +2,73 @@ | |||
| // Licensed under GPLv2 or any later version
 | ||||
| // Refer to the license.txt file included.
 | ||||
| 
 | ||||
| #include <array> | ||||
| #include "core/frontend/mic.h" | ||||
| #include "core/hle/service/mic_u.h" | ||||
| 
 | ||||
| namespace Frontend { | ||||
| namespace Frontend::Mic { | ||||
| 
 | ||||
| constexpr std::array<u8, 32> NOISE_SAMPLE_8_BIT = { | ||||
|     0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF5, 0xFF, 0xFF, 0xFF, 0xFF, 0x8E, 0xFF, | ||||
|     0xF4, 0xE1, 0xBF, 0x9A, 0x71, 0x58, 0x5B, 0x5F, 0x62, 0xC2, 0x25, 0x05, 0x01, 0x01, 0x01, 0x01}; | ||||
| 
 | ||||
| constexpr std::array<u8, 512> NOISE_SAMPLE_16_BIT = { | ||||
|     0x64, 0x61, 0x74, 0x61, 0x56, 0xD7, 0x00, 0x00, 0x48, 0xF7, 0x86, 0x05, 0x77, 0x1A, 0xF4, 0x1F, | ||||
|     0x28, 0x0F, 0x6B, 0xEB, 0x1C, 0xC0, 0xCB, 0x9D, 0x46, 0x90, 0xDF, 0x98, 0xEA, 0xAE, 0xB5, 0xC4, | ||||
|     0x9D, 0xCE, 0xB6, 0xC9, 0xDF, 0xBD, 0x82, 0xBA, 0x83, 0xCD, 0x57, 0xF9, 0x96, 0x30, 0x2C, 0x5B, | ||||
|     0x29, 0x64, 0xD3, 0x46, 0x0D, 0x12, 0x3E, 0xDE, 0x00, 0xBD, 0x74, 0xAE, 0xF0, 0xA4, 0x91, 0x93, | ||||
|     0x02, 0x80, 0x00, 0x80, 0x03, 0x80, 0x6F, 0xAA, 0x8E, 0xE8, 0xEE, 0x1A, 0x2B, 0x2C, 0xC6, 0x18, | ||||
|     0xF8, 0xED, 0xC2, 0xBE, 0x00, 0x99, 0xC1, 0x82, 0x00, 0x80, 0xA6, 0x8A, 0x37, 0xA8, 0x6B, 0xCE, | ||||
|     0x20, 0xEF, 0xD0, 0xFD, 0x68, 0xF9, 0x50, 0xEF, 0x89, 0xF2, 0xDE, 0x0C, 0x24, 0x36, 0xDB, 0x58, | ||||
|     0xB2, 0x61, 0xD5, 0x4C, 0x0B, 0x27, 0x6D, 0x02, 0xDC, 0xE8, 0x13, 0xD8, 0x2F, 0xC9, 0x07, 0xBC, | ||||
|     0xAB, 0xBA, 0x70, 0xD1, 0xDE, 0x01, 0xF2, 0x3C, 0x64, 0x6A, 0xFF, 0x78, 0x47, 0x6B, 0x26, 0x56, | ||||
|     0x9B, 0x51, 0xF3, 0x65, 0xFF, 0x7F, 0xFF, 0x7F, 0x88, 0x6B, 0x46, 0x24, 0xBF, 0xD8, 0x8C, 0xB4, | ||||
|     0xD9, 0xCF, 0x77, 0x1C, 0x43, 0x6B, 0xFE, 0x7F, 0x15, 0x64, 0xA6, 0x13, 0x03, 0xCE, 0x51, 0xBF, | ||||
|     0xC7, 0xEB, 0xCB, 0x2E, 0x6C, 0x58, 0xA7, 0x51, 0x40, 0x2A, 0x24, 0x06, 0x45, 0xFB, 0xD3, 0xFE, | ||||
|     0x51, 0xF2, 0x1E, 0xC5, 0x79, 0x8A, 0x00, 0x80, 0x94, 0x8E, 0x7A, 0xDE, 0x83, 0x29, 0x8E, 0x3C, | ||||
|     0x4B, 0x0F, 0xD8, 0xCB, 0x41, 0xAB, 0xC1, 0xC5, 0xC6, 0xFE, 0x0F, 0x1F, 0x92, 0x05, 0x4B, 0xC4, | ||||
|     0xDC, 0x8F, 0xE1, 0x90, 0xE3, 0xC0, 0xDB, 0xF1, 0xCC, 0xF8, 0xC8, 0xD4, 0x2A, 0xAF, 0xB7, 0xB5, | ||||
|     0x7F, 0xF0, 0xB2, 0x39, 0xD4, 0x5C, 0xD6, 0x41, 0x69, 0xFD, 0xEA, 0xBB, 0x57, 0x9B, 0x59, 0x98, | ||||
|     0x8E, 0x9B, 0x8A, 0x97, 0x54, 0x98, 0xE6, 0xB5, 0x25, 0xF8, 0x77, 0x48, 0xFF, 0x7F, 0xFF, 0x7F, | ||||
|     0x49, 0x6B, 0xB4, 0x4B, 0xE9, 0x45, 0xE3, 0x57, 0x60, 0x64, 0x8C, 0x4D, 0x69, 0x10, 0x10, 0xCA, | ||||
|     0x13, 0xA4, 0xC5, 0xB7, 0xE4, 0xFD, 0x7C, 0x54, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, 0xE0, 0x52, | ||||
|     0x5E, 0x22, 0x31, 0x0B, 0xB5, 0x12, 0xB1, 0x2E, 0xA7, 0x4D, 0x17, 0x61, 0x46, 0x65, 0xA5, 0x5F, | ||||
|     0x5C, 0x57, 0xB6, 0x4C, 0x3B, 0x38, 0xFD, 0x11, 0x70, 0xDC, 0x2A, 0xA8, 0xB9, 0x8C, 0xEA, 0x98, | ||||
|     0x07, 0xC6, 0xDF, 0xF7, 0x2D, 0x0C, 0xEC, 0xF0, 0xA8, 0xB2, 0x02, 0x80, 0x00, 0x80, 0xBA, 0x8A, | ||||
|     0x0E, 0xCB, 0x54, 0xF7, 0x2B, 0xEE, 0x4C, 0xB9, 0x48, 0x89, 0x8F, 0x90, 0x0E, 0xD8, 0x83, 0x32, | ||||
|     0xC5, 0x5C, 0x54, 0x34, 0x86, 0xD6, 0x78, 0x8C, 0x88, 0x90, 0x87, 0xDE, 0x75, 0x37, 0x55, 0x56, | ||||
|     0xF1, 0x28, 0xF0, 0xDA, 0xE2, 0xAB, 0xE6, 0xB6, 0xD6, 0xDF, 0x4D, 0xF4, 0xCF, 0xDE, 0x3E, 0xBA, | ||||
|     0xC6, 0xB3, 0x81, 0xDA, 0xFE, 0x0D, 0xE9, 0x1D, 0xCE, 0xFB, 0x59, 0xCD, 0x57, 0xCA, 0x77, 0x06, | ||||
|     0x63, 0x5A, 0xFE, 0x7F, 0x49, 0x63, 0x7F, 0x14, 0x0E, 0xDB, 0x2A, 0xE5, 0x3B, 0x27, 0xFF, 0x69, | ||||
|     0x0A, 0x7C, 0xC5, 0x56, 0x65, 0x19, 0xEC, 0xE5, 0x0E, 0xC6, 0xA6, 0xB0, 0x09, 0xA2, 0x06, 0xA8, | ||||
|     0xC7, 0xD1, 0xE9, 0x15, 0xD5, 0x4E, 0xBB, 0x56, 0x85, 0x2A, 0x25, 0xF0, 0x78, 0xD6, 0x70, 0xEB, | ||||
|     0xF2, 0x0F, 0xE1, 0x15, 0x66, 0xEC, 0xC7, 0xB0, 0xE7, 0x93, 0x9D, 0xAD, 0xD1, 0xE6, 0xD3, 0x0D, | ||||
|     0xAC, 0x00, 0xB2, 0xC7, 0x5D, 0x8B, 0x00, 0x80, 0xA1, 0x88, 0x14, 0xBE, 0xDF, 0xFB, 0xCF, 0x32, | ||||
|     0xD8, 0x5B, 0x0F, 0x6F, 0x6C, 0x62, 0xD9, 0x33, 0x76, 0xF3, 0xD6, 0xBF, 0x41, 0xB3, 0x5C, 0xD1}; | ||||
| 
 | ||||
| StaticMic::StaticMic() | ||||
|     : CACHE_8_BIT{NOISE_SAMPLE_8_BIT.begin(), NOISE_SAMPLE_8_BIT.end()}, | ||||
|       CACHE_16_BIT{NOISE_SAMPLE_16_BIT.begin(), NOISE_SAMPLE_16_BIT.end()} {} | ||||
| 
 | ||||
| StaticMic::~StaticMic() = default; | ||||
| 
 | ||||
| void StaticMic::StartSampling(Parameters params) { | ||||
|     sample_rate = params.sample_rate; | ||||
|     sample_size = params.sample_size; | ||||
| 
 | ||||
|     parameters = params; | ||||
|     is_sampling = true; | ||||
| } | ||||
| 
 | ||||
| void StaticMic::StopSampling() { | ||||
|     is_sampling = false; | ||||
| } | ||||
| 
 | ||||
| void StaticMic::AdjustSampleRate(u32 sample_rate) {} | ||||
| 
 | ||||
| Samples StaticMic::Read() { | ||||
|     return (sample_size == 8) ? CACHE_8_BIT : CACHE_16_BIT; | ||||
| } | ||||
| 
 | ||||
| static std::shared_ptr<Mic::Interface> current_mic; | ||||
| 
 | ||||
|  | @ -20,4 +83,4 @@ std::shared_ptr<Mic::Interface> GetCurrentMic() { | |||
|     return current_mic; | ||||
| } | ||||
| 
 | ||||
| } // namespace Frontend
 | ||||
| } // namespace Frontend::Mic
 | ||||
|  |  | |||
|  | @ -4,19 +4,21 @@ | |||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <array> | ||||
| #include <memory> | ||||
| #include <vector> | ||||
| #include "common/swap.h" | ||||
| #include "common/threadsafe_queue.h" | ||||
| 
 | ||||
| namespace Frontend { | ||||
| 
 | ||||
| namespace Mic { | ||||
| namespace Frontend::Mic { | ||||
| 
 | ||||
| enum class Signedness : u8 { | ||||
|     Signed, | ||||
|     Unsigned, | ||||
| }; | ||||
| 
 | ||||
| using Samples = std::vector<u8>; | ||||
| using SampleQueue = Common::SPSCQueue<Samples>; | ||||
| 
 | ||||
| struct Parameters { | ||||
|     Signedness sign; | ||||
|     u8 sample_size; | ||||
|  | @ -28,23 +30,20 @@ struct Parameters { | |||
| 
 | ||||
| class Interface { | ||||
| public: | ||||
|     Interface() = default; | ||||
| 
 | ||||
|     virtual ~Interface() = default; | ||||
| 
 | ||||
|     /// Starts the microphone. Called by Core
 | ||||
|     virtual void StartSampling(Parameters params) = 0; | ||||
| 
 | ||||
|     /// Stops the microphone. Called by Core
 | ||||
|     virtual void StopSampling() = 0; | ||||
| 
 | ||||
|     Interface() = default; | ||||
| 
 | ||||
|     Interface(const Interface& other) | ||||
|         : gain(other.gain), powered(other.powered), backing_memory(other.backing_memory), | ||||
|           backing_memory_size(other.backing_memory_size), parameters(other.parameters) {} | ||||
| 
 | ||||
|     /// Sets the backing memory that the mic should write raw samples into. Called by Core
 | ||||
|     void SetBackingMemory(u8* pointer, u32 size) { | ||||
|         backing_memory = pointer; | ||||
|         backing_memory_size = size; | ||||
|     } | ||||
|     /// Called from the actual event timing read back. The frontend impl is responsible for wrapping
 | ||||
|     /// up any data and returning them to the core so the core can write them to the sharedmem. If
 | ||||
|     /// theres nothing to return just return an empty vector
 | ||||
|     virtual Samples Read() = 0; | ||||
| 
 | ||||
|     /// Adjusts the Parameters. Implementations should update the parameters field in addition to
 | ||||
|     /// changing the mic to sample according to the new parameters. Called by Core
 | ||||
|  | @ -76,9 +75,6 @@ public: | |||
|     } | ||||
| 
 | ||||
| protected: | ||||
|     u8* backing_memory; | ||||
|     u32 backing_memory_size; | ||||
| 
 | ||||
|     Parameters parameters; | ||||
|     u8 gain = 0; | ||||
|     bool is_sampling = false; | ||||
|  | @ -99,12 +95,32 @@ public: | |||
|     void AdjustSampleRate(u32 sample_rate) override { | ||||
|         parameters.sample_rate = sample_rate; | ||||
|     } | ||||
| 
 | ||||
|     Samples Read() override { | ||||
|         return {}; | ||||
|     } | ||||
| }; | ||||
| 
 | ||||
| } // namespace Mic
 | ||||
| class StaticMic final : public Interface { | ||||
| public: | ||||
|     StaticMic(); | ||||
|     ~StaticMic() override; | ||||
| 
 | ||||
|     void StartSampling(Parameters params) override; | ||||
|     void StopSampling() override; | ||||
|     void AdjustSampleRate(u32 sample_rate) override; | ||||
| 
 | ||||
|     Samples Read() override; | ||||
| 
 | ||||
| private: | ||||
|     u16 sample_rate = 0; | ||||
|     u8 sample_size = 0; | ||||
|     std::vector<u8> CACHE_8_BIT; | ||||
|     std::vector<u8> CACHE_16_BIT; | ||||
| }; | ||||
| 
 | ||||
| void RegisterMic(std::shared_ptr<Mic::Interface> mic); | ||||
| 
 | ||||
| std::shared_ptr<Mic::Interface> GetCurrentMic(); | ||||
| 
 | ||||
| } // namespace Frontend
 | ||||
| } // namespace Frontend::Mic
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue