Ryan Haining | 2c1efe6 | 2018-12-20 17:44:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2018 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | #include <SDL2/SDL.h> |
| 18 | #include <cstdint> |
| 19 | |
| 20 | namespace cfp { |
| 21 | |
| 22 | class SDLLib; |
| 23 | |
| 24 | class SDLAudioDevice { |
| 25 | public: |
| 26 | SDLAudioDevice(SDLAudioDevice&& other); |
| 27 | SDLAudioDevice& operator=(SDLAudioDevice&& other); |
| 28 | |
| 29 | SDLAudioDevice(const SDLAudioDevice&) = delete; |
| 30 | SDLAudioDevice& operator=(const SDLAudioDevice&) = delete; |
| 31 | |
| 32 | ~SDLAudioDevice(); |
| 33 | |
| 34 | int QueueAudio(const void* data, std::uint32_t len); |
| 35 | |
| 36 | private: |
| 37 | friend SDLLib; |
| 38 | explicit SDLAudioDevice(SDL_AudioDeviceID device_id); |
| 39 | void close(); |
| 40 | |
| 41 | SDL_AudioDeviceID device_id_{}; |
| 42 | }; |
| 43 | |
| 44 | class SDLLib { |
| 45 | public: |
| 46 | SDLLib(); |
| 47 | ~SDLLib(); |
| 48 | |
| 49 | SDLLib(const SDLLib&) = delete; |
| 50 | SDLLib& operator=(const SDLLib&) = delete; |
| 51 | |
| 52 | SDLAudioDevice OpenAudioDevice(int freq, std::uint8_t num_channels); |
| 53 | }; |
| 54 | |
| 55 | } // namespace cfp |