I'm manipulating .wav audio files in Android.
So far things are going well (I can record a .wav file from the mic, add echoes etc.), but I'd like to mimic the behaviour of sf_readf_double() and sf_writef_double as per libsndfile in C++ to implement more complex filters.
I have a com.sun.media.sound.WaveFileReader and WaveFileWriter objects and I'm getting at the audio data using
stream = wfr.getAudioInputStream(new File(inputAudioFileName));
which returns an AudioInputStream.
Is it just a case of reading 8 bytes from the stream at a time into a double or is there more to it than that? I'm a little confused as other filters I'm using seem to manipulate shorts rather than doubles.
Try this:
What should I use in Android when porting C++ code written with libsndfile?
Check this:
android-ndk
Related
Using javax.sound.midi i've managed to open my midi device up for outputting a .midi file in the past but the issue is i need to be able to pickup the midievent in it's raw form as in "3C40"/"903C40".
I'm able to find documentation on opening transmitters/receivers/sequencers but no code examples using these to output to say a string as the raw data from the midi device example of which is my yamaha ypt-240
digital keyboard.
Basically the reasoning behind why i want this raw data is to make some simple keybindings that would be triggered by said raw data from the midi device almost like a stream deck or using software that allows this.
The ShortMessage seems like the way to go but again can't find any code using it the way i would like to.
Every example is mididevice||file.midi -> synth||mididevice
I need a way to intercept that input java is getting from the device...
please help lol
I would consider myself an amateur programmer. I've taken Java classes and i'm in the process of self-teaching myself C#.
When it comes to Reading Data (say for example an Excel file) I've noticed a trend, It always begins with Open...ImportData/ManipulateData/ExportData....Export
My question:
Is there some other way to read data other than the "OpenStream" "CloseStream" that I know of already?
I know that there are a ton of different languages out there, but maybe a built in function that I don't know of already for Java or C#?
I/O operations are essentially streaming operations. Your main logic stored and executed inside the memory. After that you can dump the result, temporary calculations or the application state down to the disk. The traditional way to achive this is using streams (filestream, networkstream...) because the data is layed down one after another. Usually these streams are not random access streams, thats why there is easy to work with them.
In C# if you dont want to open or close disposable objects manually you can use the using statement.
I want to read wav files in Java and I am going to classify them with K-means.
How can I read wav files in Java and assign them into an array or something like that(you can suggest ideas for it) to classify them?
EDIT: I want to use APIs for reading wav files and for K-means.
The official Java Sound Programmer Guide walks through reading and writing audio files.
This article by A Greensted: Reading and Writing Wav Files in java should be helpful. The WavFile class is very useful and it can be tweaked to return the entire data array instead of buffered fragments.
Equivalent to matlab's wavread function:
http://web.archive.org/web/20120531113946/http://www.builogic.com/java/javasound-read-write.html
You could read the sound files using javax sound library and FileInputStream
(found a nice example here)
and treat the wave files as a vector of bits (0,1) or bytes.. using multiple sequence alignment (Wiki) create a distance matrix between every stream of bits/bytes, and from there, the clustering should be straight forward.
The Problem is, that this method is very sensitive to noise, etc, but it is worth a shot...
Not sure if this will help someone. Java JDK already provides AudioSystem class.
I used this as part of my tests to check generated WAV properties,
AudioFileFormat audioFileFormat = AudioSystem.getAudioFileFormat(new File(response.get()));
assertEquals(1, audioFileFormat.getFormat().getChannels());
assertEquals(8000.0, audioFileFormat.getFormat().getSampleRate(), 0.0f);
assertEquals(8, audioFileFormat.getFormat().getSampleSizeInBits());
Are there libraries out there that can convert data (text files, etc) to sound and back to the original data?
The sound can be transmitted any medium I wish, whether radio, etc. I just need to store data in sound files.
Scenario:
step1: Convert a .docx file with embedded images to .wav.
step2: Send over a radio wave.
step3: Convert this .wav back to the .docx file with the embedded images.
This concept can be applied to any data.
Technology:
.net or java
I think the medium is important, as are other factors such as the size of the files and the transmission time available. A simple algorithm would be to convert your files to text (UUENCODE should do that trick) then convert to morse code : http://www.codeproject.com/KB/vb/morsecode.aspx
Morse gives you a simple alphabet able to survive transmission over a fairly noisy radio channel.
If your carrier is cleaner a conversion of your UUEncoded file into a series of frequencies one per character would probably also work, and be easy enough to decode at the other end, Frequency Analyzer in C#
You could try to use the magnetic card technology for your files, I'm also trying to do this on android.
Any data can be converted to byte into a string of characters it very possible with java and android.
then use the Encoding mechanism of Magnetic Cards API to encode the string to sound. Then you can just use the vice versa, convert the sound into string convert string into byte and save the data. It's just it takes time to convert both ways but it is feasible, I'm trying to do this so that any one with unlimited voice connection can transfer files or in the future browse the internet just through calling the other number. I hope I gave you some idea.
The problem is that the data in a word document doesn't necessarily make decent sound. If you pick a 1.8kHz carrier and use the binary contents of the word document to modulate the volume or the frequency (AM or FM) the result will be messy and hardly to decode.
But if you save the document as a bitmap, you can use the pixel values to modulate the volume of the carrier wave.
We've been sending pictures (not just black/white but greyscale and color (three different separations of the image, r, g and b) over phonelines using this method for many years before modems and the internet took off.
The fun part is that you can broadcast data this way. The sound can be received by more than one receiver at the same time. There's no error correction, but as you deal with visual data, you don't have to worry about a few pixels getting lost. It's similar to old fax protocols.
Does the audio file need to be convertible using lossy compressors (MP3 etc.)? If not, you can just add a WAV container around any binary data and you'll be fine. Otherwise it gets more difficult, and you need to ensure that the audio is audible (in a reasonable frequency range when played) and be tolerant enough on the frequency detection to match the output of lossy codecs.
Best way is to convert the audio file into binary and store in a file type you specify.
Try out the AudioInputStream Class in Java
To give what I think is a better response to all of the above, have a look at packet radio and the various bits that correspond to it AX.25 is a good example and there are a number of implementations for it. POCSAG is also another good implementation. Both have libraries available for many different languages and have been around for quite a long time.
Other example include things like WEFAX (weather fax), HFFax, SSTV (slow scan tv), etc.
You can think of them all as being similar to the old school phone line modem type encoders and decoders that run around the 300-2400baud
I have a very huge WAV file, about 100MB in size. I would like to use Java to read this wav file and split it into smaller chunks for every 2 seconds of audio.
Is it possible to do this in Java? Could you please suggest me an API with which I can achieve it?
Thanks in advance,
Snehal
You can use AudioInputStream and its AudioFileFormat member (which contains an AudioFormat instance) to know what to write (format, sample rate), you can use AudioSystem to write it.
Based on the sample rate of the format you can find out how many bytes of audio are 2 seconds, and go on a loop of reading that many bytes from the AudioInputStream, writing them to a new file.
You could also look up the specification for a wav file which is really basic and simple.
And then binary read the file, and save it again in smaller bits.
I think it's a better learning experience to do it this way instead of always relying on libraries.
If you don't care about the longevity of your code, then Quicktime For Java is a good bet for media. It runs on Windows and Mac and will read and write pretty much any audio (and video) format. The downside is that Apple have not supported it for years, so while it still works, you're investing in a dying technology.