iPhone - combine two wav/caf files into one - iphone

Is it possible to combine two wav files into one as if they've been played simultaneously? I need to do this programatically.
The only way I found till now is to play both simultaneously and record the output using AVAudioRecorder. But this won't work if the user's using headphones.
Can someone please point me to the right direction.
Thanks.

You'll need to read the sample data of each file, average each sample value, and write the result to a new file. You can use ExtAudioFile to read and write files, including the headers and the sample data.
You also need to update the header with the correct length of the file, because there are fields whose value depends on the length of the sample data.

There might be a better way, but if both wavs have same encoding/bitrate, etc, you can just strip the wav header (first 44 bytes according to wav format spec) of the second file and concatenate the rest of 2nd wav to first.

Related

How to use VTK to efficiently write time-varying field data on a fixed mesh?

I am working on physics simulation research. I have a large fixed grid in one of my projects that does not vary with time. The fields on the grid, on the other hand, vary with time in the simulation. I need to use VTK to record the field data in each step for visualization (Paraview).
The method I am using is to write a separate *.vtu file to disk at each time step. This basically serves the purpose, but actually writes a lot of duplicate data (re-recording the geometry of the mesh at each step), which not only consumes more disk space, but also wastes time on encoding and parsing.
I would like to have a way to write the mesh information only once, and the rest of the time only new field data is written, while being able to guarantee the same visualization. Please let me know if VTK and Paraview provide such an interface and how to implement it.
Using .pvtu and refer to the same .vtu as Piece for each step should do the trick.
See this similar post on the ParaView discourse, and the pvtu doc
EDIT
This seems to be a side effect of the format, this is not supported by the writer.
The correct solution is to use another file format ...
Let me provide my own research findings for reference.
As Nico said, with the combination of pvtu/vtu files, we could theoretically implement a geometry structure stored in a separate vtu file, referenced by a pvtu file. Setting the NumberOfPieces attribute of the ptvu file to 1 would enable the construction of only one separate vtu file.
However, the VTK library does not expose a dedicated operation interface to control the writing process of vtu files. No matter how it is set, as long as the writer's input contains geometry structures, the writer will write geometry information to disk, and this process cannot be skipped through the exposed interface.
However, it is indeed possible to make multiple pvtu files point to the same vtu file by manually editing the piece node in the ptvu file, and paraview can recognize and visualize such a file group properly.
I did not proceed to try adding arrays to the unstructured grid and using pvtu output.
So, I think the conclusion is.
if you don't want to dive into VTK's library code and XML implementation, then this approach doesn't make sense.
if you are willing to write a series of files, delete most of them from the vtu file, and then point all the pvtu's piece nodes to the only surviving vtu file by editing the pvtu file, you can save a lot of disk space, but will not shorten the write, read, and parse times.
If you implement an XML writer by yourself, you can achieve all the requirements in theory, but it requires a lot of coding work.

Working with many inputs (Matlab)

I'm new to Matlab and I need some suggestions on how to deal with having many inputs to a function.
The program reads data from multiple elements and stores them in an array, which I'm doing in a loop. The problem is that if I input the wrong information about one element, I must re-input the data all over again. I believe that there must exist a better way to input these data, like reading it from a external file, for example.
The problem with the external file would be, as far as I know, with the reading of multiple arrays from a single file, hence the need of multiple external files - and I believe also that must exist some better way.
As noted by #beaker, you can use save and load to store the data. You can store multiple variables in a given file without a problem.

How do I obtain a hash of the payload of a digital photo container, ideally in Java?

I have edited EXIF properties on digital pictures, and would like to be able to identify them as identical. I believe this implies extracting the payload stream and computing a hash. What is the best way to do this, ideally in the Java language, most ideally in Java using a native implementation for performance.
JPEG files are a series of 'segments'. Some contain image data, others don't.
Exif data is stored in the APP1 segment. You could write some code to compare the other segments, and see if they match. A hash seems like a reasonable approach here. For example, you might compare a hash of only the SOI, DQT or DHT segments. You'd need to experiment to see which of these gives the best result.
Check out the JpegSegmentReader class from my metadata-extractor library.
Java: https://github.com/drewnoakes/metadata-extractor
.NET: https://github.com/drewnoakes/metadata-extractor-dotnet
With that class you can pull out specific segment(s) from a JPEG for processing.
Let us know how you get on!

Writing text information to existing CSV file with Matlab

I am appending an array of numbers to an existing excel file using this:
dlmwrite(mydatafile,newdataarray,'-append');
I need to add a column to the beginning of the new row for a text identifier (employee name), but I can't get Matlab to write the name to a single cell. Does anyone have any ideas how I'd be able to do this?
Your question is not completely clear, for example it is not completely defined how you can add a column to a row.
If the following does not work I would recommend you to provide a small scale example of the data that you have and the things you want to append.
Assuming you just need to get this done and are not looking for a pretty solution you could try to:
First read it into matlab
Then perform the operation that you like
Then write it to a new file
This will allow you to do pretty much anything but whether it is convenient depends on your specific needs.

Mix two audios using Xuggler's MediaTool API

I want to read the data from two audio files and after mixing it write it to a new audio file. Both audios have the same duration, samplerate & number of channels and I want to take the left channel of audio1 and the right channel of audio2 to make an stereo output with that.
From what I can see in the MediaTool API demos, onAudioSamples gets called whenever a packet is read and decoded, but for this scenario I need to have the data of both audio1 and audio2 available when onAudioSamples is called in order to modify the right channel of the samples of audio1 with the right channel of audio2.
Can I achieve this using the MediaTool API? should I use the lower level API?
Should I read all the packets from both audio files (like it is done in ConcatenateAudioAndVideo demo) before modifying the sample data, should I read a packet from each?
while(reader1.readPacket() == null && reader2.readPacket());
Thanks.
I couldn't find any way to split audio channels in the provided documentation. But the IAudioSampler and IAudioResampler can be used for audio chunks. If you start with those classes and manipulate the lower level data in IMediaData.