mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 01:32:45 +00:00 
			
		
		
		
	 759e07579e
			
		
	
	
		759e07579e
		
	
	
	
	
		
			
			https://developer.apple.com/documentation/audiounit Apple has a number of audio frameworks we could use. This uses the Audio Unit framework, as it gives us most control over the rendering of the audio frames (such as being able to quickly pause / discard buffers). From some reading, we could implement niceties such as fading playback in and out while seeking over a short (10ms) period. This patch does not implement such fancy features though. Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
		
			
				
	
	
		
			39 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
 | |
|  * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/Error.h>
 | |
| #include <AK/NonnullRefPtr.h>
 | |
| #include <LibAudio/PlaybackStream.h>
 | |
| 
 | |
| namespace Audio {
 | |
| 
 | |
| class AudioState;
 | |
| 
 | |
| class PlaybackStreamAudioUnit final : public PlaybackStream {
 | |
| public:
 | |
|     static ErrorOr<NonnullRefPtr<PlaybackStream>> create(OutputState initial_output_state, u32 sample_rate, u8 channels, u32 target_latency_ms, AudioDataRequestCallback&& data_request_callback);
 | |
| 
 | |
|     virtual void set_underrun_callback(Function<void()>) override;
 | |
| 
 | |
|     virtual NonnullRefPtr<Core::ThreadedPromise<Duration>> resume() override;
 | |
|     virtual NonnullRefPtr<Core::ThreadedPromise<void>> drain_buffer_and_suspend() override;
 | |
|     virtual NonnullRefPtr<Core::ThreadedPromise<void>> discard_buffer_and_suspend() override;
 | |
| 
 | |
|     virtual ErrorOr<Duration> total_time_played() override;
 | |
| 
 | |
|     virtual NonnullRefPtr<Core::ThreadedPromise<void>> set_volume(double) override;
 | |
| 
 | |
| private:
 | |
|     explicit PlaybackStreamAudioUnit(NonnullRefPtr<AudioState>);
 | |
|     ~PlaybackStreamAudioUnit();
 | |
| 
 | |
|     NonnullRefPtr<AudioState> m_state;
 | |
| };
 | |
| 
 | |
| }
 |