this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

CoreAudio: Rework of AFAVFormatComponent

+218 -61
+11 -2
src/CoreAudio/AFAVFormatComponent/AVFormatFileObject.h
··· 21 21 #define _AV_FORMAT_FILE_OBJECT_H 22 22 #include "AudioFileComponentBase.h" 23 23 24 + template <typename FormatClass, typename FileClass, UInt32 FileType> 24 25 class AVFormatFileObject : public AudioFileObjectComponentBase 25 26 { 26 27 public: 27 - AVFormatFileObject(AudioComponentInstance inInstance); 28 - AudioFileFormat* GetAudioFormat() const override; 28 + AVFormatFileObject(AudioComponentInstance inInstance) 29 + : AudioFileObjectComponentBase(inInstance) 30 + { 31 + mAudioFileObject = new FileClass; 32 + } 33 + AudioFileFormat* GetAudioFormat() const override 34 + { 35 + static FormatClass inst; 36 + return &inst; 37 + } 29 38 }; 30 39 31 40 #endif
+29 -5
src/CoreAudio/AFAVFormatComponent/AudioFileFormatGeneric.cpp
··· 101 101 102 102 AudioFileObject* AudioFileFormatGeneric::New() 103 103 { 104 - // TODO 104 + // This method is never called from AFPublic 105 105 return nullptr; 106 106 } 107 107 108 108 OSStatus AudioFileFormatGeneric::GetAvailableFormatIDs(UInt32* ioDataSize, void* outPropertyData) 109 109 { 110 - // TODO 111 - return unimpErr; 110 + const std::vector<Format>& formats = description().formats; 111 + 112 + *ioDataSize = formats.size() * sizeof(UInt32); 113 + if (outPropertyData) 114 + { 115 + UInt32* dest = static_cast<UInt32*>(outPropertyData); 116 + for (int i = 0; i < formats.size(); i++) 117 + dest[i] = formats[i].mFormatID; 118 + } 119 + 120 + return noErr; 112 121 } 113 122 114 123 OSStatus AudioFileFormatGeneric::GetAvailableStreamDescriptions(UInt32 inFormatID, UInt32* ioDataSize, void* outPropertyData) 115 124 { 116 - // TODO 117 - return unimpErr; 125 + int count = 0; 126 + 127 + for (const Format& format : description().formats) 128 + { 129 + if (format.mFormatID == inFormatID) 130 + { 131 + if (outPropertyData) 132 + { 133 + AudioStreamBasicDescription* ptr = static_cast<AudioStreamBasicDescription*>(outPropertyData); 134 + ptr[count] = format; 135 + } 136 + count++; 137 + } 138 + } 139 + 140 + *ioDataSize = count * sizeof(AudioStreamBasicDescription); 141 + return noErr; 118 142 }
+11
src/CoreAudio/AFAVFormatComponent/AudioFileFormatGeneric.h
··· 34 34 35 35 AudioFileObject* New() override; 36 36 AudioFileStreamObject* NewStream() override { return NULL; } 37 + 38 + // File format -> data formats 39 + // https://developer.apple.com/library/archive/documentation/MusicAudio/Conceptual/CoreAudioOverview/SupportedAudioFormatsMacOSX/SupportedAudioFormatsMacOSX.html 37 40 OSStatus GetAvailableFormatIDs(UInt32* ioDataSize, void* outPropertyData) override; 41 + 38 42 OSStatus GetAvailableStreamDescriptions(UInt32 inFormatID, UInt32* ioDataSize, void* outPropertyData) override; 39 43 private: 40 44 static CFArrayRef toCFArray(const std::vector<const char*>& array); 41 45 protected: 46 + struct Format : public AudioStreamBasicDescription 47 + { 48 + Format(UInt32 formatID) { mFormatID = formatID; } 49 + Format(UInt32 formatID, UInt32 formatFlags, UInt32 bitsPerChannel) { mFormatID = formatID; mFormatFlags = formatFlags; mBitsPerChannel = bitsPerChannel; } 50 + Format() {} 51 + }; 42 52 struct Description 43 53 { 44 54 const char* name; 45 55 std::vector<const char*> extensions; 46 56 std::vector<const char*> utis; 47 57 std::vector<const char*> mimeTypes; 58 + std::vector<Format> formats; 48 59 }; 49 60 virtual const Description& description() const = 0; 50 61 private:
-42
src/CoreAudio/AFAVFormatComponent/AudioFileFormatMP3.cpp
··· 1 - /* 2 - This file is part of Darling. 3 - 4 - Copyright (C) 2020 Lubos Dolezel 5 - 6 - Darling is free software: you can redistribute it and/or modify 7 - it under the terms of the GNU General Public License as published by 8 - the Free Software Foundation, either version 3 of the License, or 9 - (at your option) any later version. 10 - 11 - Darling is distributed in the hope that it will be useful, 12 - but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 - GNU General Public License for more details. 15 - 16 - You should have received a copy of the GNU General Public License 17 - along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 - */ 19 - 20 - #include "AudioFileFormatMP3.h" 21 - 22 - AudioFileFormatMP3::AudioFileFormatMP3() 23 - : AudioFileFormatGeneric('.mp3', "mp3") 24 - { 25 - } 26 - 27 - AudioFileFormatMP3* AudioFileFormatMP3::instance() 28 - { 29 - static AudioFileFormatMP3 inst; 30 - return &inst; 31 - } 32 - 33 - const AudioFileFormatMP3::Description& AudioFileFormatMP3::description() const 34 - { 35 - static const Description d = { 36 - .name = "MPEG Layer 3", 37 - .extensions = { "mp3" }, 38 - .utis = { "public.mp3", "public.audio", "public.data" }, 39 - .mimeTypes = { "audio/mpeg" }, 40 - }; 41 - return d; 42 - }
+6 -10
src/CoreAudio/AFAVFormatComponent/AudioFileFormatMP3.h src/CoreAudio/AFAVFormatComponent/AudioFileMP3.h
··· 17 17 along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 18 */ 19 19 20 - #ifndef _AUDIO_FILE_FORMAT_MP3_H 21 - #define _AUDIO_FILE_FORMAT_MP3_H 22 - #include "AudioFileFormatGeneric.h" 20 + #ifndef _AUDIO_FILE_MP3_H 21 + #define _AUDIO_FILE_MP3_H 22 + #include "AudioFileObject.h" 23 23 24 - class AudioFileFormatMP3 : public AudioFileFormatGeneric 24 + class AudioFileMP3 : public AudioFileObject 25 25 { 26 - private: 27 - AudioFileFormatMP3(); 28 26 public: 29 - static AudioFileFormatMP3* instance(); 30 - protected: 31 - const Description& description() const override; 27 + AudioFileMP3(); 28 + Boolean IsDataFormatSupported(const AudioStreamBasicDescription *inFormat) override; 32 29 }; 33 30 34 31 #endif 35 -
+60
src/CoreAudio/AFAVFormatComponent/AudioFileMP3.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + #include "AudioFileMP3.h" 20 + #include "AVFormatFileObject.h" 21 + #include "AudioFileFormatGeneric.h" 22 + 23 + class AudioFileFormatMP3 : public AudioFileFormatGeneric 24 + { 25 + public: 26 + AudioFileFormatMP3() : AudioFileFormatGeneric('.mp3', "mp3") {} 27 + protected: 28 + const Description& description() const override 29 + { 30 + static const Description d = { 31 + .name = "MPEG Layer 3", 32 + .extensions = { "mp3" }, 33 + .utis = { "public.mp3", "public.audio", "public.data" }, 34 + .mimeTypes = { "audio/mpeg" }, 35 + .formats = { '.mp3' }, 36 + }; 37 + return d; 38 + } 39 + }; 40 + 41 + class MP3Component : public AVFormatFileObject<AudioFileFormatMP3, AudioFileMP3, '.mp3'> 42 + { 43 + public: 44 + MP3Component(AudioComponentInstance inInstance) : AVFormatFileObject(inInstance) {} 45 + }; 46 + 47 + #pragma GCC visibility push(default) 48 + AUDIOCOMPONENT_ENTRY(AudioFileComponentFactory, MP3Component); 49 + #pragma GCC visibility pop 50 + 51 + AudioFileMP3::AudioFileMP3() 52 + : AudioFileObject('.mp3') 53 + { 54 + 55 + } 56 + 57 + Boolean AudioFileMP3::IsDataFormatSupported(const AudioStreamBasicDescription *inFormat) 58 + { 59 + return true; 60 + }
+68
src/CoreAudio/AFAVFormatComponent/AudioFileWAV.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + #include "AudioFileWAV.h" 20 + #include "AVFormatFileObject.h" 21 + #include "AudioFileFormatGeneric.h" 22 + 23 + class AudioFileFormatWAV : public AudioFileFormatGeneric 24 + { 25 + public: 26 + AudioFileFormatWAV() : AudioFileFormatGeneric('.mp3', "wav") {} 27 + protected: 28 + const Description& description() const override 29 + { 30 + static const Description d = { 31 + .name = "WAVE", 32 + .extensions = { "wav" }, 33 + .utis = { "com.microsoft.waveform-audio", "public.audio", "public.data" }, 34 + .mimeTypes = { "audio/wav" }, 35 + .formats = { 36 + Format(kAudioFormatLinearPCM, 0, 8), 37 + Format(kAudioFormatLinearPCM, kAudioFormatFlagIsSignedInteger, 16), 38 + Format(kAudioFormatLinearPCM, kAudioFormatFlagIsSignedInteger, 24), 39 + Format(kAudioFormatLinearPCM, kAudioFormatFlagIsSignedInteger, 32), 40 + Format(kAudioFormatLinearPCM, kAudioFormatFlagIsFloat, 32), 41 + Format(kAudioFormatLinearPCM, kAudioFormatFlagIsFloat, 64), 42 + 'ulaw', 'alaw' 43 + }, 44 + }; 45 + return d; 46 + } 47 + }; 48 + 49 + class WAVComponent : public AVFormatFileObject<AudioFileFormatWAV, AudioFileWAV, '.wav'> 50 + { 51 + public: 52 + WAVComponent(AudioComponentInstance inInstance) : AVFormatFileObject(inInstance) {} 53 + }; 54 + 55 + #pragma GCC visibility push(default) 56 + AUDIOCOMPONENT_ENTRY(AudioFileComponentFactory, WAVComponent); 57 + #pragma GCC visibility pop 58 + 59 + AudioFileWAV::AudioFileWAV() 60 + : AudioFileObject('.wav') 61 + { 62 + 63 + } 64 + 65 + Boolean AudioFileWAV::IsDataFormatSupported(const AudioStreamBasicDescription *inFormat) 66 + { 67 + return true; 68 + }
+31
src/CoreAudio/AFAVFormatComponent/AudioFileWAV.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #ifndef _AUDIO_FILE_WAV_H 21 + #define _AUDIO_FILE_WAV_H 22 + #include "AudioFileObject.h" 23 + 24 + class AudioFileWAV : public AudioFileObject 25 + { 26 + public: 27 + AudioFileWAV(); 28 + Boolean IsDataFormatSupported(const AudioStreamBasicDescription *inFormat) override; 29 + }; 30 + 31 + #endif
+2 -2
src/CoreAudio/AFAVFormatComponent/CMakeLists.txt
··· 17 17 AFPublic/DataSource.cpp 18 18 AUPublic/AUBase/ComponentBase.cpp 19 19 PublicUtility/CACFDictionary.cpp 20 - AVFormatFileObject.cpp 21 20 AudioFileFormatGeneric.cpp 22 - AudioFileFormatMP3.cpp 21 + AudioFileMP3.cpp 22 + AudioFileWAV.cpp 23 23 ) 24 24 25 25 add_darling_bundle(AFAVFormatComponent "" ${component_sources})