JAVA MP2 playback (native) - java

I have a problem with MP2 audio files and JAVA. Audio seems to be a pain in JAVA anyway. I tried using JavaLayer and Xuggler to decode and transcode the MP2 file to WAV. Both of which failed. And development of those seems to be not active. Although many are still using these. JMF or FMJ I haven't tried yet. I was wishing for more native approach.
I ended up forking JavaLayer to my project. And with a small code change I managed to seemingly get it to read all the frames from the MP2. But trying to convert it to WAV resulted in a file playable only in VLC and well, it was recognizable but distorted.
Anyway, a broad question, I apologize. I guess I'm asking that is there any JAVA + JavaLayer + MP2 gurus out there who can help me?
Original MP2: https://dl.dropboxusercontent.com/u/90134918/horng014.mp2
Failed WAV conversion: https://dl.dropboxusercontent.com/u/90134918/horng014_fail.wav
I have a public GitHub account for this project, but I haven't posted this broken code there yet.

Meanwhile theres's a new Java Media Framework here:
https://sourceforge.net/projects/doppio/
with a high level API for players and a low level API for using only decoders.
This player here https://sourceforge.net/projects/xamp2/ based on this media framework and can play mentioned file. Also the stuff is open source.

After stepping through jlayer1.01 in debugger, I conclude there are only two possibilities:
Either jlayer decodes the header word wrong, or jlayers tables and code are correct and the file's parameters deviate from what the standard defines. I lack the knowledge and time to find out wich of the two is the case.
Just because jlayer hasn't been updated for a few years does not necessarily mean its abandoned; it generally works very well with the average MP3. Why should there be an update if there aren't any known bugs left?
MP2 isn't exactly common these days; actually it hasn't even been that common 15 years ago, so it might well be the case there is a still unknown bug. Try filing a bug report and give it some time.

The MP2 file is is correct and MP2 is common these days, the MP2 Encoder twolame is up to date with enhanced VBR encoding. You can play the file with common players. There are two different bugs in JLayer: 1. The frame size calculation is wrong and 2. A Bit allocation table for MP2 Low Sampling Frequency (Mpeg2-Layer2) is buggy.

Related

How do I edit .mca files from Minecraft?

Introduction
I want to combine my separate Minecraft worlds into a single world and it seemed like a relatively easy feat, but as I did research it evolved into the need to make a custom program.
The Struggle
I started by shifting the region files and combining them in one region folder, which seemed like the obvious solution and it almost worked. Note: I've opened the files and it seems entire sectors have their coordinates stored, not entities, hence the terrain itself is spatially mismatched with the region file name.
That led to quite a bit of lag when I opened the client and the regions failed to render. I read up on the Anvil file format and imagined a scheme for reading NBT files. I figured I could manually read out the bytes and edit them, but in my continued research I got conflicting answers as to whether region files are gzipped.
I finished enough code to read some raw bytes, but the byte values didn't come out as I expected.
According to the info I have on NBT files, they all start with a CompoundTag and a CompoundTag starts as a single byte valued as 10, or x0A.
This is where I got my format information: https://minecraft.gamepedia.com/NBT_format
Here's a screenshot of what actually came out:
Note: The class description in the screenshot is not accurate. I just quickly filled in enough to read the bytes, not flesh out the UI function.
I assume these bytes coming out as non-sense is a sign that the file is compressed. I found this as a start to the gzip problem:
http://gnuwin32.sourceforge.net/packages/gzip.htm
I imagine if I could get this installed it would unzip this .mca file and I could read the bytes as expected, but I don't understand the installation instructions. It says use the "Shell Commands, 'configure', 'make' and 'make install'". To me that sounds like Unix, but the file I downloaded is for Windows? There aren't any exe's, but there are quite a few C files. I don't have a C-compiler. . .
Note: I still have not got the gzip software to work.
Post Script
I've seen similar questions asked here, but all of them were either old (2016ish) with dead links to software that used to work, or they were recent and unanswered. I found one specific copy of this question asked 5 months ago, but I had to make an account to comment. Here's the link: How can read Minecraft .mca files so that in python I can extract individual blocks? His question is with regard to a Python implementation. He said he found an NBT library for Python, but it was rejecting his MCA files for being not-gzipped.
I've got a lead on understanding the problem because I have the NBTExplorer source code (see the answer I posted), but I'll have to update on how that pans out. As far as getting my world fixed, I think I have a viable solution now.
If anyone could point me to a finished Java library, with source code, that opens .mca's or a discussion board related to this topic that'd be cool. I'm still also interested in how file compression works, but that's probably outside this question's scope. I realize this isn't directly bug or error related; it's it was moreso that I didn't know what further steps to take to make a code that accomplishes this task.
Update
I found someone else's program to do this and posted it as an answer, but I'd still like to know how the file is converted from bytes to useable info. Using the manual edit method of the answer I posted, I will need at most 241,664 manual edits, so I still need a better solution.
First of: As far as I know there is no more information about "where the chunks are", stored in the region files. There are 32(x direction)*32(z-direction)= 1024 Chunks stored within one region file and each of it has its position of data within the file. So the chunks are just numbered within the file itself and the first 8192 bytes are just about if there is any data about that specific chunk or not, where its found within the file and when it got last updated. Where the complete region (those 1024 Chunks) are positioned within the world can be worked out within the file name where the regions themself are numbered in x and z direction.
So in your case you should be able to rename your region files in a way they stay togehter as they are in the original worlds and you should be able to merge them together.
Second: The NBT Format is not the first thing to look at when you want to decode the data. First of the Region files have their own structure: https://minecraft.gamepedia.com/Region_file_format and when you get to the actual data using Zlib (RFC1950) it's getting complicated...
Anyway if you want further information on how to decode I can give you some information (since the files https://www.rfc-editor.org/rfc/rfc1950.html and https://www.rfc-editor.org/rfc/rfc1951 about Zlib (RFC1950) are written in a hard way to understand - at least it was for me). But theres a point where I myself am struggeling right now which is why I came across this question.
I found an editor!
Now I can edit, but I don't know how the editing works. I haven't learned anything, but I did finally find someone else's editor. Not quite what I wanted because I wanted to know how to do this myself.
Update: To fix a region using this software I have to manually edit 2 fields, for up to 32x32 chunks, and I have 118 regions that I need to fix. **That's 241,664 potential manual edits! This solution is not viable on a reasonable timescale, but it's the best I have so far:
I found this page: https://fileinfo.com/extension/mca
Which linked to this page: https://fileinfo.com/software/nbtexplorer/nbtexplorer
Which linked to this page: https://github.com/jaquadro/NBTExplorer/releases
I installed the software and it automatically linked to the .minecraft folder, here's a screenshot of the GUI:
On the bright side, the application download page also has a download link for the source, so I intend to read that! I've opened two files so far to take a glance and they were not commented at all. They're also written in C# which I have never seen before, but I've heard it's very similar to Java, so maybe I'll learn that language too.
This Java library is quite nice for editing .mca and has some examples of doing so in the README
https://github.com/Querz/NBT
As for how the compression works, chunks can be individually compressed via either gzip or zlib, but in practice are generally all zlib compressed, which is implemented in Java through Inflater and Deflater. One annoying thing about the format for chunk data is it is only prefixed with the size of the compressed buffer, with no info on the size of the uncompressed buffer (so the uncompressed buffer must be estimated to be large enough or multiple buffers can be used to fill until the compressed buffer is completely "inflated").

How do I proceed in an attempt to find audio files which play the same song but are in different compressed formats?

all i want is suppose i have same song named as song.mp3 and song.aac now i want my program to identify that they are same, i know this is non-trivail task to do.
so far i have tried fingerprinting audio using dejavu python library which produces 2 different fingerprints for our case song.mp3 and song.aac, hence it doesnt suit need of my program.
I also tried MD5 using FFMPEG but as expected it gives different hash for even same songs downloaded from different websites
Do you guys have any idea how do I proceed?
It would be even great to provide me step wise procedure and library to achieve my goal.
thank you
Audio fingerprinting is incredibly complex, and difficult to get right. You do not really want to come up with your own algorithm just like that, because it likely is much worse than established methods (being better than established methods requires doing some research ;-)).
One of the open source solutions for audio fingerprinting which I found is http://echoprint.me/codegen
You can use that in your application, either by calling directly into the libcodegen API, or by spawning subprocesses for audio analysis.

Issues Streaming Certain mp3s Using Java Sound and MP3SPI

I'm writing an application in Java using the Java Sound libaray that will allow me to stream music from my personal library to whatever computer I'm on. It's going well. I've success streaming mp3s with the occasional crack or pop. However, on one of my test files, I experienced regular and frequent stop-and-go kind of behavior.
This, to me, says that I'm failing to put data in the SourceDataLine fast enough and that it's underflowing. Everything I've tried has not resolved this. I'm wondering if this has anything to do with how I'm getting the data bytes to begin with so I'm posting the method I'm using. That can be found here. The method I'm talking about is the top box. I'd modified it so that I'm getting the data, sending it over the network using Sockets, and writing it to the proper line on the client end.
Any ideas on what could cause this? I've tried reading up on audio files, but I'm not really making any headway into what would cause this. Thanks in advance.

Mixing audio on android with Jmusic

I have been working on a music app for android devices for the past few months. I have written a considerable amount of code so far. However, I have been stuck for almost a month on the mixing part of the code. Since Android does not offer a way to mix audio (merge sounds into one file so that they play at the same time) I decided to add the Jmusic library to the project and use it to manipulate audio files. Unfortunately, every time I try to read an audio file from the sdcard, the app crashes. I have been looking for resource online to solve this problem, but I can't find a good one. I am thinking that maybe Android does not support the use of other libraries. Can any of you guys suggest an alternative solution if that's the case. An example code (with explanation) using Java would be greatly appreciated. What I am mainly doing is declaring a float array (data) and reading the audio file as such
data = Read.Audio("string that holds the path of the file on the sd card");
what i think is android doesn't support javaSE environment..after the compilation process
Android produces dalvik code while java has it's byte code both of them being significantly different.

What is the platform independent sound format in java

I am working on a chat application in java. My program need to play sounds at regular interval as the message arrives. What are the sound format should I choose to play on (Windows/Linux/MacOS) platforms, without using external liberaries
Sound-formats are all platform independent. The question is: Is there a Codec on the target platform which supports this format.
If you're developing a chat-application i guess you won't use high quality audio things, so Sun Audio-files should work for you. Check out this older post on how to use them.
For some reason .ao seems to be the lowest common denominator for Java, while .wav seems to be used almost everywhere else for notification-sounds (or possibly even .ogg or .mp3).

Categories

Resources