├── .gitignore ├── JKRecorderKit ├── JKRecorderKit.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── JKRecorderKit │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Class │ │ ├── JKAudioFilePathTool.h │ │ ├── JKAudioFilePathTool.m │ │ ├── JKAudioFileTool.h │ │ ├── JKAudioFileTool.m │ │ ├── JKAudioPlayerTool.h │ │ ├── JKAudioPlayerTool.m │ │ ├── JKAudioTool.h │ │ ├── JKAudioTool.m │ │ ├── JKRecorderKit.h │ │ ├── JKSingle.h │ │ └── lame │ │ │ ├── JKLameTool.h │ │ │ ├── JKLameTool.m │ │ │ ├── lame.h │ │ │ └── libmp3lame.a │ ├── Info.plist │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── JKRecorderKitTests │ ├── Info.plist │ └── JKRecorderKitTests.m └── JKRecorderKitUITests │ ├── Info.plist │ └── JKRecorderKitUITests.m ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | # CocoaPods 32 | # 33 | # We recommend against adding the Pods directory to your .gitignore. However 34 | # you should judge for yourself, the pros and cons are mentioned at: 35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 36 | # 37 | # Pods/ 38 | 39 | # Carthage 40 | # 41 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 42 | # Carthage/Checkouts 43 | 44 | Carthage/Build 45 | 46 | # fastlane 47 | # 48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 49 | # screenshots whenever they are needed. 50 | # For more information about the recommended setup visit: 51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 52 | 53 | fastlane/report.xml 54 | fastlane/Preview.html 55 | fastlane/screenshots/**/*.png 56 | fastlane/test_output 57 | 58 | # Code Injection 59 | # 60 | # After new code Injection tools there's a generated folder /iOSInjectionProject 61 | # https://github.com/johnno1962/injectionforxcode 62 | 63 | iOSInjectionProject/ 64 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E23F98A6221E4692006C4141 /* libmp3lame.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E23F98A4221E4692006C4141 /* libmp3lame.a */; }; 11 | E23F98A9221E46F5006C4141 /* JKLameTool.m in Sources */ = {isa = PBXBuildFile; fileRef = E23F98A8221E46F5006C4141 /* JKLameTool.m */; }; 12 | E23F98AC221E5843006C4141 /* JKAudioFilePathTool.m in Sources */ = {isa = PBXBuildFile; fileRef = E23F98AB221E5843006C4141 /* JKAudioFilePathTool.m */; }; 13 | E285A879221D303300FA70DB /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E285A878221D303300FA70DB /* AppDelegate.m */; }; 14 | E285A87C221D303300FA70DB /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E285A87B221D303300FA70DB /* ViewController.m */; }; 15 | E285A87F221D303300FA70DB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E285A87D221D303300FA70DB /* Main.storyboard */; }; 16 | E285A881221D303400FA70DB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E285A880221D303400FA70DB /* Assets.xcassets */; }; 17 | E285A884221D303400FA70DB /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E285A882221D303400FA70DB /* LaunchScreen.storyboard */; }; 18 | E285A887221D303400FA70DB /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E285A886221D303400FA70DB /* main.m */; }; 19 | E285A891221D303400FA70DB /* JKRecorderKitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E285A890221D303400FA70DB /* JKRecorderKitTests.m */; }; 20 | E285A89C221D303400FA70DB /* JKRecorderKitUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = E285A89B221D303400FA70DB /* JKRecorderKitUITests.m */; }; 21 | E285A8B3221D350100FA70DB /* JKAudioTool.m in Sources */ = {isa = PBXBuildFile; fileRef = E285A8B2221D350100FA70DB /* JKAudioTool.m */; }; 22 | E285A8B6221D3AC800FA70DB /* JKAudioPlayerTool.m in Sources */ = {isa = PBXBuildFile; fileRef = E285A8B5221D3AC800FA70DB /* JKAudioPlayerTool.m */; }; 23 | E285A8BA221D495F00FA70DB /* JKAudioFileTool.m in Sources */ = {isa = PBXBuildFile; fileRef = E285A8B9221D495F00FA70DB /* JKAudioFileTool.m */; }; 24 | /* End PBXBuildFile section */ 25 | 26 | /* Begin PBXContainerItemProxy section */ 27 | E285A88D221D303400FA70DB /* PBXContainerItemProxy */ = { 28 | isa = PBXContainerItemProxy; 29 | containerPortal = E285A86C221D303300FA70DB /* Project object */; 30 | proxyType = 1; 31 | remoteGlobalIDString = E285A873221D303300FA70DB; 32 | remoteInfo = JKRecorderKit; 33 | }; 34 | E285A898221D303400FA70DB /* PBXContainerItemProxy */ = { 35 | isa = PBXContainerItemProxy; 36 | containerPortal = E285A86C221D303300FA70DB /* Project object */; 37 | proxyType = 1; 38 | remoteGlobalIDString = E285A873221D303300FA70DB; 39 | remoteInfo = JKRecorderKit; 40 | }; 41 | /* End PBXContainerItemProxy section */ 42 | 43 | /* Begin PBXFileReference section */ 44 | E23F98A4221E4692006C4141 /* libmp3lame.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libmp3lame.a; sourceTree = ""; }; 45 | E23F98A5221E4692006C4141 /* lame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lame.h; sourceTree = ""; }; 46 | E23F98A7221E46F5006C4141 /* JKLameTool.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JKLameTool.h; sourceTree = ""; }; 47 | E23F98A8221E46F5006C4141 /* JKLameTool.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JKLameTool.m; sourceTree = ""; }; 48 | E23F98AA221E5843006C4141 /* JKAudioFilePathTool.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JKAudioFilePathTool.h; sourceTree = ""; }; 49 | E23F98AB221E5843006C4141 /* JKAudioFilePathTool.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JKAudioFilePathTool.m; sourceTree = ""; }; 50 | E285A874221D303300FA70DB /* JKRecorderKit.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JKRecorderKit.app; sourceTree = BUILT_PRODUCTS_DIR; }; 51 | E285A877221D303300FA70DB /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 52 | E285A878221D303300FA70DB /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 53 | E285A87A221D303300FA70DB /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 54 | E285A87B221D303300FA70DB /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 55 | E285A87E221D303300FA70DB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 56 | E285A880221D303400FA70DB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 57 | E285A883221D303400FA70DB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 58 | E285A885221D303400FA70DB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 59 | E285A886221D303400FA70DB /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 60 | E285A88C221D303400FA70DB /* JKRecorderKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JKRecorderKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 61 | E285A890221D303400FA70DB /* JKRecorderKitTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JKRecorderKitTests.m; sourceTree = ""; }; 62 | E285A892221D303400FA70DB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 63 | E285A897221D303400FA70DB /* JKRecorderKitUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JKRecorderKitUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 64 | E285A89B221D303400FA70DB /* JKRecorderKitUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JKRecorderKitUITests.m; sourceTree = ""; }; 65 | E285A89D221D303400FA70DB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 66 | E285A8B0221D345A00FA70DB /* JKSingle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JKSingle.h; sourceTree = ""; }; 67 | E285A8B1221D350100FA70DB /* JKAudioTool.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JKAudioTool.h; sourceTree = ""; }; 68 | E285A8B2221D350100FA70DB /* JKAudioTool.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JKAudioTool.m; sourceTree = ""; }; 69 | E285A8B4221D3AC800FA70DB /* JKAudioPlayerTool.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JKAudioPlayerTool.h; sourceTree = ""; }; 70 | E285A8B5221D3AC800FA70DB /* JKAudioPlayerTool.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JKAudioPlayerTool.m; sourceTree = ""; }; 71 | E285A8B7221D3B7500FA70DB /* JKRecorderKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JKRecorderKit.h; sourceTree = ""; }; 72 | E285A8B8221D495F00FA70DB /* JKAudioFileTool.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JKAudioFileTool.h; sourceTree = ""; }; 73 | E285A8B9221D495F00FA70DB /* JKAudioFileTool.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JKAudioFileTool.m; sourceTree = ""; }; 74 | /* End PBXFileReference section */ 75 | 76 | /* Begin PBXFrameworksBuildPhase section */ 77 | E285A871221D303300FA70DB /* Frameworks */ = { 78 | isa = PBXFrameworksBuildPhase; 79 | buildActionMask = 2147483647; 80 | files = ( 81 | E23F98A6221E4692006C4141 /* libmp3lame.a in Frameworks */, 82 | ); 83 | runOnlyForDeploymentPostprocessing = 0; 84 | }; 85 | E285A889221D303400FA70DB /* Frameworks */ = { 86 | isa = PBXFrameworksBuildPhase; 87 | buildActionMask = 2147483647; 88 | files = ( 89 | ); 90 | runOnlyForDeploymentPostprocessing = 0; 91 | }; 92 | E285A894221D303400FA70DB /* Frameworks */ = { 93 | isa = PBXFrameworksBuildPhase; 94 | buildActionMask = 2147483647; 95 | files = ( 96 | ); 97 | runOnlyForDeploymentPostprocessing = 0; 98 | }; 99 | /* End PBXFrameworksBuildPhase section */ 100 | 101 | /* Begin PBXGroup section */ 102 | E23F98A3221E4692006C4141 /* lame */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | E23F98A4221E4692006C4141 /* libmp3lame.a */, 106 | E23F98A5221E4692006C4141 /* lame.h */, 107 | E23F98A7221E46F5006C4141 /* JKLameTool.h */, 108 | E23F98A8221E46F5006C4141 /* JKLameTool.m */, 109 | ); 110 | path = lame; 111 | sourceTree = ""; 112 | }; 113 | E285A86B221D303300FA70DB = { 114 | isa = PBXGroup; 115 | children = ( 116 | E285A876221D303300FA70DB /* JKRecorderKit */, 117 | E285A88F221D303400FA70DB /* JKRecorderKitTests */, 118 | E285A89A221D303400FA70DB /* JKRecorderKitUITests */, 119 | E285A875221D303300FA70DB /* Products */, 120 | ); 121 | sourceTree = ""; 122 | }; 123 | E285A875221D303300FA70DB /* Products */ = { 124 | isa = PBXGroup; 125 | children = ( 126 | E285A874221D303300FA70DB /* JKRecorderKit.app */, 127 | E285A88C221D303400FA70DB /* JKRecorderKitTests.xctest */, 128 | E285A897221D303400FA70DB /* JKRecorderKitUITests.xctest */, 129 | ); 130 | name = Products; 131 | sourceTree = ""; 132 | }; 133 | E285A876221D303300FA70DB /* JKRecorderKit */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | E285A877221D303300FA70DB /* AppDelegate.h */, 137 | E285A878221D303300FA70DB /* AppDelegate.m */, 138 | E285A87A221D303300FA70DB /* ViewController.h */, 139 | E285A87B221D303300FA70DB /* ViewController.m */, 140 | E285A8A9221D31A200FA70DB /* Class */, 141 | E285A87D221D303300FA70DB /* Main.storyboard */, 142 | E285A880221D303400FA70DB /* Assets.xcassets */, 143 | E285A882221D303400FA70DB /* LaunchScreen.storyboard */, 144 | E285A885221D303400FA70DB /* Info.plist */, 145 | E285A886221D303400FA70DB /* main.m */, 146 | ); 147 | path = JKRecorderKit; 148 | sourceTree = ""; 149 | }; 150 | E285A88F221D303400FA70DB /* JKRecorderKitTests */ = { 151 | isa = PBXGroup; 152 | children = ( 153 | E285A890221D303400FA70DB /* JKRecorderKitTests.m */, 154 | E285A892221D303400FA70DB /* Info.plist */, 155 | ); 156 | path = JKRecorderKitTests; 157 | sourceTree = ""; 158 | }; 159 | E285A89A221D303400FA70DB /* JKRecorderKitUITests */ = { 160 | isa = PBXGroup; 161 | children = ( 162 | E285A89B221D303400FA70DB /* JKRecorderKitUITests.m */, 163 | E285A89D221D303400FA70DB /* Info.plist */, 164 | ); 165 | path = JKRecorderKitUITests; 166 | sourceTree = ""; 167 | }; 168 | E285A8A9221D31A200FA70DB /* Class */ = { 169 | isa = PBXGroup; 170 | children = ( 171 | E23F98A3221E4692006C4141 /* lame */, 172 | E285A8B7221D3B7500FA70DB /* JKRecorderKit.h */, 173 | E285A8B0221D345A00FA70DB /* JKSingle.h */, 174 | E285A8B1221D350100FA70DB /* JKAudioTool.h */, 175 | E285A8B2221D350100FA70DB /* JKAudioTool.m */, 176 | E285A8B8221D495F00FA70DB /* JKAudioFileTool.h */, 177 | E285A8B9221D495F00FA70DB /* JKAudioFileTool.m */, 178 | E285A8B4221D3AC800FA70DB /* JKAudioPlayerTool.h */, 179 | E285A8B5221D3AC800FA70DB /* JKAudioPlayerTool.m */, 180 | E23F98AA221E5843006C4141 /* JKAudioFilePathTool.h */, 181 | E23F98AB221E5843006C4141 /* JKAudioFilePathTool.m */, 182 | ); 183 | path = Class; 184 | sourceTree = ""; 185 | }; 186 | /* End PBXGroup section */ 187 | 188 | /* Begin PBXNativeTarget section */ 189 | E285A873221D303300FA70DB /* JKRecorderKit */ = { 190 | isa = PBXNativeTarget; 191 | buildConfigurationList = E285A8A0221D303400FA70DB /* Build configuration list for PBXNativeTarget "JKRecorderKit" */; 192 | buildPhases = ( 193 | E285A870221D303300FA70DB /* Sources */, 194 | E285A871221D303300FA70DB /* Frameworks */, 195 | E285A872221D303300FA70DB /* Resources */, 196 | ); 197 | buildRules = ( 198 | ); 199 | dependencies = ( 200 | ); 201 | name = JKRecorderKit; 202 | productName = JKRecorderKit; 203 | productReference = E285A874221D303300FA70DB /* JKRecorderKit.app */; 204 | productType = "com.apple.product-type.application"; 205 | }; 206 | E285A88B221D303400FA70DB /* JKRecorderKitTests */ = { 207 | isa = PBXNativeTarget; 208 | buildConfigurationList = E285A8A3221D303400FA70DB /* Build configuration list for PBXNativeTarget "JKRecorderKitTests" */; 209 | buildPhases = ( 210 | E285A888221D303400FA70DB /* Sources */, 211 | E285A889221D303400FA70DB /* Frameworks */, 212 | E285A88A221D303400FA70DB /* Resources */, 213 | ); 214 | buildRules = ( 215 | ); 216 | dependencies = ( 217 | E285A88E221D303400FA70DB /* PBXTargetDependency */, 218 | ); 219 | name = JKRecorderKitTests; 220 | productName = JKRecorderKitTests; 221 | productReference = E285A88C221D303400FA70DB /* JKRecorderKitTests.xctest */; 222 | productType = "com.apple.product-type.bundle.unit-test"; 223 | }; 224 | E285A896221D303400FA70DB /* JKRecorderKitUITests */ = { 225 | isa = PBXNativeTarget; 226 | buildConfigurationList = E285A8A6221D303400FA70DB /* Build configuration list for PBXNativeTarget "JKRecorderKitUITests" */; 227 | buildPhases = ( 228 | E285A893221D303400FA70DB /* Sources */, 229 | E285A894221D303400FA70DB /* Frameworks */, 230 | E285A895221D303400FA70DB /* Resources */, 231 | ); 232 | buildRules = ( 233 | ); 234 | dependencies = ( 235 | E285A899221D303400FA70DB /* PBXTargetDependency */, 236 | ); 237 | name = JKRecorderKitUITests; 238 | productName = JKRecorderKitUITests; 239 | productReference = E285A897221D303400FA70DB /* JKRecorderKitUITests.xctest */; 240 | productType = "com.apple.product-type.bundle.ui-testing"; 241 | }; 242 | /* End PBXNativeTarget section */ 243 | 244 | /* Begin PBXProject section */ 245 | E285A86C221D303300FA70DB /* Project object */ = { 246 | isa = PBXProject; 247 | attributes = { 248 | LastUpgradeCheck = 1010; 249 | ORGANIZATIONNAME = "JK科技有限公司"; 250 | TargetAttributes = { 251 | E285A873221D303300FA70DB = { 252 | CreatedOnToolsVersion = 10.1; 253 | }; 254 | E285A88B221D303400FA70DB = { 255 | CreatedOnToolsVersion = 10.1; 256 | TestTargetID = E285A873221D303300FA70DB; 257 | }; 258 | E285A896221D303400FA70DB = { 259 | CreatedOnToolsVersion = 10.1; 260 | TestTargetID = E285A873221D303300FA70DB; 261 | }; 262 | }; 263 | }; 264 | buildConfigurationList = E285A86F221D303300FA70DB /* Build configuration list for PBXProject "JKRecorderKit" */; 265 | compatibilityVersion = "Xcode 9.3"; 266 | developmentRegion = en; 267 | hasScannedForEncodings = 0; 268 | knownRegions = ( 269 | en, 270 | Base, 271 | ); 272 | mainGroup = E285A86B221D303300FA70DB; 273 | productRefGroup = E285A875221D303300FA70DB /* Products */; 274 | projectDirPath = ""; 275 | projectRoot = ""; 276 | targets = ( 277 | E285A873221D303300FA70DB /* JKRecorderKit */, 278 | E285A88B221D303400FA70DB /* JKRecorderKitTests */, 279 | E285A896221D303400FA70DB /* JKRecorderKitUITests */, 280 | ); 281 | }; 282 | /* End PBXProject section */ 283 | 284 | /* Begin PBXResourcesBuildPhase section */ 285 | E285A872221D303300FA70DB /* Resources */ = { 286 | isa = PBXResourcesBuildPhase; 287 | buildActionMask = 2147483647; 288 | files = ( 289 | E285A884221D303400FA70DB /* LaunchScreen.storyboard in Resources */, 290 | E285A881221D303400FA70DB /* Assets.xcassets in Resources */, 291 | E285A87F221D303300FA70DB /* Main.storyboard in Resources */, 292 | ); 293 | runOnlyForDeploymentPostprocessing = 0; 294 | }; 295 | E285A88A221D303400FA70DB /* Resources */ = { 296 | isa = PBXResourcesBuildPhase; 297 | buildActionMask = 2147483647; 298 | files = ( 299 | ); 300 | runOnlyForDeploymentPostprocessing = 0; 301 | }; 302 | E285A895221D303400FA70DB /* Resources */ = { 303 | isa = PBXResourcesBuildPhase; 304 | buildActionMask = 2147483647; 305 | files = ( 306 | ); 307 | runOnlyForDeploymentPostprocessing = 0; 308 | }; 309 | /* End PBXResourcesBuildPhase section */ 310 | 311 | /* Begin PBXSourcesBuildPhase section */ 312 | E285A870221D303300FA70DB /* Sources */ = { 313 | isa = PBXSourcesBuildPhase; 314 | buildActionMask = 2147483647; 315 | files = ( 316 | E285A8B6221D3AC800FA70DB /* JKAudioPlayerTool.m in Sources */, 317 | E285A87C221D303300FA70DB /* ViewController.m in Sources */, 318 | E23F98AC221E5843006C4141 /* JKAudioFilePathTool.m in Sources */, 319 | E285A8B3221D350100FA70DB /* JKAudioTool.m in Sources */, 320 | E285A8BA221D495F00FA70DB /* JKAudioFileTool.m in Sources */, 321 | E23F98A9221E46F5006C4141 /* JKLameTool.m in Sources */, 322 | E285A887221D303400FA70DB /* main.m in Sources */, 323 | E285A879221D303300FA70DB /* AppDelegate.m in Sources */, 324 | ); 325 | runOnlyForDeploymentPostprocessing = 0; 326 | }; 327 | E285A888221D303400FA70DB /* Sources */ = { 328 | isa = PBXSourcesBuildPhase; 329 | buildActionMask = 2147483647; 330 | files = ( 331 | E285A891221D303400FA70DB /* JKRecorderKitTests.m in Sources */, 332 | ); 333 | runOnlyForDeploymentPostprocessing = 0; 334 | }; 335 | E285A893221D303400FA70DB /* Sources */ = { 336 | isa = PBXSourcesBuildPhase; 337 | buildActionMask = 2147483647; 338 | files = ( 339 | E285A89C221D303400FA70DB /* JKRecorderKitUITests.m in Sources */, 340 | ); 341 | runOnlyForDeploymentPostprocessing = 0; 342 | }; 343 | /* End PBXSourcesBuildPhase section */ 344 | 345 | /* Begin PBXTargetDependency section */ 346 | E285A88E221D303400FA70DB /* PBXTargetDependency */ = { 347 | isa = PBXTargetDependency; 348 | target = E285A873221D303300FA70DB /* JKRecorderKit */; 349 | targetProxy = E285A88D221D303400FA70DB /* PBXContainerItemProxy */; 350 | }; 351 | E285A899221D303400FA70DB /* PBXTargetDependency */ = { 352 | isa = PBXTargetDependency; 353 | target = E285A873221D303300FA70DB /* JKRecorderKit */; 354 | targetProxy = E285A898221D303400FA70DB /* PBXContainerItemProxy */; 355 | }; 356 | /* End PBXTargetDependency section */ 357 | 358 | /* Begin PBXVariantGroup section */ 359 | E285A87D221D303300FA70DB /* Main.storyboard */ = { 360 | isa = PBXVariantGroup; 361 | children = ( 362 | E285A87E221D303300FA70DB /* Base */, 363 | ); 364 | name = Main.storyboard; 365 | sourceTree = ""; 366 | }; 367 | E285A882221D303400FA70DB /* LaunchScreen.storyboard */ = { 368 | isa = PBXVariantGroup; 369 | children = ( 370 | E285A883221D303400FA70DB /* Base */, 371 | ); 372 | name = LaunchScreen.storyboard; 373 | sourceTree = ""; 374 | }; 375 | /* End PBXVariantGroup section */ 376 | 377 | /* Begin XCBuildConfiguration section */ 378 | E285A89E221D303400FA70DB /* Debug */ = { 379 | isa = XCBuildConfiguration; 380 | buildSettings = { 381 | ALWAYS_SEARCH_USER_PATHS = NO; 382 | CLANG_ANALYZER_NONNULL = YES; 383 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 384 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 385 | CLANG_CXX_LIBRARY = "libc++"; 386 | CLANG_ENABLE_MODULES = YES; 387 | CLANG_ENABLE_OBJC_ARC = YES; 388 | CLANG_ENABLE_OBJC_WEAK = YES; 389 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 390 | CLANG_WARN_BOOL_CONVERSION = YES; 391 | CLANG_WARN_COMMA = YES; 392 | CLANG_WARN_CONSTANT_CONVERSION = YES; 393 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 394 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 395 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 396 | CLANG_WARN_EMPTY_BODY = YES; 397 | CLANG_WARN_ENUM_CONVERSION = YES; 398 | CLANG_WARN_INFINITE_RECURSION = YES; 399 | CLANG_WARN_INT_CONVERSION = YES; 400 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 401 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 402 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 403 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 404 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 405 | CLANG_WARN_STRICT_PROTOTYPES = YES; 406 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 407 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 408 | CLANG_WARN_UNREACHABLE_CODE = YES; 409 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 410 | CODE_SIGN_IDENTITY = "iPhone Developer"; 411 | COPY_PHASE_STRIP = NO; 412 | DEBUG_INFORMATION_FORMAT = dwarf; 413 | ENABLE_STRICT_OBJC_MSGSEND = YES; 414 | ENABLE_TESTABILITY = YES; 415 | GCC_C_LANGUAGE_STANDARD = gnu11; 416 | GCC_DYNAMIC_NO_PIC = NO; 417 | GCC_NO_COMMON_BLOCKS = YES; 418 | GCC_OPTIMIZATION_LEVEL = 0; 419 | GCC_PREPROCESSOR_DEFINITIONS = ( 420 | "DEBUG=1", 421 | "$(inherited)", 422 | ); 423 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 424 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 425 | GCC_WARN_UNDECLARED_SELECTOR = YES; 426 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 427 | GCC_WARN_UNUSED_FUNCTION = YES; 428 | GCC_WARN_UNUSED_VARIABLE = YES; 429 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 430 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 431 | MTL_FAST_MATH = YES; 432 | ONLY_ACTIVE_ARCH = YES; 433 | SDKROOT = iphoneos; 434 | }; 435 | name = Debug; 436 | }; 437 | E285A89F221D303400FA70DB /* Release */ = { 438 | isa = XCBuildConfiguration; 439 | buildSettings = { 440 | ALWAYS_SEARCH_USER_PATHS = NO; 441 | CLANG_ANALYZER_NONNULL = YES; 442 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 443 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 444 | CLANG_CXX_LIBRARY = "libc++"; 445 | CLANG_ENABLE_MODULES = YES; 446 | CLANG_ENABLE_OBJC_ARC = YES; 447 | CLANG_ENABLE_OBJC_WEAK = YES; 448 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 449 | CLANG_WARN_BOOL_CONVERSION = YES; 450 | CLANG_WARN_COMMA = YES; 451 | CLANG_WARN_CONSTANT_CONVERSION = YES; 452 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 453 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 454 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 455 | CLANG_WARN_EMPTY_BODY = YES; 456 | CLANG_WARN_ENUM_CONVERSION = YES; 457 | CLANG_WARN_INFINITE_RECURSION = YES; 458 | CLANG_WARN_INT_CONVERSION = YES; 459 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 460 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 461 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 462 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 463 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 464 | CLANG_WARN_STRICT_PROTOTYPES = YES; 465 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 466 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 467 | CLANG_WARN_UNREACHABLE_CODE = YES; 468 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 469 | CODE_SIGN_IDENTITY = "iPhone Developer"; 470 | COPY_PHASE_STRIP = NO; 471 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 472 | ENABLE_NS_ASSERTIONS = NO; 473 | ENABLE_STRICT_OBJC_MSGSEND = YES; 474 | GCC_C_LANGUAGE_STANDARD = gnu11; 475 | GCC_NO_COMMON_BLOCKS = YES; 476 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 477 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 478 | GCC_WARN_UNDECLARED_SELECTOR = YES; 479 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 480 | GCC_WARN_UNUSED_FUNCTION = YES; 481 | GCC_WARN_UNUSED_VARIABLE = YES; 482 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 483 | MTL_ENABLE_DEBUG_INFO = NO; 484 | MTL_FAST_MATH = YES; 485 | SDKROOT = iphoneos; 486 | VALIDATE_PRODUCT = YES; 487 | }; 488 | name = Release; 489 | }; 490 | E285A8A1221D303400FA70DB /* Debug */ = { 491 | isa = XCBuildConfiguration; 492 | buildSettings = { 493 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 494 | CODE_SIGN_STYLE = Automatic; 495 | DEVELOPMENT_TEAM = 75LW4CAG6Y; 496 | INFOPLIST_FILE = JKRecorderKit/Info.plist; 497 | LD_RUNPATH_SEARCH_PATHS = ( 498 | "$(inherited)", 499 | "@executable_path/Frameworks", 500 | ); 501 | LIBRARY_SEARCH_PATHS = ( 502 | "$(inherited)", 503 | "$(PROJECT_DIR)/JKRecorderKit/Class/lame", 504 | ); 505 | PRODUCT_BUNDLE_IDENTIFIER = com.xiaoou.joanking.JKRecorderKit; 506 | PRODUCT_NAME = "$(TARGET_NAME)"; 507 | TARGETED_DEVICE_FAMILY = "1,2"; 508 | }; 509 | name = Debug; 510 | }; 511 | E285A8A2221D303400FA70DB /* Release */ = { 512 | isa = XCBuildConfiguration; 513 | buildSettings = { 514 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 515 | CODE_SIGN_STYLE = Automatic; 516 | DEVELOPMENT_TEAM = 75LW4CAG6Y; 517 | INFOPLIST_FILE = JKRecorderKit/Info.plist; 518 | LD_RUNPATH_SEARCH_PATHS = ( 519 | "$(inherited)", 520 | "@executable_path/Frameworks", 521 | ); 522 | LIBRARY_SEARCH_PATHS = ( 523 | "$(inherited)", 524 | "$(PROJECT_DIR)/JKRecorderKit/Class/lame", 525 | ); 526 | PRODUCT_BUNDLE_IDENTIFIER = com.xiaoou.joanking.JKRecorderKit; 527 | PRODUCT_NAME = "$(TARGET_NAME)"; 528 | TARGETED_DEVICE_FAMILY = "1,2"; 529 | }; 530 | name = Release; 531 | }; 532 | E285A8A4221D303400FA70DB /* Debug */ = { 533 | isa = XCBuildConfiguration; 534 | buildSettings = { 535 | BUNDLE_LOADER = "$(TEST_HOST)"; 536 | CODE_SIGN_STYLE = Automatic; 537 | DEVELOPMENT_TEAM = 75LW4CAG6Y; 538 | INFOPLIST_FILE = JKRecorderKitTests/Info.plist; 539 | LD_RUNPATH_SEARCH_PATHS = ( 540 | "$(inherited)", 541 | "@executable_path/Frameworks", 542 | "@loader_path/Frameworks", 543 | ); 544 | PRODUCT_BUNDLE_IDENTIFIER = com.xiaoou.joanking.JKRecorderKitTests; 545 | PRODUCT_NAME = "$(TARGET_NAME)"; 546 | TARGETED_DEVICE_FAMILY = "1,2"; 547 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/JKRecorderKit.app/JKRecorderKit"; 548 | }; 549 | name = Debug; 550 | }; 551 | E285A8A5221D303400FA70DB /* Release */ = { 552 | isa = XCBuildConfiguration; 553 | buildSettings = { 554 | BUNDLE_LOADER = "$(TEST_HOST)"; 555 | CODE_SIGN_STYLE = Automatic; 556 | DEVELOPMENT_TEAM = 75LW4CAG6Y; 557 | INFOPLIST_FILE = JKRecorderKitTests/Info.plist; 558 | LD_RUNPATH_SEARCH_PATHS = ( 559 | "$(inherited)", 560 | "@executable_path/Frameworks", 561 | "@loader_path/Frameworks", 562 | ); 563 | PRODUCT_BUNDLE_IDENTIFIER = com.xiaoou.joanking.JKRecorderKitTests; 564 | PRODUCT_NAME = "$(TARGET_NAME)"; 565 | TARGETED_DEVICE_FAMILY = "1,2"; 566 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/JKRecorderKit.app/JKRecorderKit"; 567 | }; 568 | name = Release; 569 | }; 570 | E285A8A7221D303400FA70DB /* Debug */ = { 571 | isa = XCBuildConfiguration; 572 | buildSettings = { 573 | CODE_SIGN_STYLE = Automatic; 574 | DEVELOPMENT_TEAM = 75LW4CAG6Y; 575 | INFOPLIST_FILE = JKRecorderKitUITests/Info.plist; 576 | LD_RUNPATH_SEARCH_PATHS = ( 577 | "$(inherited)", 578 | "@executable_path/Frameworks", 579 | "@loader_path/Frameworks", 580 | ); 581 | PRODUCT_BUNDLE_IDENTIFIER = com.xiaoou.joanking.JKRecorderKitUITests; 582 | PRODUCT_NAME = "$(TARGET_NAME)"; 583 | TARGETED_DEVICE_FAMILY = "1,2"; 584 | TEST_TARGET_NAME = JKRecorderKit; 585 | }; 586 | name = Debug; 587 | }; 588 | E285A8A8221D303400FA70DB /* Release */ = { 589 | isa = XCBuildConfiguration; 590 | buildSettings = { 591 | CODE_SIGN_STYLE = Automatic; 592 | DEVELOPMENT_TEAM = 75LW4CAG6Y; 593 | INFOPLIST_FILE = JKRecorderKitUITests/Info.plist; 594 | LD_RUNPATH_SEARCH_PATHS = ( 595 | "$(inherited)", 596 | "@executable_path/Frameworks", 597 | "@loader_path/Frameworks", 598 | ); 599 | PRODUCT_BUNDLE_IDENTIFIER = com.xiaoou.joanking.JKRecorderKitUITests; 600 | PRODUCT_NAME = "$(TARGET_NAME)"; 601 | TARGETED_DEVICE_FAMILY = "1,2"; 602 | TEST_TARGET_NAME = JKRecorderKit; 603 | }; 604 | name = Release; 605 | }; 606 | /* End XCBuildConfiguration section */ 607 | 608 | /* Begin XCConfigurationList section */ 609 | E285A86F221D303300FA70DB /* Build configuration list for PBXProject "JKRecorderKit" */ = { 610 | isa = XCConfigurationList; 611 | buildConfigurations = ( 612 | E285A89E221D303400FA70DB /* Debug */, 613 | E285A89F221D303400FA70DB /* Release */, 614 | ); 615 | defaultConfigurationIsVisible = 0; 616 | defaultConfigurationName = Release; 617 | }; 618 | E285A8A0221D303400FA70DB /* Build configuration list for PBXNativeTarget "JKRecorderKit" */ = { 619 | isa = XCConfigurationList; 620 | buildConfigurations = ( 621 | E285A8A1221D303400FA70DB /* Debug */, 622 | E285A8A2221D303400FA70DB /* Release */, 623 | ); 624 | defaultConfigurationIsVisible = 0; 625 | defaultConfigurationName = Release; 626 | }; 627 | E285A8A3221D303400FA70DB /* Build configuration list for PBXNativeTarget "JKRecorderKitTests" */ = { 628 | isa = XCConfigurationList; 629 | buildConfigurations = ( 630 | E285A8A4221D303400FA70DB /* Debug */, 631 | E285A8A5221D303400FA70DB /* Release */, 632 | ); 633 | defaultConfigurationIsVisible = 0; 634 | defaultConfigurationName = Release; 635 | }; 636 | E285A8A6221D303400FA70DB /* Build configuration list for PBXNativeTarget "JKRecorderKitUITests" */ = { 637 | isa = XCConfigurationList; 638 | buildConfigurations = ( 639 | E285A8A7221D303400FA70DB /* Debug */, 640 | E285A8A8221D303400FA70DB /* Release */, 641 | ); 642 | defaultConfigurationIsVisible = 0; 643 | defaultConfigurationName = Release; 644 | }; 645 | /* End XCConfigurationList section */ 646 | }; 647 | rootObject = E285A86C221D303300FA70DB /* Project object */; 648 | } 649 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/20. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/20. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Class/JKAudioFilePathTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // JKAudioFilePathTool.h 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/21. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface JKAudioFilePathTool : NSObject 14 | 15 | #pragma mark 1、判断文件或文件夹是否存在 16 | + (BOOL)jk_judgeFileOrFolderExists:(NSString *)filePathName; 17 | 18 | #pragma mark 2、判断文件是否存在 19 | /** 20 | 判断文件是否存在 21 | 22 | @param filePath 文件路径 23 | @return YES:存在 NO:不存在 24 | */ 25 | + (BOOL)jk_judgeFileExists:(NSString *)filePath; 26 | 27 | /** 28 | 类方法创建文件夹目录 29 | 30 | @param folderName 文件夹的名字 31 | @return 返回一个路径 32 | */ 33 | + (NSString *)jk_createFolder:(NSString *)folderName; 34 | 35 | @end 36 | 37 | NS_ASSUME_NONNULL_END 38 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Class/JKAudioFilePathTool.m: -------------------------------------------------------------------------------- 1 | // 2 | // JKAudioFilePathTool.m 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/21. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import "JKAudioFilePathTool.h" 10 | 11 | @implementation JKAudioFilePathTool 12 | 13 | #pragma mark 1、判断文件或文件夹是否存在 14 | + (BOOL)jk_judgeFileOrFolderExists:(NSString *)filePathName { 15 | 16 | // 长度等于0,直接返回不存在 17 | if (filePathName.length == 0) { 18 | return NO; 19 | } 20 | 21 | NSFileManager *fileManager = [NSFileManager defaultManager]; 22 | NSString *filePath = [NSString stringWithFormat:@"%@",filePathName]; 23 | BOOL isDir = NO; 24 | // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录 25 | BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir]; 26 | 27 | if ( !(isDir == YES && existed == YES) ) { 28 | 29 | // 不存在的路径才会创建 30 | return NO; 31 | }else{ 32 | 33 | return YES; 34 | } 35 | return nil; 36 | } 37 | 38 | + (BOOL)jk_judgeFileExists:(NSString *)filePath { 39 | 40 | // 长度等于0,直接返回不存在 41 | if (filePath.length == 0) { 42 | return NO; 43 | } 44 | 45 | NSFileManager *fileManager = [NSFileManager defaultManager]; 46 | NSString *path = [NSString stringWithFormat:@"%@",filePath]; 47 | BOOL isDir = NO; 48 | // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录 49 | BOOL existed = [fileManager fileExistsAtPath:path isDirectory:&isDir]; 50 | 51 | if (existed == YES) { 52 | 53 | return YES; 54 | }else{ 55 | // 不存在 56 | return NO; 57 | } 58 | return nil; 59 | } 60 | 61 | /**类方法创建文件夹目录 folderNmae:文件夹的名字*/ 62 | + (NSString *)jk_createFolder:(NSString *)folderName { 63 | 64 | // NSHomeDirectory():应用程序目录, Caches、Library、Documents目录文件夹下创建文件夹(蓝色的) 65 | // @"Documents/JKPdf" 66 | NSString *filePath = [NSString stringWithFormat:@"%@",folderName]; 67 | NSFileManager *fileManager = [NSFileManager defaultManager]; 68 | BOOL isDir = NO; 69 | // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录 70 | BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir]; 71 | 72 | if ( !(isDir == YES && existed == YES) ) { 73 | 74 | // 不存在的路径才会创建 75 | [fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil]; 76 | } 77 | return filePath; 78 | } 79 | 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Class/JKAudioFileTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // JKAudioFileTool.h 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/20. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface JKAudioFileTool : NSObject 14 | 15 | #pragma mark 音频的拼接:追加某个音频在某个音频的后面 16 | /// 音频的拼接 17 | /// @param fromPath 前段音频路径 18 | /// @param toPath 后段音频路径 19 | /// @param outputPath 拼接后的音频路径 20 | + (void)addAudio:(NSString *)fromPath toAudio:(NSString *)toPath outputPath:(NSString *)outputPath; 21 | 22 | #pragma mark 音频的剪切 23 | /// 音频的剪切 24 | /// @param audioPath 要剪切的音频路径 25 | /// @param fromTime 开始剪切的时间 26 | /// @param toTime 结束剪切的时间 27 | /// @param outputPath 剪切成功后的音频路径 28 | + (void)cutAudio:(NSString *)audioPath fromTime:(NSTimeInterval)fromTime toTime:(NSTimeInterval)toTime outputPath:(NSString *)outputPath; 29 | 30 | #pragma mark m4a格式转caf格式 31 | /// 把.m4a转为.caf格式 32 | /// @param originalUrlStr .m4a文件路径 33 | /// @param destUrlStr .caf文件路径 34 | /// @param completed 转化完成的block 35 | + (void)convetM4aToWav:(NSString *)originalUrlStr 36 | destUrl:(NSString *)destUrlStr 37 | completed:(void (^)(NSError *error)) completed; 38 | 39 | #pragma mark caf格式转m4a格式 40 | /// 把.caf转为.m4a格式 41 | /// @param cafUrlStr .m4a文件路径 42 | /// @param m4aUrlStr .caf文件路径 43 | /// @param completed 转化完成的block 44 | + (void)convetCafToM4a:(NSString *)cafUrlStr 45 | destUrl:(NSString *)m4aUrlStr 46 | completed:(void (^)(NSError *error)) completed; 47 | 48 | @end 49 | 50 | NS_ASSUME_NONNULL_END 51 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Class/JKAudioFileTool.m: -------------------------------------------------------------------------------- 1 | // 2 | // JKAudioFileTool.m 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/20. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import "JKAudioFileTool.h" 10 | #import 11 | @implementation JKAudioFileTool 12 | 13 | #pragma mark 音频的拼接:追加某个音频在某个音频的后面 14 | /// 音频的拼接 15 | /// @param fromPath 前段音频路径 16 | /// @param toPath 后段音频路径 17 | /// @param outputPath 拼接后的音频路径 18 | + (void)addAudio:(NSString *)fromPath toAudio:(NSString *)toPath outputPath:(NSString *)outputPath { 19 | 20 | // 1. 获取两个音频源 21 | AVURLAsset *audioAsset1 = [AVURLAsset assetWithURL:[NSURL fileURLWithPath:fromPath]]; 22 | AVURLAsset *audioAsset2 = [AVURLAsset assetWithURL:[NSURL fileURLWithPath:toPath]]; 23 | 24 | // 2. 获取两个音频素材中的素材轨道 25 | AVAssetTrack *audioAssetTrack1 = [[audioAsset1 tracksWithMediaType:AVMediaTypeAudio] firstObject]; 26 | AVAssetTrack *audioAssetTrack2 = [[audioAsset2 tracksWithMediaType:AVMediaTypeAudio] firstObject]; 27 | 28 | // 3. 向音频合成器, 添加一个空的素材容器 29 | AVMutableComposition *composition = [AVMutableComposition composition]; 30 | AVMutableCompositionTrack *audioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:0]; 31 | 32 | // 4. 向素材容器中, 插入音轨素材 33 | [audioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset2.duration) ofTrack:audioAssetTrack2 atTime:kCMTimeZero error:nil]; 34 | [audioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset1.duration) ofTrack:audioAssetTrack1 atTime:audioAsset2.duration error:nil]; 35 | 36 | // 5. 根据合成器, 创建一个导出对象, 并设置导出参数 37 | AVAssetExportSession *session = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetAppleM4A]; 38 | session.outputURL = [NSURL fileURLWithPath:outputPath]; 39 | session.outputFileType = AVFileTypeMPEGLayer3; 40 | 41 | // 6. 开始导出数据 42 | __weak typeof(self) weakSelf = self; 43 | [session exportAsynchronouslyWithCompletionHandler:^{ 44 | 45 | AVAssetExportSessionStatus status = session.status; 46 | 47 | NSString *statusStr = [weakSelf outputStatus:status]; 48 | 49 | NSLog(@"%@",statusStr); 50 | 51 | }]; 52 | 53 | } 54 | 55 | #pragma mark 音频的剪切 56 | /// 音频的剪切 57 | /// @param audioPath 要剪切的音频路径 58 | /// @param fromTime 开始剪切的时间 59 | /// @param toTime 结束剪切的时间 60 | /// @param outputPath 剪切成功后的音频路径 61 | + (void)cutAudio:(NSString *)audioPath fromTime:(NSTimeInterval)fromTime toTime:(NSTimeInterval)toTime outputPath:(NSString *)outputPath { 62 | 63 | // 1. 获取音频源 64 | AVURLAsset *asset = [AVURLAsset assetWithURL:[NSURL fileURLWithPath:audioPath]]; 65 | 66 | // 2. 创建一个音频会话, 并且,设置相应的配置 67 | AVAssetExportSession *session = [AVAssetExportSession exportSessionWithAsset:asset presetName:AVAssetExportPresetAppleM4A]; 68 | // AVFileTypeAppleM4A : 导出 69 | session.outputFileType = AVFileTypeAppleM4A; 70 | session.outputURL = [NSURL fileURLWithPath:outputPath]; 71 | CMTime startTime = CMTimeMake(fromTime, 1); 72 | CMTime endTime = CMTimeMake(toTime, 1); 73 | session.timeRange = CMTimeRangeFromTimeToTime(startTime, endTime); 74 | // 3. 导出 75 | __weak typeof(self) weakSelf = self; 76 | [session exportAsynchronouslyWithCompletionHandler:^{ 77 | 78 | AVAssetExportSessionStatus status = session.status; 79 | 80 | NSString *statusStr = [weakSelf outputStatus:status]; 81 | 82 | NSLog(@"%@",statusStr); 83 | 84 | }]; 85 | } 86 | 87 | + (NSString *)outputStatus:(AVAssetExportSessionStatus)status { 88 | 89 | /** 90 | AVAssetExportSessionStatusUnknown, 91 | AVAssetExportSessionStatusWaiting, 92 | AVAssetExportSessionStatusExporting, 93 | AVAssetExportSessionStatusCompleted, 94 | AVAssetExportSessionStatusFailed, 95 | AVAssetExportSessionStatusCancelled 96 | */ 97 | NSString *statusStr = @""; 98 | switch (status) { 99 | case AVAssetExportSessionStatusUnknown: 100 | // NSLog(@"未知状态"); 101 | statusStr = @"未知状态"; 102 | break; 103 | case AVAssetExportSessionStatusWaiting: 104 | NSLog(@"等待导出"); 105 | statusStr = @"等待导出"; 106 | break; 107 | case AVAssetExportSessionStatusExporting: 108 | NSLog(@"导出中"); 109 | break; 110 | case AVAssetExportSessionStatusCompleted:{ 111 | 112 | // NSLog(@"导出成功,路径是:%@", outputPath); 113 | statusStr = @"导出成功"; 114 | } 115 | break; 116 | case AVAssetExportSessionStatusFailed: 117 | 118 | NSLog(@"导出失败"); 119 | statusStr = @"导出失败"; 120 | break; 121 | case AVAssetExportSessionStatusCancelled: 122 | NSLog(@"取消导出"); 123 | statusStr = @"取消导出"; 124 | break; 125 | default: 126 | break; 127 | } 128 | 129 | return statusStr; 130 | 131 | } 132 | 133 | #pragma mark m4a格式转caf格式 134 | /// 把.m4a转为.caf格式 135 | /// @param originalUrlStr .m4a文件路径 136 | /// @param destUrlStr .caf文件路径 137 | /// @param completed 转化完成的block 138 | + (void)convetM4aToWav:(NSString *)originalUrlStr 139 | destUrl:(NSString *)destUrlStr 140 | completed:(void (^)(NSError *error)) completed { 141 | 142 | if ([[NSFileManager defaultManager] fileExistsAtPath:destUrlStr]) { 143 | [[NSFileManager defaultManager] removeItemAtPath:destUrlStr error:nil]; 144 | } 145 | NSURL *originalUrl = [NSURL fileURLWithPath:originalUrlStr]; 146 | NSURL *destUrl = [NSURL fileURLWithPath:destUrlStr]; 147 | AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:originalUrl options:nil]; 148 | 149 | //读取原始文件信息 150 | NSError *error = nil; 151 | AVAssetReader *assetReader = [AVAssetReader assetReaderWithAsset:songAsset error:&error]; 152 | if (error) { 153 | NSLog (@"error: %@", error); 154 | completed(error); 155 | return; 156 | } 157 | AVAssetReaderOutput *assetReaderOutput = [AVAssetReaderAudioMixOutput 158 | assetReaderAudioMixOutputWithAudioTracks:songAsset.tracks 159 | audioSettings: nil]; 160 | if (![assetReader canAddOutput:assetReaderOutput]) { 161 | NSLog (@"can't add reader output... die!"); 162 | completed(error); 163 | return; 164 | } 165 | [assetReader addOutput:assetReaderOutput]; 166 | 167 | AVAssetWriter *assetWriter = [AVAssetWriter assetWriterWithURL:destUrl 168 | fileType:AVFileTypeCoreAudioFormat 169 | error:&error]; 170 | if (error) { 171 | NSLog (@"error: %@", error); 172 | completed(error); 173 | return; 174 | } 175 | AudioChannelLayout channelLayout; 176 | memset(&channelLayout, 0, sizeof(AudioChannelLayout)); 177 | channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo; 178 | NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys: 179 | [NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey, 180 | [NSNumber numberWithFloat:44100], AVSampleRateKey, 181 | [NSNumber numberWithInt:2], AVNumberOfChannelsKey, 182 | [NSNumber numberWithInt:16], AVLinearPCMBitDepthKey, 183 | [NSNumber numberWithBool:NO], AVLinearPCMIsNonInterleaved, 184 | [NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey, 185 | [NSNumber numberWithBool:NO], AVLinearPCMIsBigEndianKey, 186 | nil]; 187 | AVAssetWriterInput *assetWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio 188 | outputSettings:outputSettings]; 189 | if ([assetWriter canAddInput:assetWriterInput]) { 190 | [assetWriter addInput:assetWriterInput]; 191 | } else { 192 | NSLog (@"can't add asset writer input... die!"); 193 | completed(error); 194 | return; 195 | } 196 | 197 | assetWriterInput.expectsMediaDataInRealTime = NO; 198 | 199 | [assetWriter startWriting]; 200 | [assetReader startReading]; 201 | 202 | AVAssetTrack *soundTrack = [songAsset.tracks objectAtIndex:0]; 203 | CMTime startTime = CMTimeMake (0, soundTrack.naturalTimeScale); 204 | [assetWriter startSessionAtSourceTime:startTime]; 205 | 206 | __block UInt64 convertedByteCount = 0; 207 | 208 | dispatch_queue_t mediaInputQueue = dispatch_queue_create("mediaInputQueue", NULL); 209 | [assetWriterInput requestMediaDataWhenReadyOnQueue:mediaInputQueue 210 | usingBlock: ^ 211 | { 212 | while (assetWriterInput.readyForMoreMediaData) { 213 | CMSampleBufferRef nextBuffer = [assetReaderOutput copyNextSampleBuffer]; 214 | if (nextBuffer) { 215 | // append buffer 216 | [assetWriterInput appendSampleBuffer: nextBuffer]; 217 | NSLog (@"appended a buffer (%zu bytes)", 218 | CMSampleBufferGetTotalSampleSize (nextBuffer)); 219 | convertedByteCount += CMSampleBufferGetTotalSampleSize (nextBuffer); 220 | 221 | 222 | } else { 223 | [assetWriterInput markAsFinished]; 224 | [assetWriter finishWritingWithCompletionHandler:^{ 225 | 226 | }]; 227 | [assetReader cancelReading]; 228 | NSDictionary *outputFileAttributes = [[NSFileManager defaultManager] 229 | attributesOfItemAtPath:[destUrl path] 230 | error:nil]; 231 | NSLog (@"FlyElephant %lld",[outputFileAttributes fileSize]); 232 | break; 233 | } 234 | } 235 | NSLog(@"转换结束"); 236 | // 删除临时temprecordAudio.m4a文件 237 | NSError *removeError = nil; 238 | if ([[NSFileManager defaultManager] fileExistsAtPath:originalUrlStr]) { 239 | BOOL success = [[NSFileManager defaultManager] removeItemAtPath:originalUrlStr error:&removeError]; 240 | if (!success) { 241 | NSLog(@"删除临时temprecordAudio.m4a文件失败:%@",removeError); 242 | completed(removeError); 243 | }else{ 244 | NSLog(@"删除临时temprecordAudio.m4a文件:%@成功",originalUrlStr); 245 | completed(removeError); 246 | } 247 | } 248 | 249 | }]; 250 | } 251 | 252 | #pragma mark caf格式转m4a格式 253 | /// 把.caf转为.m4a格式 254 | /// @param cafUrlStr .m4a文件路径 255 | /// @param m4aUrlStr .caf文件路径 256 | /// @param completed 转化完成的block 257 | + (void)convetCafToM4a:(NSString *)cafUrlStr 258 | destUrl:(NSString *)m4aUrlStr 259 | completed:(void (^)(NSError *error)) completed { 260 | 261 | AVMutableComposition* mixComposition = [AVMutableComposition composition]; 262 | // 音频插入的开始时间 263 | CMTime beginTime = kCMTimeZero; 264 | // 获取音频合并音轨 265 | AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; 266 | // 用于记录错误的对象 267 | NSError *error = nil; 268 | // 音频原文件资源 269 | AVURLAsset *cafAsset = [[AVURLAsset alloc]initWithURL:[NSURL fileURLWithPath:cafUrlStr] options:nil]; 270 | // 原音频需要合并的音频文件的区间 271 | CMTimeRange audio_timeRange = CMTimeRangeMake(kCMTimeZero, cafAsset.duration); 272 | BOOL success = [compositionAudioTrack insertTimeRange:audio_timeRange ofTrack:[[cafAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:beginTime error:&error]; 273 | if (!success) { 274 | NSLog(@"插入原音频失败: %@",error); 275 | }else { 276 | NSLog(@"插入原音频成功"); 277 | } 278 | // 创建一个导入M4A格式的音频的导出对象 279 | AVAssetExportSession* assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetAppleM4A]; 280 | // 导入音视频的URL 281 | assetExport.outputURL = [NSURL fileURLWithPath:m4aUrlStr]; 282 | // 导出音视频的文件格式 283 | assetExport.outputFileType = @"com.apple.m4a-audio"; 284 | [assetExport exportAsynchronouslyWithCompletionHandler:^{ 285 | // 分发到主线程 286 | dispatch_async(dispatch_get_main_queue(), ^{ 287 | int exportStatus = assetExport.status; 288 | if (exportStatus == AVAssetExportSessionStatusCompleted) { 289 | // 合成成功 290 | completed(nil); 291 | NSError *removeError = nil; 292 | if([cafUrlStr hasSuffix:@"caf"]) { 293 | // 删除老录音caf文件 294 | if ([[NSFileManager defaultManager] fileExistsAtPath:cafUrlStr]) { 295 | BOOL success = [[NSFileManager defaultManager] removeItemAtPath:cafUrlStr error:&removeError]; 296 | if (!success) { 297 | NSLog(@"删除老录音caf文件失败:%@",removeError); 298 | }else{ 299 | NSLog(@"删除老录音caf文件:%@成功",cafUrlStr); 300 | } 301 | } 302 | } 303 | 304 | }else { 305 | completed(assetExport.error); 306 | } 307 | 308 | }); 309 | }]; 310 | } 311 | 312 | 313 | 314 | @end 315 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Class/JKAudioPlayerTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // JKAudioPlayerTool.h 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/20. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "JKSingle.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | @interface JKAudioPlayerTool : NSObject 16 | 17 | jkSingleH(JKAudioPlayerTool) 18 | 19 | /// 播放歌曲 20 | /// @param audioPath 音频路径 21 | - (AVAudioPlayer *)playAudioWith:(NSString *)audioPath; 22 | 23 | /// 恢复当前歌曲播放 24 | - (void)resumeCurrentAudio; 25 | 26 | /// 暂停歌曲 27 | - (void)pauseCurrentAudio; 28 | 29 | /// 停止歌曲播放 30 | - (void)stopCurrentAudio; 31 | 32 | /// 音量大小,范围0-1.0 33 | @property (nonatomic, assign) float volumn; 34 | 35 | /// 播放进度大小 36 | @property (nonatomic, assign, readonly) float progress; 37 | 38 | /// 是否允许改变播放速率 39 | @property (nonatomic, assign) BOOL enableRate; 40 | 41 | /// 播放速率,范围0.5-2.0,如果为1.0则正常播放,如果要修改播放速率则必须设置enableRate为YES 42 | @property (nonatomic, assign) float rate; 43 | 44 | /// 立体声平衡,如果为-1.0则完全左声道,如果0.0则左右声道平衡,如果为1.0则完全为右声道 45 | @property (nonatomic, assign) float span; 46 | 47 | /// 循环播放次数,如果为0则不循环,如果小于0则无限循环,大于0则表示循环次数 48 | @property (nonatomic, assign) NSInteger numberOfLoops; 49 | 50 | @end 51 | 52 | NS_ASSUME_NONNULL_END 53 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Class/JKAudioPlayerTool.m: -------------------------------------------------------------------------------- 1 | // 2 | // JKAudioPlayerTool.m 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/20. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import "JKAudioPlayerTool.h" 10 | 11 | @interface JKAudioPlayerTool() 12 | 13 | /** 音乐播放器 */ 14 | @property (nonatomic ,strong) AVAudioPlayer *player; 15 | 16 | @end 17 | 18 | @implementation JKAudioPlayerTool 19 | 20 | jkSingleM(JKAudioPlayerTool) 21 | 22 | /** 播放歌曲 */ 23 | - (AVAudioPlayer *)playAudioWith:(NSString *)audioPath { 24 | NSURL *url = [NSURL URLWithString:audioPath]; 25 | if (url == nil) { 26 | url = [[NSBundle mainBundle] URLForResource:audioPath.lastPathComponent withExtension:nil]; 27 | } 28 | /** 29 | 使用文件URL初始化播放器,注意这个URL不能是HTTP URL,AVAudioPlayer不支持加载网络媒体流,只能播放本地文件 30 | */ 31 | self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; 32 | self.player.delegate = self; 33 | /** 34 | 加载音频文件到缓冲区,注意即使在播放之前音频文件没有加载到缓冲区程序也会隐式调用此方法。 35 | */ 36 | [self.player prepareToPlay]; 37 | /** 38 | 播放音频文件 39 | */ 40 | [self.player play]; 41 | return self.player; 42 | } 43 | 44 | /** 恢复当前歌曲 */ 45 | - (void)resumeCurrentAudio { 46 | [self.player play]; 47 | } 48 | 49 | /** 暂停歌曲 */ 50 | - (void)pauseCurrentAudio { 51 | [self.player pause]; 52 | } 53 | 54 | /** 停止歌曲 */ 55 | - (void)stopCurrentAudio { 56 | [self.player stop]; 57 | } 58 | 59 | - (void)setVolumn:(float)volumn { 60 | self.player.volume = volumn; 61 | } 62 | 63 | - (float)volumn { 64 | return self.player.volume; 65 | } 66 | 67 | - (float)progress { 68 | return self.player.currentTime / self.player.duration; 69 | } 70 | 71 | 72 | - (void)setEnableRate:(BOOL)enableRate { 73 | [self.player setEnableRate:enableRate]; 74 | } 75 | 76 | - (BOOL)enableRate { 77 | return self.enableRate; 78 | } 79 | 80 | - (void)setRate:(float)rate { 81 | [self.player setRate:rate]; 82 | } 83 | 84 | - (float)rate { 85 | return self.rate; 86 | } 87 | 88 | - (void)setSpan:(float)span { 89 | [self.player setPan:span]; 90 | } 91 | 92 | - (float)span { 93 | return self.span; 94 | } 95 | 96 | - (void)setNumberOfLoops:(NSInteger)numberOfLoops { 97 | [self.player setNumberOfLoops:numberOfLoops]; 98 | } 99 | 100 | - (NSInteger)numberOfLoops { 101 | return self.numberOfLoops; 102 | } 103 | 104 | #pragma mark --- AVAudioPlayerDelegate----- 105 | 106 | #pragma mark 音频播放完成 107 | - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag { 108 | NSLog(@"音频播放完成"); 109 | } 110 | 111 | #pragma mark 音频解码发生错误 112 | - (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error { 113 | NSLog(@"音频解码发生错误"); 114 | } 115 | 116 | @end 117 | 118 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Class/JKAudioTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // JKAudioTool.h 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/20. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import 10 | // 单利的类 11 | #import "JKSingle.h" 12 | #import 13 | 14 | NS_ASSUME_NONNULL_BEGIN 15 | 16 | // 录音存放的文件夹 /Library/Caches/JKRecorder 17 | #define cachesRecorderPath [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Caches/JKRecorder"] 18 | 19 | typedef void(^AudioSuccess)(BOOL ret); 20 | 21 | @interface JKAudioTool : NSObject 22 | 23 | jkSingleH(JKAudioTool) 24 | 25 | /** 录音文件路径 */ 26 | @property (nonatomic, copy, readonly) NSString *recordPath; 27 | 28 | /** 当前录音的时间 */ 29 | @property(nonatomic,assign) NSTimeInterval audioCurrentTime; 30 | 31 | #pragma mark 开始录音 32 | /// 开始录音 33 | /// @param recordName 录音的名字 34 | /// @param type 类型 35 | /// @param isConventToMp3 是否转MP3 36 | - (void)beginRecordWithRecordName:(NSString *)recordName withRecordType:(NSString *)type withIsConventToMp3:(BOOL)isConventToMp3; 37 | 38 | #pragma mark 结束录音 39 | /** 结束录音 */ 40 | - (void)endRecord; 41 | 42 | #pragma mark 暂停录音 43 | /** 暂停录音 */ 44 | - (void)pauseRecord; 45 | 46 | #pragma mark 删除录音 47 | /** 删除录音 */ 48 | - (void)deleteRecord; 49 | 50 | #pragma mark 重新录音 51 | /** 重新录音 */ 52 | - (void)reRecord; 53 | 54 | #pragma mark 更新音频测量值 55 | /** 56 | 更新音频测量值,注意如果要更新音频测量值必须设置meteringEnabled为YES,通过音频测量值可以即时获得音频分贝等信息 57 | @property(getter=isMeteringEnabled) BOOL meteringEnabled:是否启用音频测量,默认为NO,一旦启用音频测量可以通过updateMeters方法更新测量值 58 | */ 59 | - (void)updateMeters; 60 | 61 | #pragma mark 获得指定声道的分贝峰值 62 | /** 63 | 获得指定声道的分贝峰值 64 | 获得指定声道的分贝峰值,注意如果要获得分贝峰值必须在此之前调用updateMeters方法 65 | @return 指定频道的值 66 | */ 67 | - (float)peakPowerForChannel0; 68 | 69 | @end 70 | 71 | NS_ASSUME_NONNULL_END 72 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Class/JKAudioTool.m: -------------------------------------------------------------------------------- 1 | // 2 | // JKAudioTool.m 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/20. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import "JKAudioTool.h" 10 | #import "JKAudioFilePathTool.h" 11 | #import "JKLameTool.h" 12 | @interface JKAudioTool() 13 | 14 | /// 录音对象 15 | @property (nonatomic, strong) AVAudioRecorder *audioRecorder; 16 | /// 录音成功的block 17 | @property (nonatomic, copy) AudioSuccess block; 18 | /// 录音文件的名字 19 | @property (nonatomic, strong) NSString *audioFileName; 20 | /// 录音的类型 21 | @property (nonatomic, strong) NSString *recordType; 22 | /// 是否边录边转mp3 23 | @property (nonatomic, assign) BOOL isConventMp3; 24 | 25 | @end 26 | 27 | @implementation JKAudioTool 28 | 29 | jkSingleM(JKAudioTool) 30 | 31 | -(AVAudioRecorder *)audioRecorder { 32 | __weak typeof(self) weakSelf = self; 33 | if (!_audioRecorder) { 34 | 35 | // 0. 设置录音会话 36 | /** 37 | AVAudioSessionCategoryPlayAndRecord: 可以边播放边录音(也就是平时看到的背景音乐) 38 | */ 39 | [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; 40 | // 启动会话 41 | [[AVAudioSession sharedInstance] setActive:YES error:nil]; 42 | 43 | // 1. 确定录音存放的位置 44 | NSURL *url = [NSURL URLWithString:weakSelf.recordPath]; 45 | 46 | // 2. 设置录音参数 47 | NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] init]; 48 | // 设置编码格式 49 | /** 50 | kAudioFormatLinearPCM: 无损压缩,内容非常大 51 | kAudioFormatMPEG4AAC 52 | */ 53 | [recordSettings setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey: AVFormatIDKey]; 54 | // 采样率:必须保证和转码设置的相同 55 | [recordSettings setValue :[NSNumber numberWithFloat:11025.0] forKey: AVSampleRateKey]; 56 | // 通道数(必须设置为双声道, 不然转码生成的 MP3 会声音尖锐变声.) 57 | [recordSettings setValue :[NSNumber numberWithInt:2] forKey: AVNumberOfChannelsKey]; 58 | 59 | //音频质量,采样质量(音频质量越高,文件的大小也就越大) 60 | [recordSettings setValue:[NSNumber numberWithInt:AVAudioQualityMin] forKey:AVEncoderAudioQualityKey]; 61 | 62 | // 3. 创建录音对象 63 | NSError *error ; 64 | _audioRecorder = [[AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error]; 65 | //开启音量监测 66 | _audioRecorder.meteringEnabled = YES; 67 | 68 | _audioRecorder.delegate = weakSelf; 69 | 70 | if(error){ 71 | NSLog(@"创建录音对象时发生错误,错误信息:%@",error.localizedDescription); 72 | } 73 | } 74 | return _audioRecorder; 75 | } 76 | 77 | 78 | /// 开始录音 79 | /// @param recordName 录制的名字 80 | /// @param type 类型 81 | /// @param isConventToMp3 是否转 MP3 82 | - (void)beginRecordWithRecordName: (NSString *)recordName withRecordType:(NSString *)type withIsConventToMp3:(BOOL)isConventToMp3 { 83 | // 正在录制就返回,防止多次点击录音 84 | _recordType = type; 85 | _isConventMp3 = isConventToMp3; 86 | 87 | if ([recordName containsString:[NSString stringWithFormat:@".%@",_recordType]]) { 88 | 89 | _audioFileName = recordName; 90 | }else{ 91 | 92 | _audioFileName = [NSString stringWithFormat:@"%@.%@", recordName, _recordType]; 93 | } 94 | 95 | if (![JKAudioFilePathTool jk_judgeFileOrFolderExists: cachesRecorderPath]) { 96 | // 创建 /Library/Caches/JKRecorder 文件夹 97 | [JKAudioFilePathTool jk_createFolder: cachesRecorderPath]; 98 | } 99 | 100 | // 创建录音文件存放路径 101 | _recordPath = [cachesRecorderPath stringByAppendingPathComponent: _audioFileName]; 102 | 103 | // 准备录音 104 | if ([self.audioRecorder prepareToRecord]) { 105 | // 开始录音 106 | [self.audioRecorder record]; 107 | // 判断是否需要边录边转 MP3 108 | if (isConventToMp3) { 109 | [[JKLameTool shareJKLameTool] audioRecodingToMP3: _recordPath isDeleteSourchFile:YES withSuccessBack:^(NSString * _Nonnull resultPath) { 110 | 111 | } withFailBack:^(NSString * _Nonnull error) { 112 | 113 | }]; 114 | } 115 | } 116 | } 117 | 118 | /// 结束录音 119 | - (void)endRecord { 120 | [self.audioRecorder stop]; 121 | } 122 | 123 | /// 暂停录音 124 | - (void)pauseRecord { 125 | [self.audioRecorder pause]; 126 | } 127 | 128 | /// 删除录音 129 | - (void)deleteRecord { 130 | [self.audioRecorder stop]; 131 | // 删除录音之前必须先停止录音 132 | [self.audioRecorder deleteRecording]; 133 | } 134 | 135 | /// 重新录音 136 | - (void)reRecord { 137 | 138 | self.audioRecorder = nil; 139 | [self beginRecordWithRecordName:self.audioFileName withRecordType:self.recordType withIsConventToMp3:self.isConventMp3]; 140 | } 141 | 142 | /// 更新音频测量值,注意如果要更新音频测量值必须设置meteringEnabled为YES,通过音频测量值可以即时获得音频分贝等信息 143 | - (void)updateMeters { 144 | [self.audioRecorder updateMeters]; 145 | } 146 | 147 | /** 148 | 获得指定声道的分贝峰值 149 | 获得指定声道的分贝峰值,注意如果要获得分贝峰值必须在此之前调用updateMeters方法 150 | @return 指定频道的值 151 | */ 152 | - (float)peakPowerForChannel0 { 153 | [self.audioRecorder updateMeters]; 154 | return [self.audioRecorder peakPowerForChannel:0]; 155 | } 156 | 157 | /// 当前录音的时间 158 | - (NSTimeInterval)audioCurrentTime{ 159 | 160 | return self.audioRecorder.currentTime; 161 | } 162 | 163 | /* audioRecorderDidFinishRecording:successfully: is called when a recording has been finished or stopped. This method is NOT called if the recorder is stopped due to an interruption. */ 164 | - (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag { 165 | if (flag) { 166 | NSLog(@"----- 录音 完毕"); 167 | 168 | if (self.isConventMp3) { 169 | [[JKLameTool shareJKLameTool] sendEndRecord]; 170 | } 171 | } 172 | } 173 | 174 | @end 175 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Class/JKRecorderKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // JKRecorderKit.h 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/20. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #ifndef JKRecorderKit_h 10 | #define JKRecorderKit_h 11 | 12 | // 单利的类 13 | #import "JKSingle.h" 14 | // 音频录制的类 15 | #import "JKAudioTool.h" 16 | // 音频播放的类 17 | #import "JKAudioPlayerTool.h" 18 | // 操作音频文件 拼接、剪切的 类 19 | #import "JKAudioFileTool.h" 20 | // lame 静态库的 .h 文件 21 | #import "lame.h" 22 | // 音频录制 lame 使用的类 23 | #import "JKLameTool.h" 24 | // 音频路径操作的类 25 | #import "JKAudioFilePathTool.h" 26 | // 系统的音频框架 27 | #import 28 | 29 | #endif /* JKRecorderKit_h */ 30 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Class/JKSingle.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #define jkSingleH(name) +(instancetype)share##name; 4 | 5 | #define jkSingleM(name) \ 6 | static id instanceMessages;\ 7 | +(instancetype)allocWithZone:(struct _NSZone *)zone\ 8 | {\ 9 | \ 10 | static dispatch_once_t onceToken;\ 11 | \ 12 | dispatch_once(&onceToken, ^{\ 13 | \ 14 | instanceMessages = [super allocWithZone:zone];\ 15 | \ 16 | });\ 17 | \ 18 | return instanceMessages;\ 19 | }\ 20 | -(id)copy\ 21 | {\ 22 | return instanceMessages;\ 23 | }\ 24 | +(instancetype)share##name\ 25 | {\ 26 | \ 27 | static dispatch_once_t onceToken;\ 28 | \ 29 | dispatch_once(&onceToken, ^{\ 30 | \ 31 | instanceMessages = [[self alloc]init];\ 32 | \ 33 | });\ 34 | \ 35 | return instanceMessages;\ 36 | } 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Class/lame/JKLameTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // JKLameTool.h 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/21. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "JKSingle.h" 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface JKLameTool : NSObject 14 | 15 | jkSingleH(JKLameTool) 16 | 17 | #pragma mark caf 转 mp3 : 录音完成后根据用户需要去调用 18 | /** 19 | caf 转 mp3 20 | 21 | @param sourcePath 转 mp3 的caf 路径 22 | @param isDelete 是否删除原来的 caf 文件,YES:删除、NO:不删除 23 | @param success 成功的回调 24 | @param fail 失败的回调 25 | */ 26 | + (void)audioToMP3:(NSString *)sourcePath isDeleteSourchFile: (BOOL)isDelete withSuccessBack:(void(^)(NSString *resultPath))success withFailBack:(void(^)(NSString *error))fail; 27 | 28 | #pragma mark caf 转 mp3 : 录音的同时转码 29 | /** 30 | caf 转 mp3 : 录音的同时转码 31 | 32 | @param sourcePath 转 mp3 的caf 路径 33 | @param isDelete 是否删除原来的 caf 文件,YES:删除、NO:不删除 34 | @param success 成功的回调 35 | @param fail 失败的回调 36 | */ 37 | -(void)audioRecodingToMP3:(NSString *)sourcePath isDeleteSourchFile: (BOOL)isDelete withSuccessBack:(void(^)(NSString *resultPath))success withFailBack:(void(^)(NSString *error))fail; 38 | 39 | #pragma mark 录音完成的调用 40 | /** 41 | 录音完成的调用 42 | */ 43 | - (void)sendEndRecord; 44 | 45 | @end 46 | 47 | NS_ASSUME_NONNULL_END 48 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Class/lame/JKLameTool.m: -------------------------------------------------------------------------------- 1 | // 2 | // JKLameTool.m 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/21. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import "JKLameTool.h" 10 | #import "lame.h" 11 | 12 | @interface JKLameTool() 13 | 14 | @property (nonatomic, assign) BOOL stopRecord; 15 | 16 | @end 17 | 18 | @implementation JKLameTool 19 | 20 | jkSingleM(JKLameTool) 21 | 22 | /** 23 | caf 转 mp3 24 | 如果录音时间比较长的话,会要等待几秒... 25 | @param sourcePath 转 mp3 的caf 路径 26 | @param isDelete 是否删除原来的 caf 文件,YES:删除、NO:不删除 27 | @param success 成功的回调 28 | @param fail 失败的回调 29 | */ 30 | + (void)audioToMP3:(NSString *)sourcePath isDeleteSourchFile: (BOOL)isDelete withSuccessBack:(void(^)(NSString *resultPath))success withFailBack:(void(^)(NSString *error))fail{ 31 | 32 | dispatch_async(dispatch_get_global_queue(0, 0), ^{ 33 | 34 | // 输入路径 35 | NSString *inPath = sourcePath; 36 | 37 | // 判断输入路径是否存在 38 | NSFileManager *fm = [NSFileManager defaultManager]; 39 | if (![fm fileExistsAtPath:sourcePath]) 40 | { 41 | if (fail) { 42 | fail(@"文件不存在"); 43 | } 44 | return; 45 | } 46 | 47 | // 输出路径 48 | NSString *outPath = [[sourcePath stringByDeletingPathExtension] stringByAppendingString:@".mp3"]; 49 | 50 | @try { 51 | int read, write; 52 | 53 | FILE *pcm = fopen([inPath cStringUsingEncoding:1], "rb"); //source 被转换的音频文件位置 54 | fseek(pcm, 4*1024, SEEK_CUR); //skip file header 55 | FILE *mp3 = fopen([outPath cStringUsingEncoding:1], "wb"); //output 输出生成的Mp3文件位置 56 | 57 | const int PCM_SIZE = 8192; 58 | const int MP3_SIZE = 8192; 59 | short int pcm_buffer[PCM_SIZE*2]; 60 | unsigned char mp3_buffer[MP3_SIZE]; 61 | 62 | lame_t lame = lame_init(); 63 | lame_set_in_samplerate(lame, 11025.0); 64 | lame_set_VBR(lame, vbr_default); 65 | lame_init_params(lame); 66 | 67 | do { 68 | size_t size = (size_t)(2 * sizeof(short int)); 69 | read = (int)fread(pcm_buffer, size, PCM_SIZE, pcm); 70 | if (read == 0) 71 | write = lame_encode_flush(lame, mp3_buffer, MP3_SIZE); 72 | else 73 | write = lame_encode_buffer_interleaved(lame, pcm_buffer, read, mp3_buffer, MP3_SIZE); 74 | 75 | fwrite(mp3_buffer, write, 1, mp3); 76 | 77 | } while (read != 0); 78 | 79 | lame_close(lame); 80 | fclose(mp3); 81 | fclose(pcm); 82 | } 83 | 84 | @catch (NSException *exception) { 85 | NSLog(@"%@",[exception description]); 86 | } 87 | 88 | @finally { 89 | 90 | if (isDelete) { 91 | 92 | NSError *error; 93 | [fm removeItemAtPath:sourcePath error:&error]; 94 | if (error == nil) 95 | { 96 | // NSLog(@"删除源文件成功"); 97 | } 98 | } 99 | 100 | if (success) { 101 | success(outPath); 102 | } 103 | } 104 | 105 | }); 106 | 107 | } 108 | 109 | #pragma mark caf 转 mp3 : 录音的同时转码 110 | /** 111 | caf 转 mp3 : 录音的同时转码 112 | 113 | @param sourcePath 转 mp3 的caf 路径 114 | @param isDelete 是否删除原来的 caf 文件,YES:删除、NO:不删除 115 | @param success 成功的回调 116 | @param fail 失败的回调 117 | */ 118 | -(void)audioRecodingToMP3:(NSString *)sourcePath isDeleteSourchFile: (BOOL)isDelete withSuccessBack:(void(^)(NSString *resultPath))success withFailBack:(void(^)(NSString *error))fail{ 119 | 120 | NSLog(@"convert begin!!"); 121 | 122 | // 输入路径 123 | NSString *inPath = sourcePath; 124 | 125 | // 判断输入路径是否存在 126 | NSFileManager *fm = [NSFileManager defaultManager]; 127 | if (![fm fileExistsAtPath:sourcePath]) 128 | { 129 | if (fail) { 130 | fail(@"文件不存在"); 131 | } 132 | return; 133 | } 134 | 135 | // 输出路径 136 | NSString *outPath = [[sourcePath stringByDeletingPathExtension] stringByAppendingString:@".mp3"]; 137 | 138 | __weak typeof(self) weakself = self; 139 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 140 | 141 | weakself.stopRecord = NO; 142 | 143 | @try { 144 | 145 | int read, write; 146 | 147 | FILE *pcm = fopen([inPath cStringUsingEncoding:NSASCIIStringEncoding], "rb"); 148 | FILE *mp3 = fopen([outPath cStringUsingEncoding:NSASCIIStringEncoding], "wb+"); 149 | 150 | const int PCM_SIZE = 8192; 151 | const int MP3_SIZE = 8192; 152 | short int pcm_buffer[PCM_SIZE * 2]; 153 | unsigned char mp3_buffer[MP3_SIZE]; 154 | 155 | lame_t lame = lame_init(); 156 | lame_set_in_samplerate(lame, 11025.0); 157 | lame_set_VBR(lame, vbr_default); 158 | lame_init_params(lame); 159 | 160 | long curpos; 161 | BOOL isSkipPCMHeader = NO; 162 | 163 | do { 164 | curpos = ftell(pcm); 165 | long startPos = ftell(pcm); 166 | fseek(pcm, 0, SEEK_END); 167 | long endPos = ftell(pcm); 168 | long length = endPos - startPos; 169 | fseek(pcm, curpos, SEEK_SET); 170 | 171 | if (length > PCM_SIZE * 2 * sizeof(short int)) { 172 | 173 | if (!isSkipPCMHeader) { 174 | //Uump audio file header, If you do not skip file header 175 | //you will heard some noise at the beginning!!! 176 | fseek(pcm, 4 * 1024, SEEK_CUR); 177 | isSkipPCMHeader = YES; 178 | NSLog(@"skip pcm file header !!!!!!!!!!"); 179 | } 180 | 181 | read = (int)fread(pcm_buffer, 2 * sizeof(short int), PCM_SIZE, pcm); 182 | write = lame_encode_buffer_interleaved(lame, pcm_buffer, read, mp3_buffer, MP3_SIZE); 183 | fwrite(mp3_buffer, write, 1, mp3); 184 | NSLog(@"read %d bytes", write); 185 | } else { 186 | [NSThread sleepForTimeInterval:0.05]; 187 | NSLog(@"sleep"); 188 | } 189 | 190 | } while (!weakself.stopRecord); 191 | 192 | read = (int)fread(pcm_buffer, 2 * sizeof(short int), PCM_SIZE, pcm); 193 | write = lame_encode_flush(lame, mp3_buffer, MP3_SIZE); 194 | 195 | NSLog(@"read %d bytes and flush to mp3 file", write); 196 | lame_mp3_tags_fid(lame, mp3); 197 | 198 | lame_close(lame); 199 | fclose(mp3); 200 | fclose(pcm); 201 | } 202 | 203 | @catch (NSException *exception) { 204 | // NSLog(@"%@", [exception description]); 205 | if (fail) { 206 | fail([exception description]); 207 | } 208 | } 209 | 210 | @finally { 211 | 212 | // NSLog(@"convert mp3 finish!!! %@", outPath); 213 | 214 | if (isDelete) { 215 | 216 | NSError *error; 217 | [fm removeItemAtPath:sourcePath error:&error]; 218 | if (error == nil) 219 | { 220 | // NSLog(@"删除源文件成功"); 221 | } 222 | } 223 | 224 | if (success) { 225 | success(outPath); 226 | } 227 | } 228 | }); 229 | } 230 | 231 | /** 232 | 录音完成的调用 233 | */ 234 | - (void)sendEndRecord { 235 | self.stopRecord = YES; 236 | } 237 | 238 | 239 | @end 240 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Class/lame/lame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to MP3 LAME encoding engine 3 | * 4 | * Copyright (c) 1999 Mark Taylor 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Library General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library 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 GNU 14 | * Library General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Library General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | /* $Id: lame.h,v 1.192 2017/08/31 14:14:46 robert Exp $ */ 23 | 24 | #ifndef LAME_LAME_H 25 | #define LAME_LAME_H 26 | 27 | /* for size_t typedef */ 28 | #include 29 | /* for va_list typedef */ 30 | #include 31 | /* for FILE typedef, TODO: remove when removing lame_mp3_tags_fid */ 32 | #include 33 | 34 | #if defined(__cplusplus) 35 | extern "C" { 36 | #endif 37 | 38 | typedef void (*lame_report_function)(const char *format, va_list ap); 39 | 40 | #if defined(WIN32) || defined(_WIN32) 41 | #undef CDECL 42 | #define CDECL __cdecl 43 | #else 44 | #define CDECL 45 | #endif 46 | 47 | #define DEPRECATED_OR_OBSOLETE_CODE_REMOVED 1 48 | 49 | typedef enum vbr_mode_e { 50 | vbr_off=0, 51 | vbr_mt, /* obsolete, same as vbr_mtrh */ 52 | vbr_rh, 53 | vbr_abr, 54 | vbr_mtrh, 55 | vbr_max_indicator, /* Don't use this! It's used for sanity checks. */ 56 | vbr_default=vbr_mtrh /* change this to change the default VBR mode of LAME */ 57 | } vbr_mode; 58 | 59 | 60 | /* MPEG modes */ 61 | typedef enum MPEG_mode_e { 62 | STEREO = 0, 63 | JOINT_STEREO, 64 | DUAL_CHANNEL, /* LAME doesn't supports this! */ 65 | MONO, 66 | NOT_SET, 67 | MAX_INDICATOR /* Don't use this! It's used for sanity checks. */ 68 | } MPEG_mode; 69 | 70 | /* Padding types */ 71 | typedef enum Padding_type_e { 72 | PAD_NO = 0, 73 | PAD_ALL, 74 | PAD_ADJUST, 75 | PAD_MAX_INDICATOR /* Don't use this! It's used for sanity checks. */ 76 | } Padding_type; 77 | 78 | 79 | 80 | /*presets*/ 81 | typedef enum preset_mode_e { 82 | /*values from 8 to 320 should be reserved for abr bitrates*/ 83 | /*for abr I'd suggest to directly use the targeted bitrate as a value*/ 84 | ABR_8 = 8, 85 | ABR_320 = 320, 86 | 87 | V9 = 410, /*Vx to match Lame and VBR_xx to match FhG*/ 88 | VBR_10 = 410, 89 | V8 = 420, 90 | VBR_20 = 420, 91 | V7 = 430, 92 | VBR_30 = 430, 93 | V6 = 440, 94 | VBR_40 = 440, 95 | V5 = 450, 96 | VBR_50 = 450, 97 | V4 = 460, 98 | VBR_60 = 460, 99 | V3 = 470, 100 | VBR_70 = 470, 101 | V2 = 480, 102 | VBR_80 = 480, 103 | V1 = 490, 104 | VBR_90 = 490, 105 | V0 = 500, 106 | VBR_100 = 500, 107 | 108 | 109 | 110 | /*still there for compatibility*/ 111 | R3MIX = 1000, 112 | STANDARD = 1001, 113 | EXTREME = 1002, 114 | INSANE = 1003, 115 | STANDARD_FAST = 1004, 116 | EXTREME_FAST = 1005, 117 | MEDIUM = 1006, 118 | MEDIUM_FAST = 1007 119 | } preset_mode; 120 | 121 | 122 | /*asm optimizations*/ 123 | typedef enum asm_optimizations_e { 124 | MMX = 1, 125 | AMD_3DNOW = 2, 126 | SSE = 3 127 | } asm_optimizations; 128 | 129 | 130 | /* psychoacoustic model */ 131 | typedef enum Psy_model_e { 132 | PSY_GPSYCHO = 1, 133 | PSY_NSPSYTUNE = 2 134 | } Psy_model; 135 | 136 | 137 | /* buffer considerations */ 138 | typedef enum buffer_constraint_e { 139 | MDB_DEFAULT=0, 140 | MDB_STRICT_ISO=1, 141 | MDB_MAXIMUM=2 142 | } buffer_constraint; 143 | 144 | 145 | struct lame_global_struct; 146 | typedef struct lame_global_struct lame_global_flags; 147 | typedef lame_global_flags *lame_t; 148 | 149 | 150 | 151 | 152 | /*********************************************************************** 153 | * 154 | * The LAME API 155 | * These functions should be called, in this order, for each 156 | * MP3 file to be encoded. See the file "API" for more documentation 157 | * 158 | ***********************************************************************/ 159 | 160 | 161 | /* 162 | * REQUIRED: 163 | * initialize the encoder. sets default for all encoder parameters, 164 | * returns NULL if some malloc()'s failed 165 | * otherwise returns pointer to structure needed for all future 166 | * API calls. 167 | */ 168 | lame_global_flags * CDECL lame_init(void); 169 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 170 | #else 171 | /* obsolete version */ 172 | int CDECL lame_init_old(lame_global_flags *); 173 | #endif 174 | 175 | /* 176 | * OPTIONAL: 177 | * set as needed to override defaults 178 | */ 179 | 180 | /******************************************************************** 181 | * input stream description 182 | ***********************************************************************/ 183 | /* number of samples. default = 2^32-1 */ 184 | int CDECL lame_set_num_samples(lame_global_flags *, unsigned long); 185 | unsigned long CDECL lame_get_num_samples(const lame_global_flags *); 186 | 187 | /* input sample rate in Hz. default = 44100hz */ 188 | int CDECL lame_set_in_samplerate(lame_global_flags *, int); 189 | int CDECL lame_get_in_samplerate(const lame_global_flags *); 190 | 191 | /* number of channels in input stream. default=2 */ 192 | int CDECL lame_set_num_channels(lame_global_flags *, int); 193 | int CDECL lame_get_num_channels(const lame_global_flags *); 194 | 195 | /* 196 | scale the input by this amount before encoding. default=1 197 | (not used by decoding routines) 198 | */ 199 | int CDECL lame_set_scale(lame_global_flags *, float); 200 | float CDECL lame_get_scale(const lame_global_flags *); 201 | 202 | /* 203 | scale the channel 0 (left) input by this amount before encoding. default=1 204 | (not used by decoding routines) 205 | */ 206 | int CDECL lame_set_scale_left(lame_global_flags *, float); 207 | float CDECL lame_get_scale_left(const lame_global_flags *); 208 | 209 | /* 210 | scale the channel 1 (right) input by this amount before encoding. default=1 211 | (not used by decoding routines) 212 | */ 213 | int CDECL lame_set_scale_right(lame_global_flags *, float); 214 | float CDECL lame_get_scale_right(const lame_global_flags *); 215 | 216 | /* 217 | output sample rate in Hz. default = 0, which means LAME picks best value 218 | based on the amount of compression. MPEG only allows: 219 | MPEG1 32, 44.1, 48khz 220 | MPEG2 16, 22.05, 24 221 | MPEG2.5 8, 11.025, 12 222 | (not used by decoding routines) 223 | */ 224 | int CDECL lame_set_out_samplerate(lame_global_flags *, int); 225 | int CDECL lame_get_out_samplerate(const lame_global_flags *); 226 | 227 | 228 | /******************************************************************** 229 | * general control parameters 230 | ***********************************************************************/ 231 | /* 1=cause LAME to collect data for an MP3 frame analyzer. default=0 */ 232 | int CDECL lame_set_analysis(lame_global_flags *, int); 233 | int CDECL lame_get_analysis(const lame_global_flags *); 234 | 235 | /* 236 | 1 = write a Xing VBR header frame. 237 | default = 1 238 | this variable must have been added by a Hungarian notation Windows programmer :-) 239 | */ 240 | int CDECL lame_set_bWriteVbrTag(lame_global_flags *, int); 241 | int CDECL lame_get_bWriteVbrTag(const lame_global_flags *); 242 | 243 | /* 1=decode only. use lame/mpglib to convert mp3/ogg to wav. default=0 */ 244 | int CDECL lame_set_decode_only(lame_global_flags *, int); 245 | int CDECL lame_get_decode_only(const lame_global_flags *); 246 | 247 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 248 | #else 249 | /* 1=encode a Vorbis .ogg file. default=0 */ 250 | /* DEPRECATED */ 251 | int CDECL lame_set_ogg(lame_global_flags *, int); 252 | int CDECL lame_get_ogg(const lame_global_flags *); 253 | #endif 254 | 255 | /* 256 | internal algorithm selection. True quality is determined by the bitrate 257 | but this variable will effect quality by selecting expensive or cheap algorithms. 258 | quality=0..9. 0=best (very slow). 9=worst. 259 | recommended: 2 near-best quality, not too slow 260 | 5 good quality, fast 261 | 7 ok quality, really fast 262 | */ 263 | int CDECL lame_set_quality(lame_global_flags *, int); 264 | int CDECL lame_get_quality(const lame_global_flags *); 265 | 266 | /* 267 | mode = 0,1,2,3 = stereo, jstereo, dual channel (not supported), mono 268 | default: lame picks based on compression ration and input channels 269 | */ 270 | int CDECL lame_set_mode(lame_global_flags *, MPEG_mode); 271 | MPEG_mode CDECL lame_get_mode(const lame_global_flags *); 272 | 273 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 274 | #else 275 | /* 276 | mode_automs. Use a M/S mode with a switching threshold based on 277 | compression ratio 278 | DEPRECATED 279 | */ 280 | int CDECL lame_set_mode_automs(lame_global_flags *, int); 281 | int CDECL lame_get_mode_automs(const lame_global_flags *); 282 | #endif 283 | 284 | /* 285 | force_ms. Force M/S for all frames. For testing only. 286 | default = 0 (disabled) 287 | */ 288 | int CDECL lame_set_force_ms(lame_global_flags *, int); 289 | int CDECL lame_get_force_ms(const lame_global_flags *); 290 | 291 | /* use free_format? default = 0 (disabled) */ 292 | int CDECL lame_set_free_format(lame_global_flags *, int); 293 | int CDECL lame_get_free_format(const lame_global_flags *); 294 | 295 | /* perform ReplayGain analysis? default = 0 (disabled) */ 296 | int CDECL lame_set_findReplayGain(lame_global_flags *, int); 297 | int CDECL lame_get_findReplayGain(const lame_global_flags *); 298 | 299 | /* decode on the fly. Search for the peak sample. If the ReplayGain 300 | * analysis is enabled then perform the analysis on the decoded data 301 | * stream. default = 0 (disabled) 302 | * NOTE: if this option is set the build-in decoder should not be used */ 303 | int CDECL lame_set_decode_on_the_fly(lame_global_flags *, int); 304 | int CDECL lame_get_decode_on_the_fly(const lame_global_flags *); 305 | 306 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 307 | #else 308 | /* DEPRECATED: now does the same as lame_set_findReplayGain() 309 | default = 0 (disabled) */ 310 | int CDECL lame_set_ReplayGain_input(lame_global_flags *, int); 311 | int CDECL lame_get_ReplayGain_input(const lame_global_flags *); 312 | 313 | /* DEPRECATED: now does the same as 314 | lame_set_decode_on_the_fly() && lame_set_findReplayGain() 315 | default = 0 (disabled) */ 316 | int CDECL lame_set_ReplayGain_decode(lame_global_flags *, int); 317 | int CDECL lame_get_ReplayGain_decode(const lame_global_flags *); 318 | 319 | /* DEPRECATED: now does the same as lame_set_decode_on_the_fly() 320 | default = 0 (disabled) */ 321 | int CDECL lame_set_findPeakSample(lame_global_flags *, int); 322 | int CDECL lame_get_findPeakSample(const lame_global_flags *); 323 | #endif 324 | 325 | /* counters for gapless encoding */ 326 | int CDECL lame_set_nogap_total(lame_global_flags*, int); 327 | int CDECL lame_get_nogap_total(const lame_global_flags*); 328 | 329 | int CDECL lame_set_nogap_currentindex(lame_global_flags* , int); 330 | int CDECL lame_get_nogap_currentindex(const lame_global_flags*); 331 | 332 | 333 | /* 334 | * OPTIONAL: 335 | * Set printf like error/debug/message reporting functions. 336 | * The second argument has to be a pointer to a function which looks like 337 | * void my_debugf(const char *format, va_list ap) 338 | * { 339 | * (void) vfprintf(stdout, format, ap); 340 | * } 341 | * If you use NULL as the value of the pointer in the set function, the 342 | * lame buildin function will be used (prints to stderr). 343 | * To quiet any output you have to replace the body of the example function 344 | * with just "return;" and use it in the set function. 345 | */ 346 | int CDECL lame_set_errorf(lame_global_flags *, lame_report_function); 347 | int CDECL lame_set_debugf(lame_global_flags *, lame_report_function); 348 | int CDECL lame_set_msgf (lame_global_flags *, lame_report_function); 349 | 350 | 351 | 352 | /* set one of brate compression ratio. default is compression ratio of 11. */ 353 | int CDECL lame_set_brate(lame_global_flags *, int); 354 | int CDECL lame_get_brate(const lame_global_flags *); 355 | int CDECL lame_set_compression_ratio(lame_global_flags *, float); 356 | float CDECL lame_get_compression_ratio(const lame_global_flags *); 357 | 358 | 359 | int CDECL lame_set_preset( lame_global_flags* gfp, int ); 360 | int CDECL lame_set_asm_optimizations( lame_global_flags* gfp, int, int ); 361 | 362 | 363 | 364 | /******************************************************************** 365 | * frame params 366 | ***********************************************************************/ 367 | /* mark as copyright. default=0 */ 368 | int CDECL lame_set_copyright(lame_global_flags *, int); 369 | int CDECL lame_get_copyright(const lame_global_flags *); 370 | 371 | /* mark as original. default=1 */ 372 | int CDECL lame_set_original(lame_global_flags *, int); 373 | int CDECL lame_get_original(const lame_global_flags *); 374 | 375 | /* error_protection. Use 2 bytes from each frame for CRC checksum. default=0 */ 376 | int CDECL lame_set_error_protection(lame_global_flags *, int); 377 | int CDECL lame_get_error_protection(const lame_global_flags *); 378 | 379 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 380 | #else 381 | /* padding_type. 0=pad no frames 1=pad all frames 2=adjust padding(default) */ 382 | int CDECL lame_set_padding_type(lame_global_flags *, Padding_type); 383 | Padding_type CDECL lame_get_padding_type(const lame_global_flags *); 384 | #endif 385 | 386 | /* MP3 'private extension' bit Meaningless. default=0 */ 387 | int CDECL lame_set_extension(lame_global_flags *, int); 388 | int CDECL lame_get_extension(const lame_global_flags *); 389 | 390 | /* enforce strict ISO compliance. default=0 */ 391 | int CDECL lame_set_strict_ISO(lame_global_flags *, int); 392 | int CDECL lame_get_strict_ISO(const lame_global_flags *); 393 | 394 | 395 | /******************************************************************** 396 | * quantization/noise shaping 397 | ***********************************************************************/ 398 | 399 | /* disable the bit reservoir. For testing only. default=0 */ 400 | int CDECL lame_set_disable_reservoir(lame_global_flags *, int); 401 | int CDECL lame_get_disable_reservoir(const lame_global_flags *); 402 | 403 | /* select a different "best quantization" function. default=0 */ 404 | int CDECL lame_set_quant_comp(lame_global_flags *, int); 405 | int CDECL lame_get_quant_comp(const lame_global_flags *); 406 | int CDECL lame_set_quant_comp_short(lame_global_flags *, int); 407 | int CDECL lame_get_quant_comp_short(const lame_global_flags *); 408 | 409 | int CDECL lame_set_experimentalX(lame_global_flags *, int); /* compatibility*/ 410 | int CDECL lame_get_experimentalX(const lame_global_flags *); 411 | 412 | /* another experimental option. for testing only */ 413 | int CDECL lame_set_experimentalY(lame_global_flags *, int); 414 | int CDECL lame_get_experimentalY(const lame_global_flags *); 415 | 416 | /* another experimental option. for testing only */ 417 | int CDECL lame_set_experimentalZ(lame_global_flags *, int); 418 | int CDECL lame_get_experimentalZ(const lame_global_flags *); 419 | 420 | /* Naoki's psycho acoustic model. default=0 */ 421 | int CDECL lame_set_exp_nspsytune(lame_global_flags *, int); 422 | int CDECL lame_get_exp_nspsytune(const lame_global_flags *); 423 | 424 | void CDECL lame_set_msfix(lame_global_flags *, double); 425 | float CDECL lame_get_msfix(const lame_global_flags *); 426 | 427 | 428 | /******************************************************************** 429 | * VBR control 430 | ***********************************************************************/ 431 | /* Types of VBR. default = vbr_off = CBR */ 432 | int CDECL lame_set_VBR(lame_global_flags *, vbr_mode); 433 | vbr_mode CDECL lame_get_VBR(const lame_global_flags *); 434 | 435 | /* VBR quality level. 0=highest 9=lowest */ 436 | int CDECL lame_set_VBR_q(lame_global_flags *, int); 437 | int CDECL lame_get_VBR_q(const lame_global_flags *); 438 | 439 | /* VBR quality level. 0=highest 9=lowest, Range [0,...,10[ */ 440 | int CDECL lame_set_VBR_quality(lame_global_flags *, float); 441 | float CDECL lame_get_VBR_quality(const lame_global_flags *); 442 | 443 | /* Ignored except for VBR=vbr_abr (ABR mode) */ 444 | int CDECL lame_set_VBR_mean_bitrate_kbps(lame_global_flags *, int); 445 | int CDECL lame_get_VBR_mean_bitrate_kbps(const lame_global_flags *); 446 | 447 | int CDECL lame_set_VBR_min_bitrate_kbps(lame_global_flags *, int); 448 | int CDECL lame_get_VBR_min_bitrate_kbps(const lame_global_flags *); 449 | 450 | int CDECL lame_set_VBR_max_bitrate_kbps(lame_global_flags *, int); 451 | int CDECL lame_get_VBR_max_bitrate_kbps(const lame_global_flags *); 452 | 453 | /* 454 | 1=strictly enforce VBR_min_bitrate. Normally it will be violated for 455 | analog silence 456 | */ 457 | int CDECL lame_set_VBR_hard_min(lame_global_flags *, int); 458 | int CDECL lame_get_VBR_hard_min(const lame_global_flags *); 459 | 460 | /* for preset */ 461 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 462 | #else 463 | int CDECL lame_set_preset_expopts(lame_global_flags *, int); 464 | #endif 465 | 466 | /******************************************************************** 467 | * Filtering control 468 | ***********************************************************************/ 469 | /* freq in Hz to apply lowpass. Default = 0 = lame chooses. -1 = disabled */ 470 | int CDECL lame_set_lowpassfreq(lame_global_flags *, int); 471 | int CDECL lame_get_lowpassfreq(const lame_global_flags *); 472 | /* width of transition band, in Hz. Default = one polyphase filter band */ 473 | int CDECL lame_set_lowpasswidth(lame_global_flags *, int); 474 | int CDECL lame_get_lowpasswidth(const lame_global_flags *); 475 | 476 | /* freq in Hz to apply highpass. Default = 0 = lame chooses. -1 = disabled */ 477 | int CDECL lame_set_highpassfreq(lame_global_flags *, int); 478 | int CDECL lame_get_highpassfreq(const lame_global_flags *); 479 | /* width of transition band, in Hz. Default = one polyphase filter band */ 480 | int CDECL lame_set_highpasswidth(lame_global_flags *, int); 481 | int CDECL lame_get_highpasswidth(const lame_global_flags *); 482 | 483 | 484 | /******************************************************************** 485 | * psycho acoustics and other arguments which you should not change 486 | * unless you know what you are doing 487 | ***********************************************************************/ 488 | 489 | /* only use ATH for masking */ 490 | int CDECL lame_set_ATHonly(lame_global_flags *, int); 491 | int CDECL lame_get_ATHonly(const lame_global_flags *); 492 | 493 | /* only use ATH for short blocks */ 494 | int CDECL lame_set_ATHshort(lame_global_flags *, int); 495 | int CDECL lame_get_ATHshort(const lame_global_flags *); 496 | 497 | /* disable ATH */ 498 | int CDECL lame_set_noATH(lame_global_flags *, int); 499 | int CDECL lame_get_noATH(const lame_global_flags *); 500 | 501 | /* select ATH formula */ 502 | int CDECL lame_set_ATHtype(lame_global_flags *, int); 503 | int CDECL lame_get_ATHtype(const lame_global_flags *); 504 | 505 | /* lower ATH by this many db */ 506 | int CDECL lame_set_ATHlower(lame_global_flags *, float); 507 | float CDECL lame_get_ATHlower(const lame_global_flags *); 508 | 509 | /* select ATH adaptive adjustment type */ 510 | int CDECL lame_set_athaa_type( lame_global_flags *, int); 511 | int CDECL lame_get_athaa_type( const lame_global_flags *); 512 | 513 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 514 | #else 515 | /* select the loudness approximation used by the ATH adaptive auto-leveling */ 516 | int CDECL lame_set_athaa_loudapprox( lame_global_flags *, int); 517 | int CDECL lame_get_athaa_loudapprox( const lame_global_flags *); 518 | #endif 519 | 520 | /* adjust (in dB) the point below which adaptive ATH level adjustment occurs */ 521 | int CDECL lame_set_athaa_sensitivity( lame_global_flags *, float); 522 | float CDECL lame_get_athaa_sensitivity( const lame_global_flags* ); 523 | 524 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 525 | #else 526 | /* OBSOLETE: predictability limit (ISO tonality formula) */ 527 | int CDECL lame_set_cwlimit(lame_global_flags *, int); 528 | int CDECL lame_get_cwlimit(const lame_global_flags *); 529 | #endif 530 | 531 | /* 532 | allow blocktypes to differ between channels? 533 | default: 0 for jstereo, 1 for stereo 534 | */ 535 | int CDECL lame_set_allow_diff_short(lame_global_flags *, int); 536 | int CDECL lame_get_allow_diff_short(const lame_global_flags *); 537 | 538 | /* use temporal masking effect (default = 1) */ 539 | int CDECL lame_set_useTemporal(lame_global_flags *, int); 540 | int CDECL lame_get_useTemporal(const lame_global_flags *); 541 | 542 | /* use temporal masking effect (default = 1) */ 543 | int CDECL lame_set_interChRatio(lame_global_flags *, float); 544 | float CDECL lame_get_interChRatio(const lame_global_flags *); 545 | 546 | /* disable short blocks */ 547 | int CDECL lame_set_no_short_blocks(lame_global_flags *, int); 548 | int CDECL lame_get_no_short_blocks(const lame_global_flags *); 549 | 550 | /* force short blocks */ 551 | int CDECL lame_set_force_short_blocks(lame_global_flags *, int); 552 | int CDECL lame_get_force_short_blocks(const lame_global_flags *); 553 | 554 | /* Input PCM is emphased PCM (for instance from one of the rarely 555 | emphased CDs), it is STRONGLY not recommended to use this, because 556 | psycho does not take it into account, and last but not least many decoders 557 | ignore these bits */ 558 | int CDECL lame_set_emphasis(lame_global_flags *, int); 559 | int CDECL lame_get_emphasis(const lame_global_flags *); 560 | 561 | 562 | 563 | /************************************************************************/ 564 | /* internal variables, cannot be set... */ 565 | /* provided because they may be of use to calling application */ 566 | /************************************************************************/ 567 | /* version 0=MPEG-2 1=MPEG-1 (2=MPEG-2.5) */ 568 | int CDECL lame_get_version(const lame_global_flags *); 569 | 570 | /* encoder delay */ 571 | int CDECL lame_get_encoder_delay(const lame_global_flags *); 572 | 573 | /* 574 | padding appended to the input to make sure decoder can fully decode 575 | all input. Note that this value can only be calculated during the 576 | call to lame_encoder_flush(). Before lame_encoder_flush() has 577 | been called, the value of encoder_padding = 0. 578 | */ 579 | int CDECL lame_get_encoder_padding(const lame_global_flags *); 580 | 581 | /* size of MPEG frame */ 582 | int CDECL lame_get_framesize(const lame_global_flags *); 583 | 584 | /* number of PCM samples buffered, but not yet encoded to mp3 data. */ 585 | int CDECL lame_get_mf_samples_to_encode( const lame_global_flags* gfp ); 586 | 587 | /* 588 | size (bytes) of mp3 data buffered, but not yet encoded. 589 | this is the number of bytes which would be output by a call to 590 | lame_encode_flush_nogap. NOTE: lame_encode_flush() will return 591 | more bytes than this because it will encode the reamining buffered 592 | PCM samples before flushing the mp3 buffers. 593 | */ 594 | int CDECL lame_get_size_mp3buffer( const lame_global_flags* gfp ); 595 | 596 | /* number of frames encoded so far */ 597 | int CDECL lame_get_frameNum(const lame_global_flags *); 598 | 599 | /* 600 | lame's estimate of the total number of frames to be encoded 601 | only valid if calling program set num_samples 602 | */ 603 | int CDECL lame_get_totalframes(const lame_global_flags *); 604 | 605 | /* RadioGain value. Multiplied by 10 and rounded to the nearest. */ 606 | int CDECL lame_get_RadioGain(const lame_global_flags *); 607 | 608 | /* AudiophileGain value. Multipled by 10 and rounded to the nearest. */ 609 | int CDECL lame_get_AudiophileGain(const lame_global_flags *); 610 | 611 | /* the peak sample */ 612 | float CDECL lame_get_PeakSample(const lame_global_flags *); 613 | 614 | /* Gain change required for preventing clipping. The value is correct only if 615 | peak sample searching was enabled. If negative then the waveform 616 | already does not clip. The value is multiplied by 10 and rounded up. */ 617 | int CDECL lame_get_noclipGainChange(const lame_global_flags *); 618 | 619 | /* user-specified scale factor required for preventing clipping. Value is 620 | correct only if peak sample searching was enabled and no user-specified 621 | scaling was performed. If negative then either the waveform already does 622 | not clip or the value cannot be determined */ 623 | float CDECL lame_get_noclipScale(const lame_global_flags *); 624 | 625 | /* returns the limit of PCM samples, which one can pass in an encode call 626 | under the constrain of a provided buffer of size buffer_size */ 627 | int CDECL lame_get_maximum_number_of_samples(lame_t gfp, size_t buffer_size); 628 | 629 | 630 | 631 | 632 | /* 633 | * REQUIRED: 634 | * sets more internal configuration based on data provided above. 635 | * returns -1 if something failed. 636 | */ 637 | int CDECL lame_init_params(lame_global_flags *); 638 | 639 | 640 | /* 641 | * OPTIONAL: 642 | * get the version number, in a string. of the form: 643 | * "3.63 (beta)" or just "3.63". 644 | */ 645 | const char* CDECL get_lame_version ( void ); 646 | const char* CDECL get_lame_short_version ( void ); 647 | const char* CDECL get_lame_very_short_version ( void ); 648 | const char* CDECL get_psy_version ( void ); 649 | const char* CDECL get_lame_url ( void ); 650 | const char* CDECL get_lame_os_bitness ( void ); 651 | 652 | /* 653 | * OPTIONAL: 654 | * get the version numbers in numerical form. 655 | */ 656 | typedef struct { 657 | /* generic LAME version */ 658 | int major; 659 | int minor; 660 | int alpha; /* 0 if not an alpha version */ 661 | int beta; /* 0 if not a beta version */ 662 | 663 | /* version of the psy model */ 664 | int psy_major; 665 | int psy_minor; 666 | int psy_alpha; /* 0 if not an alpha version */ 667 | int psy_beta; /* 0 if not a beta version */ 668 | 669 | /* compile time features */ 670 | const char *features; /* Don't make assumptions about the contents! */ 671 | } lame_version_t; 672 | void CDECL get_lame_version_numerical(lame_version_t *); 673 | 674 | 675 | /* 676 | * OPTIONAL: 677 | * print internal lame configuration to message handler 678 | */ 679 | void CDECL lame_print_config(const lame_global_flags* gfp); 680 | 681 | void CDECL lame_print_internals( const lame_global_flags *gfp); 682 | 683 | 684 | /* 685 | * input pcm data, output (maybe) mp3 frames. 686 | * This routine handles all buffering, resampling and filtering for you. 687 | * 688 | * return code number of bytes output in mp3buf. Can be 0 689 | * -1: mp3buf was too small 690 | * -2: malloc() problem 691 | * -3: lame_init_params() not called 692 | * -4: psycho acoustic problems 693 | * 694 | * The required mp3buf_size can be computed from num_samples, 695 | * samplerate and encoding rate, but here is a worst case estimate: 696 | * 697 | * mp3buf_size in bytes = 1.25*num_samples + 7200 698 | * 699 | * I think a tighter bound could be: (mt, March 2000) 700 | * MPEG1: 701 | * num_samples*(bitrate/8)/samplerate + 4*1152*(bitrate/8)/samplerate + 512 702 | * MPEG2: 703 | * num_samples*(bitrate/8)/samplerate + 4*576*(bitrate/8)/samplerate + 256 704 | * 705 | * but test first if you use that! 706 | * 707 | * set mp3buf_size = 0 and LAME will not check if mp3buf_size is 708 | * large enough. 709 | * 710 | * NOTE: 711 | * if gfp->num_channels=2, but gfp->mode = 3 (mono), the L & R channels 712 | * will be averaged into the L channel before encoding only the L channel 713 | * This will overwrite the data in buffer_l[] and buffer_r[]. 714 | * 715 | */ 716 | int CDECL lame_encode_buffer ( 717 | lame_global_flags* gfp, /* global context handle */ 718 | const short int buffer_l [], /* PCM data for left channel */ 719 | const short int buffer_r [], /* PCM data for right channel */ 720 | const int nsamples, /* number of samples per channel */ 721 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 722 | const int mp3buf_size ); /* number of valid octets in this 723 | stream */ 724 | 725 | /* 726 | * as above, but input has L & R channel data interleaved. 727 | * NOTE: 728 | * num_samples = number of samples in the L (or R) 729 | * channel, not the total number of samples in pcm[] 730 | */ 731 | int CDECL lame_encode_buffer_interleaved( 732 | lame_global_flags* gfp, /* global context handlei */ 733 | short int pcm[], /* PCM data for left and right 734 | channel, interleaved */ 735 | int num_samples, /* number of samples per channel, 736 | _not_ number of samples in 737 | pcm[] */ 738 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 739 | int mp3buf_size ); /* number of valid octets in this 740 | stream */ 741 | 742 | 743 | /* as lame_encode_buffer, but for 'float's. 744 | * !! NOTE: !! data must still be scaled to be in the same range as 745 | * short int, +/- 32768 746 | */ 747 | int CDECL lame_encode_buffer_float( 748 | lame_global_flags* gfp, /* global context handle */ 749 | const float pcm_l [], /* PCM data for left channel */ 750 | const float pcm_r [], /* PCM data for right channel */ 751 | const int nsamples, /* number of samples per channel */ 752 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 753 | const int mp3buf_size ); /* number of valid octets in this 754 | stream */ 755 | 756 | /* as lame_encode_buffer, but for 'float's. 757 | * !! NOTE: !! data must be scaled to +/- 1 full scale 758 | */ 759 | int CDECL lame_encode_buffer_ieee_float( 760 | lame_t gfp, 761 | const float pcm_l [], /* PCM data for left channel */ 762 | const float pcm_r [], /* PCM data for right channel */ 763 | const int nsamples, 764 | unsigned char * mp3buf, 765 | const int mp3buf_size); 766 | int CDECL lame_encode_buffer_interleaved_ieee_float( 767 | lame_t gfp, 768 | const float pcm[], /* PCM data for left and right 769 | channel, interleaved */ 770 | const int nsamples, 771 | unsigned char * mp3buf, 772 | const int mp3buf_size); 773 | 774 | /* as lame_encode_buffer, but for 'double's. 775 | * !! NOTE: !! data must be scaled to +/- 1 full scale 776 | */ 777 | int CDECL lame_encode_buffer_ieee_double( 778 | lame_t gfp, 779 | const double pcm_l [], /* PCM data for left channel */ 780 | const double pcm_r [], /* PCM data for right channel */ 781 | const int nsamples, 782 | unsigned char * mp3buf, 783 | const int mp3buf_size); 784 | int CDECL lame_encode_buffer_interleaved_ieee_double( 785 | lame_t gfp, 786 | const double pcm[], /* PCM data for left and right 787 | channel, interleaved */ 788 | const int nsamples, 789 | unsigned char * mp3buf, 790 | const int mp3buf_size); 791 | 792 | /* as lame_encode_buffer, but for long's 793 | * !! NOTE: !! data must still be scaled to be in the same range as 794 | * short int, +/- 32768 795 | * 796 | * This scaling was a mistake (doesn't allow one to exploit full 797 | * precision of type 'long'. Use lame_encode_buffer_long2() instead. 798 | * 799 | */ 800 | int CDECL lame_encode_buffer_long( 801 | lame_global_flags* gfp, /* global context handle */ 802 | const long buffer_l [], /* PCM data for left channel */ 803 | const long buffer_r [], /* PCM data for right channel */ 804 | const int nsamples, /* number of samples per channel */ 805 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 806 | const int mp3buf_size ); /* number of valid octets in this 807 | stream */ 808 | 809 | /* Same as lame_encode_buffer_long(), but with correct scaling. 810 | * !! NOTE: !! data must still be scaled to be in the same range as 811 | * type 'long'. Data should be in the range: +/- 2^(8*size(long)-1) 812 | * 813 | */ 814 | int CDECL lame_encode_buffer_long2( 815 | lame_global_flags* gfp, /* global context handle */ 816 | const long buffer_l [], /* PCM data for left channel */ 817 | const long buffer_r [], /* PCM data for right channel */ 818 | const int nsamples, /* number of samples per channel */ 819 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 820 | const int mp3buf_size ); /* number of valid octets in this 821 | stream */ 822 | 823 | /* as lame_encode_buffer, but for int's 824 | * !! NOTE: !! input should be scaled to the maximum range of 'int' 825 | * If int is 4 bytes, then the values should range from 826 | * +/- 2147483648. 827 | * 828 | * This routine does not (and cannot, without loosing precision) use 829 | * the same scaling as the rest of the lame_encode_buffer() routines. 830 | * 831 | */ 832 | int CDECL lame_encode_buffer_int( 833 | lame_global_flags* gfp, /* global context handle */ 834 | const int buffer_l [], /* PCM data for left channel */ 835 | const int buffer_r [], /* PCM data for right channel */ 836 | const int nsamples, /* number of samples per channel */ 837 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 838 | const int mp3buf_size ); /* number of valid octets in this 839 | stream */ 840 | 841 | /* 842 | * as above, but for interleaved data. 843 | * !! NOTE: !! data must still be scaled to be in the same range as 844 | * type 'int32_t'. Data should be in the range: +/- 2^(8*size(int32_t)-1) 845 | * NOTE: 846 | * num_samples = number of samples in the L (or R) 847 | * channel, not the total number of samples in pcm[] 848 | */ 849 | int 850 | lame_encode_buffer_interleaved_int( 851 | lame_t gfp, 852 | const int pcm [], /* PCM data for left and right 853 | channel, interleaved */ 854 | const int nsamples, /* number of samples per channel, 855 | _not_ number of samples in 856 | pcm[] */ 857 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 858 | const int mp3buf_size ); /* number of valid octets in this 859 | stream */ 860 | 861 | 862 | 863 | /* 864 | * REQUIRED: 865 | * lame_encode_flush will flush the intenal PCM buffers, padding with 866 | * 0's to make sure the final frame is complete, and then flush 867 | * the internal MP3 buffers, and thus may return a 868 | * final few mp3 frames. 'mp3buf' should be at least 7200 bytes long 869 | * to hold all possible emitted data. 870 | * 871 | * will also write id3v1 tags (if any) into the bitstream 872 | * 873 | * return code = number of bytes output to mp3buf. Can be 0 874 | */ 875 | int CDECL lame_encode_flush( 876 | lame_global_flags * gfp, /* global context handle */ 877 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 878 | int size); /* number of valid octets in this stream */ 879 | 880 | /* 881 | * OPTIONAL: 882 | * lame_encode_flush_nogap will flush the internal mp3 buffers and pad 883 | * the last frame with ancillary data so it is a complete mp3 frame. 884 | * 885 | * 'mp3buf' should be at least 7200 bytes long 886 | * to hold all possible emitted data. 887 | * 888 | * After a call to this routine, the outputed mp3 data is complete, but 889 | * you may continue to encode new PCM samples and write future mp3 data 890 | * to a different file. The two mp3 files will play back with no gaps 891 | * if they are concatenated together. 892 | * 893 | * This routine will NOT write id3v1 tags into the bitstream. 894 | * 895 | * return code = number of bytes output to mp3buf. Can be 0 896 | */ 897 | int CDECL lame_encode_flush_nogap( 898 | lame_global_flags * gfp, /* global context handle */ 899 | unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 900 | int size); /* number of valid octets in this stream */ 901 | 902 | /* 903 | * OPTIONAL: 904 | * Normally, this is called by lame_init_params(). It writes id3v2 and 905 | * Xing headers into the front of the bitstream, and sets frame counters 906 | * and bitrate histogram data to 0. You can also call this after 907 | * lame_encode_flush_nogap(). 908 | */ 909 | int CDECL lame_init_bitstream( 910 | lame_global_flags * gfp); /* global context handle */ 911 | 912 | 913 | 914 | /* 915 | * OPTIONAL: some simple statistics 916 | * a bitrate histogram to visualize the distribution of used frame sizes 917 | * a stereo mode histogram to visualize the distribution of used stereo 918 | * modes, useful in joint-stereo mode only 919 | * 0: LR left-right encoded 920 | * 1: LR-I left-right and intensity encoded (currently not supported) 921 | * 2: MS mid-side encoded 922 | * 3: MS-I mid-side and intensity encoded (currently not supported) 923 | * 924 | * attention: don't call them after lame_encode_finish 925 | * suggested: lame_encode_flush -> lame_*_hist -> lame_close 926 | */ 927 | 928 | void CDECL lame_bitrate_hist( 929 | const lame_global_flags * gfp, 930 | int bitrate_count[14] ); 931 | void CDECL lame_bitrate_kbps( 932 | const lame_global_flags * gfp, 933 | int bitrate_kbps [14] ); 934 | void CDECL lame_stereo_mode_hist( 935 | const lame_global_flags * gfp, 936 | int stereo_mode_count[4] ); 937 | 938 | void CDECL lame_bitrate_stereo_mode_hist ( 939 | const lame_global_flags * gfp, 940 | int bitrate_stmode_count[14][4] ); 941 | 942 | void CDECL lame_block_type_hist ( 943 | const lame_global_flags * gfp, 944 | int btype_count[6] ); 945 | 946 | void CDECL lame_bitrate_block_type_hist ( 947 | const lame_global_flags * gfp, 948 | int bitrate_btype_count[14][6] ); 949 | 950 | #if (DEPRECATED_OR_OBSOLETE_CODE_REMOVED && 0) 951 | #else 952 | /* 953 | * OPTIONAL: 954 | * lame_mp3_tags_fid will rewrite a Xing VBR tag to the mp3 file with file 955 | * pointer fid. These calls perform forward and backwards seeks, so make 956 | * sure fid is a real file. Make sure lame_encode_flush has been called, 957 | * and all mp3 data has been written to the file before calling this 958 | * function. 959 | * NOTE: 960 | * if VBR tags are turned off by the user, or turned off by LAME because 961 | * the output is not a regular file, this call does nothing 962 | * NOTE: 963 | * LAME wants to read from the file to skip an optional ID3v2 tag, so 964 | * make sure you opened the file for writing and reading. 965 | * NOTE: 966 | * You can call lame_get_lametag_frame instead, if you want to insert 967 | * the lametag yourself. 968 | */ 969 | void CDECL lame_mp3_tags_fid(lame_global_flags *, FILE* fid); 970 | #endif 971 | 972 | /* 973 | * OPTIONAL: 974 | * lame_get_lametag_frame copies the final LAME-tag into 'buffer'. 975 | * The function returns the number of bytes copied into buffer, or 976 | * the required buffer size, if the provided buffer is too small. 977 | * Function failed, if the return value is larger than 'size'! 978 | * Make sure lame_encode flush has been called before calling this function. 979 | * NOTE: 980 | * if VBR tags are turned off by the user, or turned off by LAME, 981 | * this call does nothing and returns 0. 982 | * NOTE: 983 | * LAME inserted an empty frame in the beginning of mp3 audio data, 984 | * which you have to replace by the final LAME-tag frame after encoding. 985 | * In case there is no ID3v2 tag, usually this frame will be the very first 986 | * data in your mp3 file. If you put some other leading data into your 987 | * file, you'll have to do some bookkeeping about where to write this buffer. 988 | */ 989 | size_t CDECL lame_get_lametag_frame( 990 | const lame_global_flags *, unsigned char* buffer, size_t size); 991 | 992 | /* 993 | * REQUIRED: 994 | * final call to free all remaining buffers 995 | */ 996 | int CDECL lame_close (lame_global_flags *); 997 | 998 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 999 | #else 1000 | /* 1001 | * OBSOLETE: 1002 | * lame_encode_finish combines lame_encode_flush() and lame_close() in 1003 | * one call. However, once this call is made, the statistics routines 1004 | * will no longer work because the data will have been cleared, and 1005 | * lame_mp3_tags_fid() cannot be called to add data to the VBR header 1006 | */ 1007 | int CDECL lame_encode_finish( 1008 | lame_global_flags* gfp, 1009 | unsigned char* mp3buf, 1010 | int size ); 1011 | #endif 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | /********************************************************************* 1019 | * 1020 | * decoding 1021 | * 1022 | * a simple interface to mpglib, part of mpg123, is also included if 1023 | * libmp3lame is compiled with HAVE_MPGLIB 1024 | * 1025 | *********************************************************************/ 1026 | 1027 | struct hip_global_struct; 1028 | typedef struct hip_global_struct hip_global_flags; 1029 | typedef hip_global_flags *hip_t; 1030 | 1031 | 1032 | typedef struct { 1033 | int header_parsed; /* 1 if header was parsed and following data was 1034 | computed */ 1035 | int stereo; /* number of channels */ 1036 | int samplerate; /* sample rate */ 1037 | int bitrate; /* bitrate */ 1038 | int mode; /* mp3 frame type */ 1039 | int mode_ext; /* mp3 frame type */ 1040 | int framesize; /* number of samples per mp3 frame */ 1041 | 1042 | /* this data is only computed if mpglib detects a Xing VBR header */ 1043 | unsigned long nsamp; /* number of samples in mp3 file. */ 1044 | int totalframes; /* total number of frames in mp3 file */ 1045 | 1046 | /* this data is not currently computed by the mpglib routines */ 1047 | int framenum; /* frames decoded counter */ 1048 | } mp3data_struct; 1049 | 1050 | /* required call to initialize decoder */ 1051 | hip_t CDECL hip_decode_init(void); 1052 | 1053 | /* cleanup call to exit decoder */ 1054 | int CDECL hip_decode_exit(hip_t gfp); 1055 | 1056 | /* HIP reporting functions */ 1057 | void CDECL hip_set_errorf(hip_t gfp, lame_report_function f); 1058 | void CDECL hip_set_debugf(hip_t gfp, lame_report_function f); 1059 | void CDECL hip_set_msgf (hip_t gfp, lame_report_function f); 1060 | 1061 | /********************************************************************* 1062 | * input 1 mp3 frame, output (maybe) pcm data. 1063 | * 1064 | * nout = hip_decode(hip, mp3buf,len,pcm_l,pcm_r); 1065 | * 1066 | * input: 1067 | * len : number of bytes of mp3 data in mp3buf 1068 | * mp3buf[len] : mp3 data to be decoded 1069 | * 1070 | * output: 1071 | * nout: -1 : decoding error 1072 | * 0 : need more data before we can complete the decode 1073 | * >0 : returned 'nout' samples worth of data in pcm_l,pcm_r 1074 | * pcm_l[nout] : left channel data 1075 | * pcm_r[nout] : right channel data 1076 | * 1077 | *********************************************************************/ 1078 | int CDECL hip_decode( hip_t gfp 1079 | , unsigned char * mp3buf 1080 | , size_t len 1081 | , short pcm_l[] 1082 | , short pcm_r[] 1083 | ); 1084 | 1085 | /* same as hip_decode, and also returns mp3 header data */ 1086 | int CDECL hip_decode_headers( hip_t gfp 1087 | , unsigned char* mp3buf 1088 | , size_t len 1089 | , short pcm_l[] 1090 | , short pcm_r[] 1091 | , mp3data_struct* mp3data 1092 | ); 1093 | 1094 | /* same as hip_decode, but returns at most one frame */ 1095 | int CDECL hip_decode1( hip_t gfp 1096 | , unsigned char* mp3buf 1097 | , size_t len 1098 | , short pcm_l[] 1099 | , short pcm_r[] 1100 | ); 1101 | 1102 | /* same as hip_decode1, but returns at most one frame and mp3 header data */ 1103 | int CDECL hip_decode1_headers( hip_t gfp 1104 | , unsigned char* mp3buf 1105 | , size_t len 1106 | , short pcm_l[] 1107 | , short pcm_r[] 1108 | , mp3data_struct* mp3data 1109 | ); 1110 | 1111 | /* same as hip_decode1_headers, but also returns enc_delay and enc_padding 1112 | from VBR Info tag, (-1 if no info tag was found) */ 1113 | int CDECL hip_decode1_headersB( hip_t gfp 1114 | , unsigned char* mp3buf 1115 | , size_t len 1116 | , short pcm_l[] 1117 | , short pcm_r[] 1118 | , mp3data_struct* mp3data 1119 | , int *enc_delay 1120 | , int *enc_padding 1121 | ); 1122 | 1123 | 1124 | 1125 | /* OBSOLETE: 1126 | * lame_decode... functions are there to keep old code working 1127 | * but it is strongly recommended to replace calls by hip_decode... 1128 | * function calls, see above. 1129 | */ 1130 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 1131 | #else 1132 | int CDECL lame_decode_init(void); 1133 | int CDECL lame_decode( 1134 | unsigned char * mp3buf, 1135 | int len, 1136 | short pcm_l[], 1137 | short pcm_r[] ); 1138 | int CDECL lame_decode_headers( 1139 | unsigned char* mp3buf, 1140 | int len, 1141 | short pcm_l[], 1142 | short pcm_r[], 1143 | mp3data_struct* mp3data ); 1144 | int CDECL lame_decode1( 1145 | unsigned char* mp3buf, 1146 | int len, 1147 | short pcm_l[], 1148 | short pcm_r[] ); 1149 | int CDECL lame_decode1_headers( 1150 | unsigned char* mp3buf, 1151 | int len, 1152 | short pcm_l[], 1153 | short pcm_r[], 1154 | mp3data_struct* mp3data ); 1155 | int CDECL lame_decode1_headersB( 1156 | unsigned char* mp3buf, 1157 | int len, 1158 | short pcm_l[], 1159 | short pcm_r[], 1160 | mp3data_struct* mp3data, 1161 | int *enc_delay, 1162 | int *enc_padding ); 1163 | int CDECL lame_decode_exit(void); 1164 | 1165 | #endif /* obsolete lame_decode API calls */ 1166 | 1167 | 1168 | /********************************************************************* 1169 | * 1170 | * id3tag stuff 1171 | * 1172 | *********************************************************************/ 1173 | 1174 | /* 1175 | * id3tag.h -- Interface to write ID3 version 1 and 2 tags. 1176 | * 1177 | * Copyright (C) 2000 Don Melton. 1178 | * 1179 | * This library is free software; you can redistribute it and/or 1180 | * modify it under the terms of the GNU Library General Public 1181 | * License as published by the Free Software Foundation; either 1182 | * version 2 of the License, or (at your option) any later version. 1183 | * 1184 | * This library is distributed in the hope that it will be useful, 1185 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 1186 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1187 | * Library General Public License for more details. 1188 | * 1189 | * You should have received a copy of the GNU Library General Public 1190 | * License along with this library; if not, write to the Free Software 1191 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 1192 | */ 1193 | 1194 | /* utility to obtain alphabetically sorted list of genre names with numbers */ 1195 | void CDECL id3tag_genre_list( 1196 | void (*handler)(int, const char *, void *), 1197 | void* cookie); 1198 | 1199 | void CDECL id3tag_init (lame_t gfp); 1200 | 1201 | /* force addition of version 2 tag */ 1202 | void CDECL id3tag_add_v2 (lame_t gfp); 1203 | 1204 | /* add only a version 1 tag */ 1205 | void CDECL id3tag_v1_only (lame_t gfp); 1206 | 1207 | /* add only a version 2 tag */ 1208 | void CDECL id3tag_v2_only (lame_t gfp); 1209 | 1210 | /* pad version 1 tag with spaces instead of nulls */ 1211 | void CDECL id3tag_space_v1 (lame_t gfp); 1212 | 1213 | /* pad version 2 tag with extra 128 bytes */ 1214 | void CDECL id3tag_pad_v2 (lame_t gfp); 1215 | 1216 | /* pad version 2 tag with extra n bytes */ 1217 | void CDECL id3tag_set_pad (lame_t gfp, size_t n); 1218 | 1219 | void CDECL id3tag_set_title(lame_t gfp, const char* title); 1220 | void CDECL id3tag_set_artist(lame_t gfp, const char* artist); 1221 | void CDECL id3tag_set_album(lame_t gfp, const char* album); 1222 | void CDECL id3tag_set_year(lame_t gfp, const char* year); 1223 | void CDECL id3tag_set_comment(lame_t gfp, const char* comment); 1224 | 1225 | /* return -1 result if track number is out of ID3v1 range 1226 | and ignored for ID3v1 */ 1227 | int CDECL id3tag_set_track(lame_t gfp, const char* track); 1228 | 1229 | /* return non-zero result if genre name or number is invalid 1230 | result 0: OK 1231 | result -1: genre number out of range 1232 | result -2: no valid ID3v1 genre name, mapped to ID3v1 'Other' 1233 | but taken as-is for ID3v2 genre tag */ 1234 | int CDECL id3tag_set_genre(lame_t gfp, const char* genre); 1235 | 1236 | /* return non-zero result if field name is invalid */ 1237 | int CDECL id3tag_set_fieldvalue(lame_t gfp, const char* fieldvalue); 1238 | 1239 | /* return non-zero result if image type is invalid */ 1240 | int CDECL id3tag_set_albumart(lame_t gfp, const char* image, size_t size); 1241 | 1242 | /* lame_get_id3v1_tag copies ID3v1 tag into buffer. 1243 | * Function returns number of bytes copied into buffer, or number 1244 | * of bytes rquired if buffer 'size' is too small. 1245 | * Function fails, if returned value is larger than 'size'. 1246 | * NOTE: 1247 | * This functions does nothing, if user/LAME disabled ID3v1 tag. 1248 | */ 1249 | size_t CDECL lame_get_id3v1_tag(lame_t gfp, unsigned char* buffer, size_t size); 1250 | 1251 | /* lame_get_id3v2_tag copies ID3v2 tag into buffer. 1252 | * Function returns number of bytes copied into buffer, or number 1253 | * of bytes rquired if buffer 'size' is too small. 1254 | * Function fails, if returned value is larger than 'size'. 1255 | * NOTE: 1256 | * This functions does nothing, if user/LAME disabled ID3v2 tag. 1257 | */ 1258 | size_t CDECL lame_get_id3v2_tag(lame_t gfp, unsigned char* buffer, size_t size); 1259 | 1260 | /* normaly lame_init_param writes ID3v2 tags into the audio stream 1261 | * Call lame_set_write_id3tag_automatic(gfp, 0) before lame_init_param 1262 | * to turn off this behaviour and get ID3v2 tag with above function 1263 | * write it yourself into your file. 1264 | */ 1265 | void CDECL lame_set_write_id3tag_automatic(lame_global_flags * gfp, int); 1266 | int CDECL lame_get_write_id3tag_automatic(lame_global_flags const* gfp); 1267 | 1268 | /* experimental */ 1269 | int CDECL id3tag_set_textinfo_latin1(lame_t gfp, char const *id, char const *text); 1270 | 1271 | /* experimental */ 1272 | int CDECL id3tag_set_comment_latin1(lame_t gfp, char const *lang, char const *desc, char const *text); 1273 | 1274 | #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED 1275 | #else 1276 | /* experimental */ 1277 | int CDECL id3tag_set_textinfo_ucs2(lame_t gfp, char const *id, unsigned short const *text); 1278 | 1279 | /* experimental */ 1280 | int CDECL id3tag_set_comment_ucs2(lame_t gfp, char const *lang, 1281 | unsigned short const *desc, unsigned short const *text); 1282 | 1283 | /* experimental */ 1284 | int CDECL id3tag_set_fieldvalue_ucs2(lame_t gfp, const unsigned short *fieldvalue); 1285 | #endif 1286 | 1287 | /* experimental */ 1288 | int CDECL id3tag_set_fieldvalue_utf16(lame_t gfp, const unsigned short *fieldvalue); 1289 | 1290 | /* experimental */ 1291 | int CDECL id3tag_set_textinfo_utf16(lame_t gfp, char const *id, unsigned short const *text); 1292 | 1293 | /* experimental */ 1294 | int CDECL id3tag_set_comment_utf16(lame_t gfp, char const *lang, unsigned short const *desc, unsigned short const *text); 1295 | 1296 | 1297 | /*********************************************************************** 1298 | * 1299 | * list of valid bitrates [kbps] & sample frequencies [Hz]. 1300 | * first index: 0: MPEG-2 values (sample frequencies 16...24 kHz) 1301 | * 1: MPEG-1 values (sample frequencies 32...48 kHz) 1302 | * 2: MPEG-2.5 values (sample frequencies 8...12 kHz) 1303 | ***********************************************************************/ 1304 | 1305 | extern const int bitrate_table [3][16]; 1306 | extern const int samplerate_table [3][ 4]; 1307 | 1308 | /* access functions for use in DLL, global vars are not exported */ 1309 | int CDECL lame_get_bitrate(int mpeg_version, int table_index); 1310 | int CDECL lame_get_samplerate(int mpeg_version, int table_index); 1311 | 1312 | 1313 | /* maximum size of albumart image (128KB), which affects LAME_MAXMP3BUFFER 1314 | as well since lame_encode_buffer() also returns ID3v2 tag data */ 1315 | #define LAME_MAXALBUMART (128 * 1024) 1316 | 1317 | /* maximum size of mp3buffer needed if you encode at most 1152 samples for 1318 | each call to lame_encode_buffer. see lame_encode_buffer() below 1319 | (LAME_MAXMP3BUFFER is now obsolete) */ 1320 | #define LAME_MAXMP3BUFFER (16384 + LAME_MAXALBUMART) 1321 | 1322 | 1323 | typedef enum { 1324 | LAME_OKAY = 0, 1325 | LAME_NOERROR = 0, 1326 | LAME_GENERICERROR = -1, 1327 | LAME_NOMEM = -10, 1328 | LAME_BADBITRATE = -11, 1329 | LAME_BADSAMPFREQ = -12, 1330 | LAME_INTERNALERROR = -13, 1331 | 1332 | FRONTEND_READERROR = -80, 1333 | FRONTEND_WRITEERROR = -81, 1334 | FRONTEND_FILETOOLARGE = -82 1335 | 1336 | } lame_errorcodes_t; 1337 | 1338 | #if defined(__cplusplus) 1339 | } 1340 | #endif 1341 | #endif /* LAME_LAME_H */ 1342 | 1343 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Class/lame/libmp3lame.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoanKing/JKRecorderKit/91320fff9c183cde5cf33fb3599caa3b6fab6227/JKRecorderKit/JKRecorderKit/Class/lame/libmp3lame.a -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | NSMicrophoneUsageDescription 38 | 想要使用您的麦克风 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/20. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/20. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "JKRecorderKit.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | 21 | self.view.backgroundColor = [UIColor whiteColor]; 22 | 23 | UIButton *buttton1 = [[UIButton alloc]initWithFrame:CGRectMake(20, 100, 100, 40)]; 24 | [buttton1 setTitle:@"开始录音" forState:UIControlStateNormal]; 25 | [buttton1 setTitleColor:[UIColor brownColor] forState:UIControlStateNormal]; 26 | [buttton1 setBackgroundColor:[UIColor yellowColor]]; 27 | [buttton1 addTarget:self action:@selector(beginRecordClick) forControlEvents:UIControlEventTouchUpInside]; 28 | buttton1.titleLabel.font = [UIFont systemFontOfSize:18.f]; 29 | [self.view addSubview:buttton1]; 30 | 31 | UIButton *buttton12 = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(buttton1.frame)+20, 100, 100, 40)]; 32 | [buttton12 setTitle:@"暂停录音" forState:UIControlStateNormal]; 33 | [buttton12 setTitleColor:[UIColor brownColor] forState:UIControlStateNormal]; 34 | [buttton12 setBackgroundColor:[UIColor yellowColor]]; 35 | [buttton12 addTarget:self action:@selector(pauseRecordClick) forControlEvents:UIControlEventTouchUpInside]; 36 | buttton12.titleLabel.font = [UIFont systemFontOfSize:18.f]; 37 | [self.view addSubview:buttton12]; 38 | 39 | UIButton *buttton2 = [[UIButton alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(buttton1.frame)+30, 100, 40)]; 40 | [buttton2 setTitle:@"结束录音" forState:UIControlStateNormal]; 41 | [buttton2 setTitleColor:[UIColor brownColor] forState:UIControlStateNormal]; 42 | [buttton2 setBackgroundColor:[UIColor yellowColor]]; 43 | [buttton2 addTarget:self action:@selector(endRecordClick) forControlEvents:UIControlEventTouchUpInside]; 44 | buttton2.titleLabel.font = [UIFont systemFontOfSize:18.f]; 45 | [self.view addSubview:buttton2]; 46 | 47 | UIButton *buttton3 = [[UIButton alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(buttton2.frame)+30, 100, 40)]; 48 | [buttton3 setTitle:@"删除录音" forState:UIControlStateNormal]; 49 | [buttton3 setTitleColor:[UIColor brownColor] forState:UIControlStateNormal]; 50 | [buttton3 setBackgroundColor:[UIColor yellowColor]]; 51 | [buttton3 addTarget:self action:@selector(deleteRecordClick) forControlEvents:UIControlEventTouchUpInside]; 52 | buttton3.titleLabel.font = [UIFont systemFontOfSize:18.f]; 53 | [self.view addSubview:buttton3]; 54 | 55 | UIButton *buttton4 = [[UIButton alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(buttton3.frame)+30, 100, 40)]; 56 | [buttton4 setTitle:@"播放录音" forState:UIControlStateNormal]; 57 | [buttton4 setTitleColor:[UIColor brownColor] forState:UIControlStateNormal]; 58 | [buttton4 setBackgroundColor:[UIColor yellowColor]]; 59 | [buttton4 addTarget:self action:@selector(playRecordClick) forControlEvents:UIControlEventTouchUpInside]; 60 | buttton4.titleLabel.font = [UIFont systemFontOfSize:18.f]; 61 | [self.view addSubview:buttton4]; 62 | 63 | UIButton *buttton5 = [[UIButton alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(buttton4.frame)+30, 100, 40)]; 64 | [buttton5 setTitle:@"拼接录音" forState:UIControlStateNormal]; 65 | [buttton5 setTitleColor:[UIColor brownColor] forState:UIControlStateNormal]; 66 | [buttton5 setBackgroundColor:[UIColor yellowColor]]; 67 | [buttton5 addTarget:self action:@selector(editRecordClick) forControlEvents:UIControlEventTouchUpInside]; 68 | buttton4.titleLabel.font = [UIFont systemFontOfSize:18.f]; 69 | [self.view addSubview:buttton5]; 70 | 71 | UIButton *buttton6 = [[UIButton alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(buttton5.frame)+30, 110, 40)]; 72 | [buttton6 setTitle:@"caf转mp3" forState:UIControlStateNormal]; 73 | [buttton6 setTitleColor:[UIColor brownColor] forState:UIControlStateNormal]; 74 | [buttton6 setBackgroundColor:[UIColor yellowColor]]; 75 | [buttton6 addTarget:self action:@selector(pcmAudioToMP3Click) forControlEvents:UIControlEventTouchUpInside]; 76 | buttton6.titleLabel.font = [UIFont systemFontOfSize:18.f]; 77 | [self.view addSubview:buttton6]; 78 | 79 | } 80 | 81 | #pragma mark 开始录音 82 | -(void)beginRecordClick{ 83 | 84 | // 不同的文件格式,存放不同的编码数据,caf结尾的文件,基本上可以存放任何苹果支持的编码格式 85 | [[JKAudioTool shareJKAudioTool]beginRecordWithRecordName:@"test6" withRecordType:@"caf" withIsConventToMp3:YES]; 86 | 87 | } 88 | 89 | #pragma mark 暂停录音 90 | -(void)pauseRecordClick{ 91 | 92 | NSLog(@"暂停录音"); 93 | 94 | [[JKAudioTool shareJKAudioTool]pauseRecord]; 95 | } 96 | 97 | #pragma mark 结束录音 98 | -(void)endRecordClick{ 99 | 100 | [[JKAudioTool shareJKAudioTool]endRecord]; 101 | 102 | } 103 | 104 | #pragma mark 删除录音 105 | -(void)deleteRecordClick{ 106 | 107 | [[JKAudioTool shareJKAudioTool]deleteRecord]; 108 | } 109 | 110 | #pragma mark 播放录音 111 | -(void)playRecordClick{ 112 | 113 | [[JKAudioPlayerTool shareJKAudioPlayerTool] playAudioWith:[cachesRecorderPath stringByAppendingPathComponent:@"test6.mp3"]]; 114 | [JKAudioPlayerTool shareJKAudioPlayerTool].span = 0; 115 | } 116 | 117 | #pragma mark 音频的拼接:追加某个音频在某个音频的后面 118 | -(void)editRecordClick{ 119 | 120 | [JKAudioFileTool addAudio:[cachesRecorderPath stringByAppendingPathComponent:@"test2.caf"] toAudio:[cachesRecorderPath stringByAppendingPathComponent:@"test1.caf"] outputPath:[cachesRecorderPath stringByAppendingPathComponent:@"test3.caf"]]; 121 | } 122 | 123 | #pragma mark caf 转 mp3 124 | -(void)pcmAudioToMP3Click{ 125 | 126 | [JKLameTool audioToMP3:[cachesRecorderPath stringByAppendingPathComponent:@"test2.caf"] isDeleteSourchFile:YES withSuccessBack:^(NSString * _Nonnull resultPath) { 127 | 128 | NSLog(@"转为MP3后的路径=%@",resultPath); 129 | 130 | } withFailBack:^(NSString * _Nonnull error) { 131 | NSLog(@"转换失败:%@",error); 132 | 133 | }]; 134 | } 135 | 136 | -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 137 | 138 | NSLog(@"家目录=%@",NSHomeDirectory()); 139 | 140 | NSString *name = @"hha.af"; 141 | 142 | if ([name containsString:@".caf"]) { 143 | 144 | NSLog(@"包含 .caf"); 145 | }else{ 146 | 147 | NSLog(@"不包含 .caf"); 148 | } 149 | } 150 | 151 | @end 152 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKit/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // JKRecorderKit 4 | // 5 | // Created by 王冲 on 2019/2/20. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKitTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKitTests/JKRecorderKitTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // JKRecorderKitTests.m 3 | // JKRecorderKitTests 4 | // 5 | // Created by 王冲 on 2019/2/20. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JKRecorderKitTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation JKRecorderKitTests 16 | 17 | - (void)setUp { 18 | // Put setup code here. This method is called before the invocation of each test method in the class. 19 | } 20 | 21 | - (void)tearDown { 22 | // Put teardown code here. This method is called after the invocation of each test method in the class. 23 | } 24 | 25 | - (void)testExample { 26 | // This is an example of a functional test case. 27 | // Use XCTAssert and related functions to verify your tests produce the correct results. 28 | } 29 | 30 | - (void)testPerformanceExample { 31 | // This is an example of a performance test case. 32 | [self measureBlock:^{ 33 | // Put the code you want to measure the time of here. 34 | }]; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKitUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /JKRecorderKit/JKRecorderKitUITests/JKRecorderKitUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // JKRecorderKitUITests.m 3 | // JKRecorderKitUITests 4 | // 5 | // Created by 王冲 on 2019/2/20. 6 | // Copyright © 2019年 JK科技有限公司. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JKRecorderKitUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation JKRecorderKitUITests 16 | 17 | - (void)setUp { 18 | // Put setup code here. This method is called before the invocation of each test method in the class. 19 | 20 | // In UI tests it is usually best to stop immediately when a failure occurs. 21 | self.continueAfterFailure = NO; 22 | 23 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 24 | [[[XCUIApplication alloc] init] launch]; 25 | 26 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 27 | } 28 | 29 | - (void)tearDown { 30 | // Put teardown code here. This method is called after the invocation of each test method in the class. 31 | } 32 | 33 | - (void)testExample { 34 | // Use recording to get started writing UI tests. 35 | // Use XCTAssert and related functions to verify your tests produce the correct results. 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 JoanKing 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JKRecorderKit 2 | 录音/压缩转码 3 | 4 | 使用方式如下: 5 | 6 | - <1>、导入 #import "JKRecorderKit.h" 7 | - <2>、使用 JKAudioTool 类进行调用 录音的一系列操作,如下 8 | 9 | - 开始录音 10 | 11 | // 目前使用 caf 格式, test2:录音的名字 caf:录音的格式 12 | [[JKAudioTool shareJKAudioTool]beginRecordWithRecordName:@"test2" withRecordType:@"caf" withIsConventToMp3:YES]; 13 | - 完成录音 14 | 15 | [[JKAudioTool shareJKAudioTool]endRecord]; 16 | - 暂停录音 17 | 18 | [[JKAudioTool shareJKAudioTool]pauseRecord]; 19 | - 删除录音 20 | 21 | [[JKAudioTool shareJKAudioTool]deleteRecord]; 22 | - caf 转 mp3 23 | // 第一个参数是原音频的路径,第二个参数是转换为 MP3 后是否删除原来的路径 24 | [JKLameTool audioToMP3:[cachesRecorderPath stringByAppendingPathComponent:@"test2.caf"] isDeleteSourchFile:YES withSuccessBack:^(NSString * _Nonnull resultPath) { 25 | 26 | NSLog(@"转为MP3后的路径=%@",resultPath); 27 | 28 | } withFailBack:^(NSString * _Nonnull error) { 29 | NSLog(@"转换失败:%@",error); 30 | 31 | }]; 32 | --------------------------------------------------------------------------------