How to split an audio file into frames ??? in C#
i want to split a wave file(.wav) into frames of 1 second or for a fixed time period. How can i do it using C# or Java. Can any one help me out for开发者_高级运维 this with some code examples or some related links regarding this.
(this too long for a comment)
.wav files are relatively easy to work with (others may point out API allowing to easily work with them but you can do it yourself too... I suppose that JMF can be used for what you want to do, for it's really basic "signal processing").
Basically you've got a few headers determining the file, then it's raw data: if you have, say, 7 seconds of 16-bit / 44 kHz stereo sound, you'll have 16*44000*7 / 8 bytes of raw data, or 616 000 bytes of raw data (601 KB).
If you want to split these 7 seconds in 7 frames of one second, you'd basically splice these 616 000 bytes into 7 pieces of 88 000 bytes, each corresponding to one second of 44 kHz 16-bit stereo data.
If you want to store these back in .wav file, then you'll have to recreate the headers.
That's the theory and you can do it all yourself (I've sure done it in Java, ten years ago or so): it is not very complicated and you'll learn a lot. .wav is basically one of the easiest format to work with.
Of course you can use some API but understanding the basics is important: you have x samples per second (for example 44 000 when you have a 44 kHz sample), that are each coded typically on 8 or 16 bits and then you usually have either mono or stereo (so either one or two channels).
In addition to that, .wav is both lossless and uncompressed, which is why it is so easy to work with (as opposed to, say, FLAC, which is lossless but compressed).
精彩评论