-1
$\begingroup$

I have built something that reads in audio files and processes the information for features. Sometimes the audio is rather long, and obviously I cannot keep all of this information in RAM. How can I process audio as efficiently as possible without keeping it all in RAM but still being able to refer back to slices when I need them?

$\endgroup$

closed as off-topic by MBaz, jojek, Peter K. Oct 10 '15 at 21:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "General programming questions are off-topic here, but can be asked on Stack Overflow." – MBaz, Peter K.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Stereo, 16-bit, 96kHz audio only takes up half a gigabyte. Are you that memory constrained? $\endgroup$ – Peter K. Oct 9 '15 at 22:17
  • $\begingroup$ The track itself is only half a gig, but lets say I want to compute 8 different features and keep it all in RAM. It maybe just my code, I hope not, but after all is said and done, I go from using 2 gigs (whatever is base for my comp to run plus the audio) to 4 (which is the max). Unfortunately, yes, I have to stay at 4 gigs on my computer, for work reasons. So I need to figure out a way to store and process this audio as efficiently as possible under the constraints of 1. The larger the DB row count gets, the longer the retrieval takes and 2. I only have 4 gigs of RAM. $\endgroup$ – dws12 Oct 9 '15 at 22:32
  • $\begingroup$ * The longer retrieval, insertion, and update takes. $\endgroup$ – dws12 Oct 9 '15 at 22:33
  • $\begingroup$ If you're using Linux, consider something using mmap, which is a way to access a file as if it were memory. Many languages have bindings to it. I'm sure there's a Windows equivalent but I don't know what it is. $\endgroup$ – MBaz Oct 9 '15 at 23:05
  • $\begingroup$ Which processing tool are you using - matlab/c/python/sox? I guess answer depends on it. $\endgroup$ – Neeks Oct 10 '15 at 5:52
2
$\begingroup$

If you use libsndfile, you can jump to a wanted position in the audio data using sf_seek, which accepts as an argument the number of sample frames to seek. If your processing is local in the sense that each output sample only depends on input samples close in time, then you can seek to the first input sample that affects your first output sample, and read from there until the last sample that affects your last output sample.

Or you could preprocess the audio piece-wise and write the output to a file as you go, and then seek in the processed audio when the output is needed.

Some file formats such as MP3 are difficult to seek, and might not be seekable by libsndfile. WAV should be easy.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.