Coder Social home page Coder Social logo

hendriks73 / ffsampledsp Goto Github PK

View Code? Open in Web Editor NEW
24.0 4.0 5.0 20.52 MB

FFmpeg based service provider for javax.sound.sampled.

License: GNU Lesser General Public License v2.1

CSS 1.32% Java 69.77% C 28.91%
ffmpeg java java-library sound audio-decoder windows macos ubuntu audio

ffsampledsp's Introduction

LGPL 2.1 Maven Central Build and Test CodeCov

FFSampledSP

FFSampledSP is an implementation of the javax.sound.sampled service provider interfaces based on FFmpeg, a complete, cross-platform solution to record, convert and stream audio and video. FFSampledSP is part of the SampledSP collection of javax.sound.sampled libraries.

Its main purpose is to decode audio files or streams to signed linear PCM.

Supported platforms are currently:

  • macOS x64 (>=10.8) and aarch64 (>=11)
  • Windows i686 and x64
  • Linux (Ubuntu 20) x64 and aarch64 (arm64)

FFSampledSP makes use of the tagtraum FFmpeg package.

Binaries and more info can be found at its tagtraum home.

Installation

FFSampledSP is released via Maven. You can install it via the following dependency:

<dependencies>
    <dependency>
        <groupId>com.tagtraum</groupId>
        <artifactId>ffsampledsp-complete</artifactId>
    </dependency>
</dependencies>

Usage

To use the library, simply use javax.sound.sampled like you normally would.

Note that opening an AudioInputStream of compressed audio (e.g. mp3), does not decode the stream. To obtain PCM you still have to transcode to PCM like this:

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;

public class DecodeExample {
    public static void main(final String[] args) {
        // compressed stream
        final AudioInputStream mp3In = AudioSystem.getAudioInputStream(new File(args[0]));
        // AudioFormat describing the compressed stream
        final AudioFormat mp3Format = mp3In.getFormat();
        // AudioFormat describing the desired decompressed stream 
        final AudioFormat pcmFormat = new AudioFormat(
            AudioFormat.Encoding.PCM_SIGNED,
            mp3Format.getSampleRate(),
            16,
            mp3Format.getChannels(),
            16 * mp3Format.getChannels() / 8,
            mp3Format.getSampleRate(),
            mp3Format.isBigEndian()
            );
        // actually decompressed stream (signed PCM)
        final AudioInputStream pcmIn = AudioSystem.getAudioInputStream(mp3In, pcmFormat);
        // do something with the raw audio stream pcmIn... 
    }
}

Build

You can build this library locally on macOS, Windows, or Linux (Ubuntu is tested). When doing so, only the appropriate native libraries are included in the "complete" jar. The GitHub-based build also adds native libraries for other platforms.

To do so, you also need:

Note, that the C sources in the ffsampledsp-x86_64-macos module are expected to compile on all supported platforms. In fact, the very same sources are compiled in the modules for other platforms.

Release Notes

You can find the release notes/history here.

ffsampledsp's People

Contributors

hendriks73 avatar jonashartwig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ffsampledsp's Issues

Issue converting mp3 to 8kHz MULAW format

Hello & thank you for this great package!

I'm writing a phone playback service which requires I send base64 encoded MULAW 8000 Hz sample rate audio format as the message to be played.

From the twilio docs

{
  "mediaFormat": {
    "encoding": "audio/x-mulaw",
    "sampleRate": 8000,
    "channels": 1
  }
}

Issue

When I try to convert, I always get unsupported format.
Initial mp3
format "MPEG-1, Layer 3 24000.0 Hz, unknown bits per sample, mono, unknown frame size, 41.666668 frames/second"

Things I tried

Converting using the format directly does not work

If I go from MP3 to my MULAW 8kHz, I get an unsupported conversion error.

Converting to PCM_SIGNED, then to ULAW 24000 HZ then to ULAW 8000 HZ

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.File;
import java.io.IOException;

class Converter {
 private static final AudioFormat phoneFormat = new AudioFormat(AudioFormat.Encoding.ULAW, 8000, 8, 1, 1, -1, false);

 static public AudioInputStream convertToMulaw(AudioInputStream stream) {
     AudioInputStream signed = AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED, stream);
     AudioInputStream ulaw24khz = AudioSystem.getAudioInputStream(AudioFormat.Encoding.ULAW, signed);
     return AudioSystem.getAudioInputStream(phoneFormat, ulaw24khz);
 }

 public static void main(String[] args) {

     try {
         File mp3 = new File("resources/speech.mp3");
         //  format `"MPEG-1, Layer 3 24000.0 Hz, unknown bits per sample, mono, unknown frame size, 41.666668 frames/second"`
         AudioInputStream mp3Stream = AudioSystem.getAudioInputStream(mp3);
         AudioInputStream ulawStream = Converter.convertToMulaw(mp3Stream);
         AudioSystem.write(ulawStream, AudioSystem.getAudioFileFormat(mp3).getType(), new File("resources/speech.wav"));
     } catch (IOException | UnsupportedAudioFileException e) {
         return;
     }


 }
}

Output:

Nov 10, 2023 3:46:13 PM com.tagtraum.ffsampledsp.FFNativeLibraryLoader arch
INFO: Using arch=aarch64
[mp3 @ 0x1430e4000] Estimating duration from bitrate, this may be inaccurate
[mp3 @ 0x141808200] Estimating duration from bitrate, this may be inaccurate
Exception in thread "main" java.lang.IllegalArgumentException: Unsupported conversion: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame, unknown frame rate from ULAW 24000.0 Hz, 8 bit, mono, 1 bytes/frame
	at java.desktop/javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:894)
	at Converter.convertToMulaw(scratch_7.java:14)
	at Converter.main(scratch_7.java:23)

Question

Do you have any idea how I should go about it? I know that this should be supported by ffmpeg but it may be that
this sample rate is not supported by the library

Can you point me in the right direction? I have been stuck on this issue for the last 4 days.

Support for Amazon linux 2/2023

Hi Hendrik,

I want to use ffsampledsp-complete version 0.9.53 on amazon linux, but it fails with below error for mp3 as well as for other audio format files. Not sure how do I go about debugging this. Any help is appreciated

javax.sound.sampled.UnsupportedAudioFileException: File of unsupported format
java.desktop/javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1066)

Incorrect framerate returned for an mp3 file

Framerate is returned incorrectly for MP3 and M4A files. For FLAC correct value of 44100.0 is returned

Example:

import java.io.File;

import javax.swing.JFileChooser;

import com.tagtraum.ffsampledsp.FFAudioFileReader;
import com.tagtraum.ffsampledsp.FFAudioInputStream;

public class TestFramerate {

	public static void main(String args[]) throws Exception {
		JFileChooser jfc = new JFileChooser();
		if (JFileChooser.APPROVE_OPTION == jfc.showOpenDialog(null)) {
			File file = jfc.getSelectedFile();
			FFAudioInputStream audioInputStream = (FFAudioInputStream) new FFAudioFileReader().getAudioInputStream(file);
			System.out.println("Format: " + audioInputStream.getFormat());
			System.out.println("Total frames: " + audioInputStream.getFrameLength());
			System.out.println("FrameSize: " + audioInputStream.getFormat().getFrameSize());
			System.out.println("FrameRate: " + audioInputStream.getFormat().getFrameRate());
			audioInputStream.close();
		}
	}
}

Opening an MP3 file:

[mp3 @ 0x7f7f8cbe2000] Estimating duration from bitrate, this may be inaccurate
[mp3 @ 0x7f7f8cbe2000] Estimating duration from bitrate, this may be inaccurate
Format: MPEG-1, Layer 3 44100.0 Hz, 0 bit, stereo, unknown frame size, 38.28125 frames/second, 
Total frames: 12180096
FrameSize: -1
FrameRate: 38.28125

Opening a FLAC file:

Format: FLAC 44100.0 Hz, 16 bit, stereo, unknown frame size, 
Total frames: 188723304
FrameSize: -1
FrameRate: 44100.0

Opening an M4A file:

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fc02ca25c00] stream 0, timescale not set
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fc02d252400] stream 0, timescale not set
Format: MPEG4 AAC 44100.0 Hz, 16 bit, stereo, unknown frame size, 43.066406 frames/second, 
Total frames: 11808768
FrameSize: -1
FrameRate: 43.066406

SUPPORT: CentOs

Hi, I used this ffsampledsp through java on my mac. I found this very nice built and worked without any major issues. However for centos I would need to build my own JNI implementation to go against ffempeg. I already build and installed ffmpeg on my centos with what I need. Can you provide some steps on how I can build the ffsampled platform specific JNI code?

Regards

I have a question

I am trying to use your library and I follow the instructions as it comes on the page, I only put the dependency inside the POM but when loading an MP3 it throws me
java.lang.UnsatisfiedLinkError: no ffsampledsp-x86_64-win in java.library.path
Did I do something wrong or did I skip a step?

Potential security vulnerability in the FFmpeg library.

Hi, @hendriks73 , @jonashartwig , I'd like to report a vulnerability issue in com.tagtraum:ffsampledsp-complete:0.9.45.

Issue Description

com.tagtraum:ffsampledsp-complete:0.9.45 directly depends on 1 C libraries (.so). However, I noticed that this C library is vulnerable, containing the following CVEs:

ffsampledsp-x86_64-unix.sofrom C project ffmpeg(version:4.0.3) exposed 1 vulnerabilities:
CVE-2019-11339

Suggested Vulnerability Patch Versions

ffmpeg has fixed the vulnerabilities in versions >=4.4.1

Java build tools cannot report vulnerable C libraries, which may induce potential security issues to many downstream Java projects.
Could you please upgrade the above shared libraries to their patch versions?

Thanks for your help~
Best regards,
Helen Parr

Question on correct usage of Maven dependency

I have written a small gaming framework (https://github.com/armin-reichert/easy-game) where I used your great library for supporting mp3 audio.

As described on the website https://www.tagtraum.com/ffsampledsp/ I added the following Maven dependency:
<dependency> <groupId>com.tagtraum</groupId> <artifactId>ffsampledsp-complete</artifactId> <version>0.9.32</version> </dependency>

The effect is that the executable archive of a game application contains everything needed, but on the other side, each archive is huge because it contains the DLLs for all operating systems and lots of stuff I do not need.

I tried to use the artifact ffsampledsp-java instead, but in that case the needed Windows DLL is not included in the executable jar file.

My question is: Can I tailor usage of the Maven plugin somehow that it only contains the minimum needed stuff?

Failed to execute goal shade on project: Error creating shaded jar: error in opening zip file ffmpeg-4.0.0-sources.tar.bz2

Maven shade plugin errs using this dependency:

<dependency>
   <groupId>com.tagtraum</groupId>
   <artifactId>ffsampledsp-complete</artifactId>
   <version>0.9.32</version>
</dependency>

Here is my shade plugin:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-shade-plugin</artifactId>
   <version>3.2.4</version>
   <executions>
      <execution>
         <phase>package</phase>
         <goals>
            <goal>shade</goal>
         </goals>
      </execution>
   </executions>
</plugin>

Going to the folder in the error, I see the "sources" archive.
Capture

Maven can't open the file for some reason. Any advice?


Here is the full error:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27.795 s (Wall Clock)
[INFO] Finished at: 2021-03-19T09:41:26+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.2.4:shade (default) on project DoaEngine: Error creating shaded jar: error in opening zip file C:\Users\Doga.m2\repository\com\tagtraum\ffmpeg\4.0.0\ffmpeg-4.0.0-sources.tar.bz2 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

and here is my full pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>doa</groupId>
	<artifactId>DoaEngine</artifactId>
	<packaging>jar</packaging>
	<version>3.0</version>
	<name>DoaEngine</name>
	<description>A simple 2D game development framework for Java Developers.</description>
	<issueManagement>
		<url>https://github.com/aeris170/DoaEngine/issues</url>
	</issueManagement>
	<developers>
		<developer>
			<id>aeris170</id>
			<name>Doğa Oruç</name>
			<email>[email protected]</email>
			<url>https://aeris170.github.io</url>
		</developer>
	</developers>
	<licenses>
		<license>
			<name>GNU AGPLv3</name>
			<url>https://choosealicense.com/licenses/agpl-3.0/</url>
		</license>
	</licenses>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.8.1</version>
				<configuration>
					<compilerArgs>
						--enable-preview
					</compilerArgs>
					<source>15</source>
					<target>15</target>
					<release>15</release>
					<encoding>UTF-8</encoding>
					<excludes>
						<exclude>doa/main/**</exclude>
					</excludes>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-source-plugin</artifactId>
				<version>3.2.1</version>
				<configuration>
					<excludes>
						<exclude>doa/main/**</exclude>
						<exclude>TOFFEE.otf</exclude>
						<exclude>1.gif</exclude>
						<exclude>2.gif</exclude>
					</excludes>
				</configuration>
				<executions>
					<execution>
						<id>attach-sources</id>
						<goals>
							<goal>jar-no-fork</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<artifactId>maven-javadoc-plugin</artifactId>
				<groupId>org.apache.maven.plugins</groupId>
				<version>3.2.0</version>
				<configuration>
					<source>14</source>
					<additionalOptions>--enable-preview</additionalOptions>
					<windowtitle>${project.name} ${project.version} API Documentation</windowtitle>
					<doctitle>${project.name} ${project.version} API Documentation</doctitle>
					<overview>${basedir}/overview.html</overview>
					<stylesheetfile>${basedir}/stylesheet.css</stylesheetfile>
					<show>protected</show>
					<excludePackageNames>doa.main</excludePackageNames>
					<failOnError>false</failOnError>
				</configuration>
				<executions>
					<execution>
						<id>attach-javadocs</id>
						<goals>
							<goal>jar</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>
				<version>3.2.4</version>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
	<organization>
		<url>aeris170.github.io</url>
	</organization>
	<repositories>
		<repository>
			<id>jitpack.io</id>
			<url>https://jitpack.io</url>
		</repository>
		<repository>
			<id>jcenter</id>
			<url>https://jcenter.bintray.com/</url>
		</repository>
	</repositories>
	<dependencies>
		<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
		<dependency>
			<groupId>javax.validation</groupId>
			<artifactId>validation-api</artifactId>
			<version>2.0.1.Final</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
		<dependency>
			<groupId>com.google.guava</groupId>
			<artifactId>guava</artifactId>
			<version>28.2-jre</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.javatuples/javatuples -->
		<dependency>
			<groupId>org.javatuples</groupId>
			<artifactId>javatuples</artifactId>
			<version>1.2</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.jbox2d/jbox2d -->
		<dependency>
			<groupId>org.jbox2d</groupId>
			<artifactId>jbox2d</artifactId>
			<version>2.2.1.1</version>
			<type>pom</type>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.jbox2d/jbox2d-library -->
		<dependency>
			<groupId>org.jbox2d</groupId>
			<artifactId>jbox2d-library</artifactId>
			<version>2.2.1.1</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/com.code-disaster.steamworks4j/steamworks4j -->
		<dependency>
			<groupId>com.code-disaster.steamworks4j</groupId>
			<artifactId>steamworks4j</artifactId>
			<version>1.8.0</version>
		</dependency>
		<!-- https://github.com/geo-gs/WaifUPnP/ -->
		<dependency>
			<groupId>com.github.geo-gs</groupId>
			<artifactId>WaifUPnP</artifactId>
			<version>master</version>
		</dependency>
		<!-- https://github.com/JnCrMx/discord-game-sdk4j -->
		<dependency>
			<groupId>com.github.JnCrMx</groupId>
			<artifactId>discord-game-sdk4j</artifactId>
			<version>0.3</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/com.tagtraum/ffsampledsp-complete -->
		<dependency>
			<groupId>com.tagtraum</groupId>
			<artifactId>ffsampledsp-complete</artifactId>
			<version>0.9.32</version>
		</dependency>
	</dependencies>
</project>

I have another question with audioInputStream.skip()

Yeah it's me again, sorry 😥, I will try to put you in context, I am rewriting an old abandoned project and everything using your library, everything so far works perfectly well, the problem comes when I want to jump to some second of the song, there is a seek() listener method in charge of executing when you do click to some position of the JSlider, internally it passes the parameter to the method of my player in this case seek(long byte) I pass the following formula as a parameter

Math.round(<Total size in bytes of the audioinputstream> * (double) <current selected second> / <duration of the song in milliseconds>)

and inside the method, the person in charge of skipping the song is the audioInputStream.skip (bytes); this same formula and code is exactly the same as the one in the project.

My observations have been at least those that I have tried both in mp3 and in ogg, it happens that they remain as 1 or 1:45 minutes from the total of the song

In Flac format something else happens, and that is that it ends 1 to 2 minutes before, I have not tried other formats.
So I don't know what I'm doing wrong if it's me and I have to program this part in another way in which I can't think of any, or another is that it is somehow affected by your library.

In both cases, as I mentioned, it only happens when I want to jump to some part of the song.

I am not using a Clip to play the file I use a SourceDataLine, hope my problem is understood

[Question] How to read a file with a high sample rate?

Hello, it's been a while, your library has surprised me a lot, it supports too many types of audio, so much so that even the teachers asked me what the hell I was using haha

Well I have a doubt, I was experimenting with the sample rate of the songs I have and it occurred to me to download a hi-fi song it works very well except that it takes up a lot of memory, I guess it's because of the way I load the song. I have tested on songs up to 176.4khz and they work fine, but i tried with 352khz and it didn't work anymore (i guess i should lower the sample rate), i don't know why exactly this is,.

This is the way i load AudioInputStream and SourceDataLine.

private void initAudioInputStream() throws JovisPlayerException {
        // Close any previous opened audio stream before creating a new one.
        closeAudioInputStream();
        if (audioStream == null) {
            try {
                logger.info("Data source: {}", audioSource);
                initAudioInputStream(audioSource);
                AudioFormat format = audioStream.getFormat();
                logger.info("Source format: {}", format);
                int nSampleSizeInBits = format.getSampleSizeInBits();
                if (nSampleSizeInBits <= 0) {
                    nSampleSizeInBits = 16;
                }
                if ((format.getEncoding() == AudioFormat.Encoding.ULAW) || (format.getEncoding() == AudioFormat.Encoding.ALAW)) {
                    nSampleSizeInBits = 16;
                }
                if (nSampleSizeInBits != 8) {
                    nSampleSizeInBits = 16;
                }
                targetFormat = new AudioFormat(FFAudioFormat.FFEncoding.PCM_SIGNED,
                        format.getSampleRate(),
                        nSampleSizeInBits,
                        format.getChannels(),
                        nSampleSizeInBits * format.getChannels() / 8,
                        format.getSampleRate(),
                        format.isBigEndian());
                audioStream = (FFAudioInputStream) AudioSystem.getAudioInputStream(targetFormat, audioStream);
                try {
                    if (equalizer) {
                        logger.info("Setting Equalizer....");
                        equalizerStream = new EqualizerInputStream(audioStream, IIR.EQ_10_BANDS, RestoreState.getEqualizerMode());
                        logger.info("Equalizer is Ready!");
                    } else {
                        equalizerStream = null;
                        logger.info("Equalizer is off :(");
                }
                } catch (Exception ex) {
                    equalizerStream = null;
                    logger.info("Equalizer not ready :( {}", ex.getMessage());
                }
              
               ....
               ....
               
            } catch (UnsupportedAudioFileException | IOException ex) {
                throw new JovisPlayerException(ex);
            }
        }

    }
private void initSourceDataLine() throws JovisPlayerException {
        if (sourceDataLine != null) {
            return;
        }
        try {
            logger.info("Create SourceDataLine");
            DataLine.Info lineInfo = new DataLine.Info(SourceDataLine.class, targetFormat);
            if (!AudioSystem.isLineSupported(lineInfo)) {
                throw new JovisPlayerException(lineInfo + "is not supported");
            }
            if (mixerName == null) {
                mixerName = getMixers().get(0);
            }
            Mixer mixer = getMixer(mixerName);
            if (mixer != null) {
                logger.info("Mixer: {}", mixer.getMixerInfo().toString());
                sourceDataLine = (SourceDataLine) mixer.getLine(lineInfo);
            } else {
                sourceDataLine = (SourceDataLine) AudioSystem.getLine(lineInfo);
                mixerName = null;
            }

            sourceDataLine.addLineListener(dss);
            logger.info("Line info: {}", sourceDataLine.getLineInfo().toString());
            logger.info("Line AudioFormat: {}", sourceDataLine.getFormat().toString());
            if (bufferSize <= 0) {
                bufferSize = sourceDataLine.getBufferSize();
            }
            sourceDataLine.open(targetFormat, bufferSize);
            logger.info("Line BufferSize: {}", sourceDataLine.getBufferSize());
            for (Control c : sourceDataLine.getControls()) {
                logger.info("Line Controls: {}", c);
            }
            if (sourceDataLine.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
                gainControl = (FloatControl) sourceDataLine.getControl(FloatControl.Type.MASTER_GAIN);
            }
            if (sourceDataLine.isControlSupported(FloatControl.Type.PAN)) {
                panControl = (FloatControl) sourceDataLine.getControl(FloatControl.Type.PAN);
            }
            if (sourceDataLine.isControlSupported(BooleanControl.Type.MUTE)) {
                muteControl = (BooleanControl) sourceDataLine.getControl(BooleanControl.Type.MUTE);
            }
            sourceDataLine.start();
            playerState = INIT;
            future = execService.submit(this);
            notifyEvent(JovisPlayback.OPENED);
        } catch (LineUnavailableException ex) {
            throw new JovisPlayerException(ex);
        }
    }

This is the error throws me
java.util.concurrent.ExecutionException: jovis.audioplayer.JovisPlayerException: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 352800.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.

works
image

it does not work
image

Incorrect value for FFAudioFileFormat#getFrameLength()

Hi, I have encountered an error in FFSampledSP. I tried to query the length of the audio file i'm working with in frames, however, i received a value of 2519. This is definitely wrong, as the audio i'm testing with is a 48000Hz ~60 second mp3 file. Using the following code, you can reproduce the bug:

File file = new File("test.mp3");
AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(file); //This is definitely an FFAudioFileFormat class
long expectedFrameLength = (long) (((long)fileFormat.getProperty("duration")) * fileFormat.getFormat().getSampleRate() / 1000 / 1000);
long actualFrameLength = fileFormat.getFrameLength();
System.out.println("Expected Frame Length: " + expectedFrameLength);
System.out.println("Actual Frame Length: " + actualFrameLength);

The output of this code should be the following:

Expected Frame Length: 2901888
Actual Frame Length: 2519

You can use the mp3 file in the following archive to reproduce these results: test.zip

The problem originates from native sources, as in the constructor of FFAudioFileFormat (which is called by native code), the frameLength parameter is already wrong. The value of frameLength gets calculated in FFAudioFileReader.c. I could not debug the native code, therefore I do not know the main source of this bug.

I am using the latest version of FFSampledSP on maven central (which is currently 0.9.46).

Add binaries for ARM

Could you please add binaries so this library can work on ARM on Linux?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.