Create a file which enables random access using CMTime - objective-c

I am currently seeking a solution whereby I can store accelerometer data into a file and retrieve the results by indexing into a file by CMTime. This way I can pass in a time value like 1.5 seconds and retrieve the motion data (stored as a plain text line)
AVAssetWriter allows me to write to a file and encode images/audio with CMTime and then retrieve using copyCGImageAtTime. However, I'm looking for a way, instead of images/audio, to store a plain text line with CMTime.
Overall, I am storing accelerometer data into a file every 10 milliseconds and once I finish writing to the file, I would like to index into a file using CMTime. Simultaneously, I will be writing a video file as well so that I can retrieve the frame associated with that CMTime. Another solution can include writing a line into the file to include the timestamp followed by the data, or perhaps encoding the accelerometer data alongside the video? But I would like to see if there is a better way of doing so.
Appreciate any thoughts.

Related

save to disk in append mode

save is used to store data in a format more directly usable by REBOL, as stated here
write has an append mode but it saves data in a raw mode.
My application needs to save a block of data (as a map!) to disk. Each couple of seconds it will generate a new element, up to tens of thousand of elements.
So, my question. I can save the whole data each couple of seconds. But I'd like to know if I can append the new elements to disk using the save command or save format. I guess that I could mimic the save format using the write command in /append mode. Is this the best solution, or is there another one I don't know?
save is a mezzanine function, that is basically write mold. So it's possible to mimic the save function using write or it's possible to update save function to support /append refinement.

Cocoa Core Data and plain text file

I'm wrinting a very simple application which can read data from a specified file and populate the fetched data to a NSTableView. The file is a plain text file where each line represents an object (I need to parse the file). I want to use Core Data and my question is what is the Cocoa way to do that?
My first idea is to parse the file and create instances for the Entity which represents one line. I'm not sure that is it the best solution. And later I'll write out the changes to the file (after save? or automatically after a given amount of time?)
My configuration is Mountain Lion and the latest XCode.
A single entity with a number of attributes sounds good. If you had an attribute which holds a reasonable amount of data and was repeated on a number of 'rows' then it would be a candidate for another entity.
Yes, each instance of your entity would represent one row in your table.
Personally, I would either save on request by the user, or not have a save button and save each change. Your issue is the conversion between your in-memory store and on-disk store. Using a plain text file doesn't help (though, depending on the file format, it could be possible to edit individual lines in the file using NSFileHandle).
Generally it would still make more sense to use a better format like XML or JSON and then make use of a framework like RestKit which will do all of the parsing and mapping for you (after you specify the mapping configuration).
You can also use bindings to connect your data to your NSTableView. Another ref.

Inserting wav file within a wav file using naudio

I have a recorder application(CSHARP) where i use NAudio to record/playback audio. Our need is to Insert and overwrite audio in an existing wav file.
Currently, for inserting audio, i use the current position of the wav file and do a split. Merge the new wav file to original one and merge with the rest of the file.
When overwrite, i take the current position of the original audio and merge the new audio from that position.
This process seem to work ok but for some reason i think reading the file and writing a file takes a big toll. When we do a fast recording,stop recording, rewinding, recording, stop recording and so on.. the request to file gets clogged up and at some point i get File IO exception error saying "The file is in use by another process.."
(Note: We use a footpedal equipment with 3 keys assigned for recording, play and rewind. The issue we have is when we bang on the pedals faster.)
i am really stuck at this point as i am unable to resolve this issue. I will need some expert help.
Is there a way to insert audio from a specific position in a file without doing Split and Merge? PLSSSSSSSSS Help!!
Overwriting audio in a WAV file is not too difficult, and when I need to do this, I use a customised version of WaveFileWriter that can open an existing WAV file, and lets you reposition within the data chunk.
Inserting on the other hand is always going to be problematic, since you need to shift all the audio after the insert point forwards. I'd be tempted to create a separate "insert" wav file, and then after your whole recording session is finished, stitch the parts together into a final WAV file.

Processing large video feed on the iPad

I need to take UIImages that are being fed in a video stream, all of this is on the iPad with limited memory, save them to the file system quickly while the stream is still feeding, then process them after a "recording" session. I need to save the UIImages coming in quickly to avoid interrupting the feed which will still be viewing on the iPad. I'm thinking of saving each frame to a separate file then afterward reading these files sequentially and combining them into a .mov file.
The tricks are: how to save the UIImages quickly, maybe raw data, then when processing the movie, append each UIImage file to it to make a seamless movie file? I will need to do some processing of each frame like scaling and transforms before appending.
Any advice would be greatly appreciated.
Depending on how big your images are, you could let the new coredata "use external storage" attribute do this for you.
Here is the explanation what it does copied from another answer of mine:
Since we are on IO5 now, you no longer need to write images to disk neccessarily.
You are now able to set "allow external storage" on an coredata binary attribute. According to apples release notes it means the following:
Small data values like image thumbnails may be efficiently stored in a
database, but large photos or other media are best handled directly by
the file system. You can now specify that the value of a managed
object attribute may be stored as an external record - see
setAllowsExternalBinaryDataStorage: When enabled, Core Data
heuristically decides on a per-value basis if it should save the data
directly in the database or store a URI to a separate file which it
manages for you. You cannot query based on the contents of a binary
data property if you use this option.
There are several advantages using this approach.
First coredate is saving the files at least as fast as you could when writing to the file system. But if there are any small images which apply to the conditions described above, it'll be much faster because they will be saved directly in the coredata sqlite file.
Further with iOS 5 it is very easy possible to work on separate managed contexts and perform changes on a child context in background. If finished successfully you can merge this child context into your main managed object context and do the processing you need.
[child performBlock:^{
[childsave:&parentError]; //do this in background on child context
}];
There is a NSPrivateQueueConcurrentType for creating "child-moc" - see [apple documentation][1]
And at least you can work with coredata objects which enables you to cache, limit and optimize further processing after your download completed
[1]: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdConcurrency.html#//apple_ref/doc/uid/TP40003385 for more info

Access data in fastest way, objective-c

in my iphone application i've a Xml file downloaded from a server which contains 20-30 strings. In the app i want to access particular nodes, the user insert two numbers and i want the corrispondent strings.
Is more performant access each time the XML file and scroll node until i reach the two indices entered by user or is it better convert the Xml file into a PLIST and then, import PLIST into an array and access data by it?
Every suggestion is welcome.
Depends on how often you intend to access it, really. An alternative to the plist is to simply parse the XML and store the data on the phone at startup or whenever the XML file is downloaded. That way even if your users access it repeatedly you'll only actually go through it one time.