objective c - iOS - Access modifiable raw music library data? -
I know that it is now possible to edit a song from the user's music library and edit it by changing speed, pitch etc. But I can not find a link for a useful tutorial which is to reach the raw data of a song. Can anyone direct me to do something like this, or maybe there is such a library for this? Thanks!
Here are some source codes that you can get started with:
- (zero) doSomethingWithAssett: (AVURLAsset *) songAsset {NSError * Error = Zero; AVAssetReader * Reader = [[AVSet Reader ALOOC] initWithAsset: songAsset Error: & amp; Error]; If (error) {NSLog (@ "% @", [error description]); } AVAssetTrack * songTrack = [songAsset.tracks objectAtIndex: 0]; NSDictionary * outputSettingsDict = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNM Number Number: KAIOFormatLinePCM], AVFformatky, // [NSNumber NumberAttah: 44100.0], AVSMPlayReta, / * Not Supported * / // [NSNumber Numberless: 2], AVNumberOff Channelski, / * Not supported * / [NSNumber numberless: 16], AvilinerPCMBTDepathak, [NSNumber numberWithBlue: NO], AVLierPCMIBIGandianKe, [NSNumber Number With Bull: number], AVLier PCMI Flataky, [NSNumber Numberwithbooths: NO], AVILINERPCMININInterlev, NIEL]; AVAssetReaderTrackOutput * Output = [[AVAssetReaderTrackOutput alloc] initWithTrack: songTrack Output Settings: Output Settings Decisive]; [Reader addOutput: output]; UInt32 sampleRate, channelCount; NSArray * formatDesc = songTrack.formatDescriptions; (Unsigned int i = 0; i & lt; [formatDesc count]; ++ i) {CMAudioFormatDescriptionRef item = (__bridge CMAudioFormatDescriptionRef) [formatDesc objectAtIndex: i]; Constant AudioStrim Basic Description * fmtDesc = CMAudioFormatDescriptionGetStreamBasicDescription (item); If (fmtDesc) {sampleRate = fmtDesc-> MsampleRate; Channel count = fmtDesc-> MChannelsPerFrame; // NSLog (@ "Channel:% U, Bytes / Packet:% U, Sample Art% F", FMTDC-> mChannelsPerFrame, fmtDesc-> MBitePaper, FMTDC-> MS Sample); }} UInt32 bytesPerSample = 2 * channelCount; SInt16 normalized mark = 0; NSMutableData * Full SongData = [[NSMUtableData Allok] Init]; [Reader startup]; UInt64 totalBytes = 0; SInt64 totalLeft = 0; SInt64 totalRight = 0; NSInteger sampleTally = 0; NSInteger samplesPerPixel = sampleRate / 50; While (reader.status == AVAssetReaderStatusReading) {AVAssetReaderTrackOutput * trackOutput = (AVAssetReaderTrackOutput *) [Reader Output ObjectOctX: 0]; CMSampleBufferRef Sample BufferRef = [trackOutput copyNextSampleBuffer]; If (sampleBufferRef) {CMBlockBufferRef Block BufferRef = CMSampleBufferGetDataBuffer (sampleBufferRef); Size_t length = CMBlockBufferGetDataLength (blockbuffer); Total bytes + = length; @ AutoreplyLabel {nsmutab data * data = [nsmutable data loss length: length]; CMBlockBufferCopyDataBytes (blockbuffers, 0, length, data. Impurity); SInt16 * samples = (SInt16 *) data. Mittelbabs; You have samples, do something with them ...
Comments
Post a Comment